Hi
I attempt to get get the Jersey integration running together with
Deltaspike, OpenEJB and Test Control according to the documentation at
the bottom of the page here:
https://deltaspike.apache.org/documentation/test-control.html
Not working so far is the injection of CDI beans into JAX-RS resources.
The resulting exceptions look like like:
MultiException stack 1 of 1
org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no
object available for injection at
SystemInjecteeImpl(requiredType=EntityManagerFactory,parent=KatharsisMgmtFeature,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1475912655)
at
org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75)
at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:945)
at
org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:979)
at
org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1054)
at
org.jvnet.hk2.internal.ServiceLocatorImpl.createAndInitialize(ServiceLocatorImpl.java:1045)
at
org.glassfish.jersey.model.internal.CommonConfig.configureFeatures(CommonConfig.java:711)
at
org.glassfish.jersey.model.internal.CommonConfig.configureMetaProviders(CommonConfig.java:648)
at
org.glassfish.jersey.server.ResourceConfig.configureMetaProviders(ResourceConfig.java:829)
at
org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:453)
at
org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
at
org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
at
org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at
org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
at
org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
at
org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:311)
at
org.glassfish.jersey.jetty.JettyHttpContainer.<init>(JettyHttpContainer.java:474)
at
org.glassfish.jersey.jetty.JettyHttpContainerProvider.createContainer(JettyHttpContainerProvider.java:60)
at
org.glassfish.jersey.server.ContainerFactory.createContainer(ContainerFactory.java:81)
at
org.glassfish.jersey.jetty.JettyHttpContainerFactory.createServer(JettyHttpContainerFactory.java:161)
at
ch.adnovum.jcan.test.deltaspike.jaxrs.internal.DeltaspikeAwareJettyTestContainer.<init>(DeltaspikeAwareJettyTestContainer.java:41)
at
ch.adnovum.jcan.test.deltaspike.jaxrs.internal.DeltaspikeAwareJettyTestContainerFactory.create(DeltaspikeAwareJettyTestContainerFactory.java:16)
at
org.glassfish.jersey.test.JerseyTest.createTestContainer(JerseyTest.java:277)
at org.glassfish.jersey.test.JerseyTest.setUp(JerseyTest.java:607)
at
ch.adnovum.moap.movie.management.web.EntityAccessTest.setUp(EntityAccessTest.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:177)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.runChild(CdiTestRunner.java:76)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$BeforeClassStatement.evaluate(CdiTestRunner.java:372)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner$AfterClassStatement.evaluate(CdiTestRunner.java:393)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at
org.apache.deltaspike.testcontrol.api.junit.CdiTestRunner.run(CdiTestRunner.java:144)
at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
KatharsisMgmtFeature is a regular Feature. And their is a Producer that
makes the EntityManagerFactory available with @Inject.
The application works if I manually register a
org.glassfish.hk2.utilities.binding.AbstractBinder bean as singleton to
the Application and use it to bind CDI beans to jersey/hk2 with
AbstractBinder.bind(x).to(y). But I would rather prefer for Jersey to
directly access the CDI beans instead of bridging those with the
AbstractBinder.
My dependencies for Jersey currently look like:
compile 'org.glassfish.jersey.core:jersey-client:2.23.1'
compile 'org.glassfish.jersey.core:jersey-common:2.23.1'
compile
'org.glassfish.jersey.test-framework:jersey-test-framework-core:2.23.1'
compile
'org.glassfish.jersey.test-framework.providers:jersey-test-framework-provider-jetty:2.23.1'
compile
'org.glassfish.jersey.containers:jersey-container-jetty-http:2.23.1'
compile 'org.glassfish.jersey.bundles.repackaged:jersey-guava:2.23.1'
compile 'org.glassfish.jersey.ext.cdi:jersey-cdi1x:2.23.1'
compile 'org.glassfish.jersey.ext.cdi:jersey-cdi1x-transaction:2.23.1'
compile 'org.glassfish.jersey.ext.cdi:jersey-cdi1x-servlet:2.23.1'
The last three are new jersey libraries first having become available
last year. Documentation about those is available here:
https://jersey.java.net/documentation/latest/cdi.support.html.
Potentially that api would open up the possiblity for a small deltaspike
library that does all the necessary integration work (request scoping,
cdi binding), probably independent of Jetty.
Or is there a complete example somewhere?
Regards Remo