Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InjectionManagerFactory not found with OSGi singe bundles #3588

Closed
jerseyrobot opened this issue Jun 19, 2017 · 17 comments
Closed

InjectionManagerFactory not found with OSGi singe bundles #3588

jerseyrobot opened this issue Jun 19, 2017 · 17 comments

Comments

@jerseyrobot
Copy link
Contributor

Hi,

if i use a "all-in-one" jersey jar i can use my Servlets.
if i use all the single bundles i got an error

some of the used bundles

javax.annotation:javax.annotation-api:jar:1.2
javax.validation:validation-api:jar:1.1.0.Final
javax.ws.rs:javax.ws.rs-api:jar:2.1-m09
**org.glassfish.hk2:hk2-api:jar:2.5.0-b36**
org.glassfish.hk2:hk2-locator:jar:2.5.0-b36
org.glassfish.hk2:hk2-utils:jar:2.5.0-b36
**org.glassfish.hk2:osgi-resource-locator:jar:1.0.1**
org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b36
org.glassfish.hk2.external:javax.inject:jar:2.5.0-b36
org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.26-b06
org.glassfish.jersey.containers:jersey-container-servlet:jar:2.26-b06
org.glassfish.jersey.core:jersey-client:jar:2.26-b06
org.glassfish.jersey.core:jersey-common:jar:2.26-b06
org.glassfish.jersey.core:jersey-server:jar:2.26-b06
org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.26-b06
org.glassfish.jersey.ext:jersey-mvc:jar:2.26-b06
**org.glassfish.jersey.inject:jersey-hk2:jar:2.26-b06**
org.glassfish.jersey.media:jersey-media-jaxb:jar:2.26-b06
org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.26-b06
org.glassfish.jersey.media:jersey-media-multipart:jar:2.26-b06
org.glassfish.jersey.media:jersey-media-sse:jar:2.26-b06
org.javassist:javassist:jar:3.20.0-GA
org.jvnet.mimepull:mimepull:jar:1.9.6
com.fasterxml.jackson.annotation:2.8.5
com.fasterxml.jackson.core:jackson-core:2.8.5
com.fasterxml.jackson.core:jackson-databind:2.8.5
com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:2.8.5
com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:2.8.5
com.fasterxml.jackson.core:jackson-annotations:2.8.5
com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.8.5

The Error:

java.lang.IllegalStateException: InjectionManagerFactory not found.
	at org.glassfish.jersey.internal.inject.Injections.lambda$lookupInjectionManagerFactory$0(Injections.java:98)
	at java.util.Optional.orElseThrow(Unknown Source)
	at org.glassfish.jersey.internal.inject.Injections.lookupInjectionManagerFactory(Injections.java:98)
	at org.glassfish.jersey.internal.inject.Injections.createInjectionManager(Injections.java:93)
	at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:282)
	at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:335)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178)
	at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370)
	at javax.servlet.GenericServlet.init(GenericServlet.java:158)
	at org.apache.felix.http.base.internal.handler.ServletHandler.init(ServletHandler.java:122)
	at org.apache.felix.http.base.internal.handler.WhiteboardServletHandler.init(WhiteboardServletHandler.java:57)
	at org.apache.felix.http.base.internal.registry.ServletRegistry.tryToActivate(ServletRegistry.java:358)
	at org.apache.felix.http.base.internal.registry.ServletRegistry.addServlet(ServletRegistry.java:161)
	at org.apache.felix.http.base.internal.registry.PerContextHandlerRegistry.registerServlet(PerContextHandlerRegistry.java:206)
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.registerWhiteboardService(WhiteboardManager.java:681)
	at org.apache.felix.http.base.internal.whiteboard.WhiteboardManager.addWhiteboardService(WhiteboardManager.java:590)
	at org.apache.felix.http.base.internal.whiteboard.tracker.WhiteboardServiceTracker.added(WhiteboardServiceTracker.java:104)
	at org.apache.felix.http.base.internal.whiteboard.tracker.WhiteboardServiceTracker.addingService(WhiteboardServiceTracker.java:79)
	at org.apache.felix.http.base.internal.whiteboard.tracker.WhiteboardServiceTracker.addingService(WhiteboardServiceTracker.java:36)
	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:941)
	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:870)
	at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
	at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
	at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:901)
	at org.apache.felix.framework.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:990)
	at org.apache.felix.framework.EventDispatcher.fireEventImmediately(EventDispatcher.java:838)
	at org.apache.felix.framework.EventDispatcher.fireServiceEvent(EventDispatcher.java:545)
	at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4579)
	at org.apache.felix.framework.Felix.registerService(Felix.java:3571)
	at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:348)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:887)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$3.register(AbstractComponentManager.java:874)
	at org.apache.felix.scr.impl.manager.RegistrationManager.changeRegistration(RegistrationManager.java:132)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.registerService(AbstractComponentManager.java:941)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.activateInternal(AbstractComponentManager.java:741)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager.enableInternal(AbstractComponentManager.java:675)
	at org.apache.felix.scr.impl.manager.AbstractComponentManager$1.run(AbstractComponentManager.java:453)
	at org.apache.felix.scr.impl.ComponentActorThread.run(ComponentActorThread.java:103)
	at java.lang.Thread.run(Unknown Source)
@jerseyrobot
Copy link
Contributor Author

@pavelbucek Commented
you need to add

org.glassfish.jersey.inject:jersey-hk2:jar:2.26-b06

@jerseyrobot
Copy link
Contributor Author

@pavelbucek Commented
Ah, it already is on your list. In that case, you might need to share a reproducer or debug serviceloader call by yourself..

@jerseyrobot
Copy link
Contributor Author

@JohneDoe Commented
I think it is is a problem with org.glassfish.hk2.osgi-resource-locator.
The bundle did not activate. because of that it could not read the META-INF/services and lookup for InjectionManagerFactory

More Details:
https://groups.google.com/forum/#!topic/bndtools-users/NuAmCd6sBaw

@jerseyrobot
Copy link
Contributor Author

@pavelbucek Commented
org.glassfish.hk2.osgi-resource-locator is part of hk2, not Jersey - can you please file the issue there? (https://github.com/javaee/hk2/issues)

@jerseyrobot
Copy link
Contributor Author

@JohneDoe Commented
here is the Issue on HK2
javaee/hk2#358

is thought that org.glassfish.jersey.inject:jersey-hk2 can require org.glassfish.hk2:osgi-resource-locator and let it run befor jersey starts

@jerseyrobot
Copy link
Contributor Author

@pavelbucek Commented
have you tried that approach?

@jerseyrobot
Copy link
Contributor Author

@cliffred
Copy link

cliffred commented Jun 12, 2019

I had the exact same problem. org.glassfish.hk2.osgi-resource-locator is in 'STARTING' state, but that's not the problem. The problem is that org.glassfish.jersey.core.jersey-common is not ACTIVE, instead it is only RESOLVED. Therefore in this code:

public static synchronized OsgiRegistry getInstance() {
if (instance == null) {
final ClassLoader classLoader = AccessController
.doPrivileged(ReflectionHelper.getClassLoaderPA(ReflectionHelper.class));
if (classLoader instanceof BundleReference) {
final BundleContext context = FrameworkUtil.getBundle(OsgiRegistry.class).getBundleContext();
if (context != null) { // context could be still null if the current bundle has not been started
instance = new OsgiRegistry(context);
}
}
}
return instance;
}

getBundleContext() returns null (only ACTIVE, STARTING, or STOPPING bundles have a BundleContext). Therefore setOSGiServiceFinderIteratorProvider() does not get invoked and ServiceFinder uses DefaultServiceIteratorProvider instead of OsgiServiceFinder. If you make sure org.glassfish.jersey.core.jersey-common is ACTIVE (via a start level in config.ini, or via the console, or programmatically) before you create the Jersey client it works.

I think org.glassfish.jersey.core.jersey-common should add Bundle-ActivationPolicy: lazy to its MANIFEST to make sure it's started upon first class load.

@tony--
Copy link

tony-- commented May 12, 2020

Thanks @cliffred this really helped me!

@malm66
Copy link

malm66 commented May 18, 2020

@cliffred Thanks as well - I was hitting a brick wall with getting to the bottom of this problem. Changing the start level for the org.glassfish.jersey.core.jersey-common bundle in my Equinox based application fixed the issue. For the record, even in the 2.30.1 the bundle still has no Bundle-ActivationPolicy: ... header.

@jansupol
Copy link
Contributor

Is it enough to set the ActivationPolicy to just the jersey-common module?

@cliffred
Copy link

I think so

@jansupol
Copy link
Contributor

Ok, Bundle-ActivationPolicy: lazy implemented. In case there is another issue regarding this, please open a new bug

@malm66
Copy link

malm66 commented May 22, 2020

@jansupol Thanks for taking action on this. Just for record: I have patched the MANIFEST.MF in the core-common 2.30.1 jar in our environment and added the Bundle-ActivationPolicy: lazy line to it. It now works fine without having to adjust start levels. So I am pretty confident this fix will work.

@raul1991
Copy link

raul1991 commented Jul 10, 2020

I am using the 2.31 jersey-common jar inside a karaf container and I still face the same issue with hk2 dependency injection.

Caused by: org.glassfish.hk2.api.MultiException: A MultiException has 1 exceptions. They are:

  1. org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=ServiceLocator,parent=JaxbAutoDiscoverable,qualifiers={},position=-1,optional=false,self=false,unqualified=null,861364607)

creckord pushed a commit to creckord/orbit-recipes that referenced this issue Sep 3, 2020
* github/jnr: make github/jnr/com.github.jnr.ffi_2.1.12/osgi.bnd
depend on latest available org.objectweb.asm 8.0.1

* glassfish/hk2: add 'Bundle-ActivationPolicy: lazy' to fix, see
eclipse-ee4j/jersey#3588 (comment)

* glassfish/jersey: fix dependency versions

* glassfish/jersey/org.glassfish.jersey.core.jersey-client_2.30.1:
add property to permit use of Require-Bundle

* glassfish/jersey/org.glassfish.jersey.core.jersey-common_2.30.1:
fix jakarta.annotation-api-version

Change-Id: I1dad84fda54c93c7ba6aaa2e9159b5af488c52bb
Signed-off-by: Tony Homer <tony.homer@intel.com>
@hieplq
Copy link

hieplq commented Nov 1, 2020

i get same issue InjectionManagerFactory not found (i use 2.30.1) note solution here

  1. org.glassfish.jersey.inject:jersey-hk2 is require
  2. org.glassfish.jersey.core.jersey-common need to auto run
  3. jackson-module-jsonSchema import javax.validation [1,2) but jersey-server import javax.validation [2,3) so i have to add both version

hieplq added a commit to hieplq/idempiere that referenced this issue Nov 1, 2020
hieplq added a commit to hieplq/idempiere that referenced this issue Nov 1, 2020
CarlosRuiz-globalqss pushed a commit to idempiere/idempiere that referenced this issue Nov 1, 2020
* IDEMPIERE-4492 update jetty to 9.4.33.v20201020 update atmosphere to 2.5.15

* IDEMPIERE-4492 update jetty to 9.4.33.v20201020 (update configuration)

update to default jetty configuration
delete unused configuration (alpn, http2,..)

* IDEMPIERE-4492 update orbit eclipse repository to 4.17

* IDEMPIERE-4492 update orbit eclipse repository to 4.17 (on parent pom)

* IDEMPIERE-4492 update jasper to 6.15.0

* IDEMPIERE-4492 update jasper to 6.15.0 (IDEMPIERE-4504)

get rid of bundle "org.w3c.dom.events version 3.0.0" by use old version of org.w3c.dom.smil

note: on target platform a bundle has multi version then tycho can pickup correct version define on feature (tab included plugins, field version)
but on eclipse when sync launching from .product it don't respect that value, always set highest version to bundle
workaround: on target platform manual un-select bundle org.w3c.dom.smil 1.0.1

* IDEMPIERE-4492 update atmosphere to 2.6.4

* IDEMPIERE-4492 refine target platform

use targetplatform-dsl to generate target platform https://github.com/eclipse-cbi/targetplatform-dsl
   + don't need to care update bundle version when update repository
   + at moment org.idempiere.eclipse.platform-feature include some feature form eclipse repository
     so target has to include that feature so target platform will include all bundler request by feature and bundle request by plugins of that feature and so on (ever optional
     so it make target content has more plugins than what we use on project
     next step will convert include feature to include plugins to define only what we used

* IDEMPIERE-4492 refine target platform (continue)

don't include framework feature, use include plugins to void load transitive dependency so minimize target flatform
remove some unused feature from idempiere product

* IDEMPIERE-4492 update c3p0 and database jdbc (patch from Carlos)

* IDEMPIERE-4492 improve target platform (continue)

provide test bundle require to repository for use on offline
remove some unused bundle
also fix for IDEMPIERE-4475

* IDEMPIERE-4492 improve target platform (continue IDEMPIERE-4475)

add launch for unittest
add more require bundle for unit test

* IDEMPIERE-4492 fix for rest api

refer:eclipse-ee4j/jersey#3588 (comment)

* IDEMPIERE-4492 fix for rest api

refer:eclipse-ee4j/jersey#3588 (comment)
AndreaCh83 pushed a commit to idempiere-consulting/idempiere that referenced this issue Nov 18, 2020
* IDEMPIERE-4492 update jetty to 9.4.33.v20201020 update atmosphere to 2.5.15

* IDEMPIERE-4492 update jetty to 9.4.33.v20201020 (update configuration)

update to default jetty configuration
delete unused configuration (alpn, http2,..)

* IDEMPIERE-4492 update orbit eclipse repository to 4.17

* IDEMPIERE-4492 update orbit eclipse repository to 4.17 (on parent pom)

* IDEMPIERE-4492 update jasper to 6.15.0

* IDEMPIERE-4492 update jasper to 6.15.0 (IDEMPIERE-4504)

get rid of bundle "org.w3c.dom.events version 3.0.0" by use old version of org.w3c.dom.smil

note: on target platform a bundle has multi version then tycho can pickup correct version define on feature (tab included plugins, field version)
but on eclipse when sync launching from .product it don't respect that value, always set highest version to bundle
workaround: on target platform manual un-select bundle org.w3c.dom.smil 1.0.1

* IDEMPIERE-4492 update atmosphere to 2.6.4

* IDEMPIERE-4492 refine target platform

use targetplatform-dsl to generate target platform https://github.com/eclipse-cbi/targetplatform-dsl
   + don't need to care update bundle version when update repository
   + at moment org.idempiere.eclipse.platform-feature include some feature form eclipse repository
     so target has to include that feature so target platform will include all bundler request by feature and bundle request by plugins of that feature and so on (ever optional
     so it make target content has more plugins than what we use on project
     next step will convert include feature to include plugins to define only what we used

* IDEMPIERE-4492 refine target platform (continue)

don't include framework feature, use include plugins to void load transitive dependency so minimize target flatform
remove some unused feature from idempiere product

* IDEMPIERE-4492 update c3p0 and database jdbc (patch from Carlos)

* IDEMPIERE-4492 improve target platform (continue)

provide test bundle require to repository for use on offline
remove some unused bundle
also fix for IDEMPIERE-4475

* IDEMPIERE-4492 improve target platform (continue IDEMPIERE-4475)

add launch for unittest
add more require bundle for unit test

* IDEMPIERE-4492 fix for rest api

refer:eclipse-ee4j/jersey#3588 (comment)

* IDEMPIERE-4492 fix for rest api

refer:eclipse-ee4j/jersey#3588 (comment)
AndreaCh83 pushed a commit to idempiere-consulting/idempiere that referenced this issue Jan 11, 2021
* IDEMPIERE-4492 update jetty to 9.4.33.v20201020 update atmosphere to 2.5.15

* IDEMPIERE-4492 update jetty to 9.4.33.v20201020 (update configuration)

update to default jetty configuration
delete unused configuration (alpn, http2,..)

* IDEMPIERE-4492 update orbit eclipse repository to 4.17

* IDEMPIERE-4492 update orbit eclipse repository to 4.17 (on parent pom)

* IDEMPIERE-4492 update jasper to 6.15.0

* IDEMPIERE-4492 update jasper to 6.15.0 (IDEMPIERE-4504)

get rid of bundle "org.w3c.dom.events version 3.0.0" by use old version of org.w3c.dom.smil

note: on target platform a bundle has multi version then tycho can pickup correct version define on feature (tab included plugins, field version)
but on eclipse when sync launching from .product it don't respect that value, always set highest version to bundle
workaround: on target platform manual un-select bundle org.w3c.dom.smil 1.0.1

* IDEMPIERE-4492 update atmosphere to 2.6.4

* IDEMPIERE-4492 refine target platform

use targetplatform-dsl to generate target platform https://github.com/eclipse-cbi/targetplatform-dsl
   + don't need to care update bundle version when update repository
   + at moment org.idempiere.eclipse.platform-feature include some feature form eclipse repository
     so target has to include that feature so target platform will include all bundler request by feature and bundle request by plugins of that feature and so on (ever optional
     so it make target content has more plugins than what we use on project
     next step will convert include feature to include plugins to define only what we used

* IDEMPIERE-4492 refine target platform (continue)

don't include framework feature, use include plugins to void load transitive dependency so minimize target flatform
remove some unused feature from idempiere product

* IDEMPIERE-4492 update c3p0 and database jdbc (patch from Carlos)

* IDEMPIERE-4492 improve target platform (continue)

provide test bundle require to repository for use on offline
remove some unused bundle
also fix for IDEMPIERE-4475

* IDEMPIERE-4492 improve target platform (continue IDEMPIERE-4475)

add launch for unittest
add more require bundle for unit test

* IDEMPIERE-4492 fix for rest api

refer:eclipse-ee4j/jersey#3588 (comment)

* IDEMPIERE-4492 fix for rest api

refer:eclipse-ee4j/jersey#3588 (comment)
@jgsuess
Copy link

jgsuess commented Mar 17, 2022

Any chance to have this merged? Or should we fork and patch this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants