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

JAX-RS integration with EJB Technology doesn't work #377

Closed
tweier opened this issue Jul 20, 2015 · 5 comments · Fixed by #466
Closed

JAX-RS integration with EJB Technology doesn't work #377

tweier opened this issue Jul 20, 2015 · 5 comments · Fixed by #466

Comments

@tweier
Copy link

tweier commented Jul 20, 2015

The Java EE 7 Tutorial describes the integration of JAX-RS with EJB Technology http://docs.oracle.com/javaee/7/tutorial/jaxrs-advanced004.htm#GKNCY

I try to use a stateless session bean as a JAX-RS root resource class:

@stateless
@path("/person")
public class PersonResource {

@ejb
private PersonServiceLocal personServiceLocal;

@path("/{id}")
@get
@produces({ APPLICATION_JSON })
public Person read(@PathParam("id") long id) {
return personServiceLocal.read(id);
}

...
}

But the injected EJB is always null.

I have tried this in 3 different environments:
works on: glassfish-3.1.2.2-b5
doesn't work on: glassfish-4.1, payara-4.1.152

We use a multi-module maven project for reproducing with:

  • lib-module (type: jar): contains a @Local PersonServiceLocal interface and the Person class
  • ejb-module (type: ejb): contains a @stateless PersonServiceBean
  • web-module (type: war): Skinny war with PersonResource and a JAX-RS ApplicationConfig class
  • ear-module (type: ear): EAR that contains EJB- and WEB-Module and lib-Module in /lib
  • root-module (type: pom)

Sources for reproducing are available under https://github.com/tweier/jaxrs-payara-failure

Steps to reproduce:

  1. mvn clean install (in project root)
  2. ./asadmin deploy jaxrs-ear-1.0-SNAPSHOT.ear
  3. curl -X GET http://localhost:8080/jaxrs/war/resources/person/1

The error on glassfish-4.1 and payara-4.1.152 occures only with the ear. If I use only the war project - containing all classes - the EJB injection works on all tested application servers.

@tweier
Copy link
Author

tweier commented Jul 21, 2015

Now we have some additional information:

The annotation javax.ejb.Singleton also does not work: EJB injections not work and the singleton works not as a singleton. With every request an existing @PostConstruct method is called

When using CDI annotation javax.inject.Singleton instead, everything works fine.

In case of error the server.log file contains a SEVERE log entry:

javax.naming.NamingException: Lookup failed for 'java:app/jaxrs-ejb-1.0-SNAPSHOT/PersonResource!com.tests.jaxrs.rest.PersonResource' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming} [Root exception is javax.naming.NameNotFoundException: No object bound to name java:app/jaxrs-ejb-1.0-SNAPSHOT/PersonResource!com.tests.jaxrs.rest.PersonResource]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:491)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:438)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.glassfish.jersey.gf.ejb.internal.EjbComponentProvider.lookupFullyQualifiedForm(EjbComponentProvider.java:399)
at org.glassfish.jersey.gf.ejb.internal.EjbComponentProvider.lookup(EjbComponentProvider.java:362)
at org.glassfish.jersey.gf.ejb.internal.EjbComponentProvider.access$000(EjbComponentProvider.java:98)
at org.glassfish.jersey.gf.ejb.internal.EjbComponentProvider$EjbFactory.provide(EjbComponentProvider.java:120)
at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:123)
at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:471)
at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:69)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2064)
at org.jvnet.hk2.internal.ServiceLocatorImpl.internalGetService(ServiceLocatorImpl.java:711)
at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:653)
at org.glassfish.jersey.internal.inject.Injections.getOrCreate(Injections.java:169)
at org.glassfish.jersey.server.model.MethodHandler$ClassBasedMethodHandler.getInstance(MethodHandler.java:185)
at org.glassfish.jersey.server.internal.routing.PushMethodHandlerRouter.apply(PushMethodHandlerRouter.java:74)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:109)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
at org.glassfish.jersey.server.internal.routing.RoutingStage._apply(RoutingStage.java:112)
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:92)
at org.glassfish.jersey.server.internal.routing.RoutingStage.apply(RoutingStage.java:61)
at org.glassfish.jersey.process.internal.Stages.process(Stages.java:197)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:297)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
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.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:288)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1110)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:401)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:386)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:222)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)
at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)
at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NameNotFoundException: No object bound to name java:app/jaxrs-ejb-1.0-SNAPSHOT/PersonResource!com.tests.jaxrs.rest.PersonResource
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:741)
at com.sun.enterprise.naming.impl.GlassfishNamingManagerImpl.lookup(GlassfishNamingManagerImpl.java:715)
at com.sun.enterprise.naming.impl.JavaURLContext.lookup(JavaURLContext.java:167)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:471)
... 65 more
]]

@schoendort
Copy link

I have the same exception like your case 3. But my webservice is in a war thats inside a ear:
ear:
-ejb-module
-war:
--Application.class
--Resource.class
This is working on wildfly9.0.1.final and on glassfish 4b89 but not on payara 4.1.153

One other webservice with a other structure is working:
war:
-Application.class
-ejb-module:
--Resource.class

trajano pushed a commit to trajano/test that referenced this issue Aug 12, 2015
Only on the web resources. This works on WildFly, Glassfish and WebSphere.

It does not fix payara/Payara#377 or
payara/Payara#394 but it is a valid workaround.

@stateless web resources do not work WildFly and per

https://issues.jboss.org/browse/WFLY-5072

it is not in the standard.
@smillidge
Copy link
Contributor

I've raised this with Jersey https://java.net/jira/browse/JERSEY-2938
I have a patch which we will incorporate into Payara. the patch is on the Jersey issue.

@smillidge
Copy link
Contributor

Jersey pull request has been merged and is targeted for Jersey 2.22 which we will pull into Payara once released.

@smillidge
Copy link
Contributor

Jersey 2.22 is now released. Needs pulling into master and retesting.

smillidge pushed a commit to smillidge/Payara that referenced this issue Oct 3, 2015
@smillidge smillidge added this to the Payara Server 4.1.154 milestone Oct 3, 2015
smillidge added a commit that referenced this issue Oct 8, 2015
PAYARA-393 upgrade Jersey to 2.22 fixes #377
Pandrex247 added a commit to Pandrex247/Payara that referenced this issue Aug 10, 2022
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

Successfully merging a pull request may close this issue.

4 participants