3 Replies Latest reply on Aug 20, 2010 6:36 AM by jharting

    Inject bean ref null

    rkilcoyne.rkilcoyne.mac.com

      Getting the following stacktrace when trying to access an injected bean from a RESTeasy component on JBoss 6 M4:


      18:39:10,251 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/st].[default]] Servlet.service() for servlet default threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
           at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:315) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:198) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:175) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:521) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:483) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:140) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:204) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:59) [:6.0.0.20100721-M4]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.20100721-M4]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.20100721-M4]
           at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:68) [:1.0.1.SP4]
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.0.0.20100721-M4]
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.0.0.20100721-M4]
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.0.0.20100721-M4]
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [:6.0.0.20100721-M4]
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.0.0.20100721-M4]
           at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.CR3]
           at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.CR3]
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.0.0.20100721-M4]
           at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:93) [:6.0.0.20100721-M4]
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [:6.0.0.20100721-M4]
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.0.0.20100721-M4]
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.0.0.20100721-M4]
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.0.0.20100721-M4]
           at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.0.0.20100721-M4]
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.0.0.20100721-M4]
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.0.0.20100721-M4]
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:653) [:6.0.0.20100721-M4]
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.0.0.20100721-M4]
           at java.lang.Thread.run(Thread.java:637) [:1.6.0_20]
      Caused by: java.lang.NullPointerException
           at xxx.xxx.xxxxxxxxxxx.server.web.Rest.getTestMessage2(Rest.java:32) [:]
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_20]
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_20]
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_20]
           at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_20]
           at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:252) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:217) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:206) [:6.0.0.20100721-M4]
           at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:506) [:6.0.0.20100721-M4]
           ... 26 more
      



      After going over the RESTeasy/CDI/JBoss6 docs, I can't for the life of me figure out why this doesn't work. The component I'm injecting is an EJB located in another jar in the same ear.


      Should the approach of injecting a stateless session bean in another jar but in the same ear work with a RESTeasy class?


        • 1. Re: Inject bean ref null
          nickarls

          @EJB or @Inject?

          • 2. Re: Inject bean ref null
            rkilcoyne.rkilcoyne.mac.com

            My REST component was a POJO and I was operating under the assumption that it is also a CDI component. However, it looks as if when I add the @Path or @Provider to the class, RESTeasy takes control of the component lifecycle and @Inject and @EJB don't work as expected.


            I think I got this worked out. I changed my REST component to a SLSB. It appears that the implementation side of this SLSB component MUST be in located in a WAR file while the interface can be in any other jar packaged in the EAR. This is a little counter-intuitive because my jax-rs annotations are located on the interface.


            Not sure I understand why this is the case, but I suspect it has something to do with the battle over component management between CDI and RESTeasy.

            • 3. Re: Inject bean ref null
              jharting

              Does your .war contain a beans.xml file? If so, CDI should take care of the component management.