Uploaded image for project: 'Application Server 3  4  5 and 6'
  1. Application Server 3 4 5 and 6
  2. JBAS-9445

JAXRS-EJB-CDI bean injection failure (classloading issue?)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 6.0.0.Final, 6.1.0
    • Fix Version/s: None
    • Component/s: EJB, Web Services, Weld/CDI
    • Labels:
      None

      Description

      Summary :

      • In a JAX-RS resource implemented as a stateless session EJB, a CDI injection fails when several applications are deployed.
      • Both JBoss 6.0.0.Final and 6.1.0.Final fail, but with different results.

      Description:

      • We have two webapps, "mockup1.war" and "mockup2.war".
      • Each webapp contains the same "SampleResource" JAX-RS resource class implemented as a stateless session EJB ("@Stateless").
      • Each webapp contains the same "ApplicationResources" JAX-RS application resource class that registers "SampleResource".
      • Each webapp contains the same "ServiceInterface" business interface.
      • Each webapp contains its own implementation of the business service : "ServiceBean1" for "mockup1.war" and "ServiceBean2" for "mockup2.war".
      • That implementation is used as a CDI bean injected into the JAX-RS resource class. It only logs a text message to stdout.

      Test scenario with JBoss 6.0.0.Final :

      What happened with JBoss 6.0.0.Final :

      • When the resource class is executed from "mockup2.war", the business service implementation is loaded from "mockup1.war" instead of "mockup2.war"!
      • When the resource class is executed from "mockup1.war", no problem.

      Other information for JBoss 6.0.0.Final :

      • I tracked the issue using a debugger.
      • If I use a servlet filter I can see that the filter classloader always correctly refers to the current web app, that's ok.
      • But inside the JAX-RS resource class I can see that the resource class loader always point to "mockup2.war". This may explain why the wrong bean gets injected.
      • If the JAX-Rs resource class is @ManagedBean instead of @Stateless, there is no bug.

      Test scenario with JBoss 6.1.0.Final :

      • Same (1) and (2) => eveything is ok.
      • (3) go to the URL => server failure, you get a stack trace :
        2011-09-05 16:26:25,421 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/mockup1].[default]] (http-127.0.0.1-8080-1) "Servlet.service()" pour la servlet default a généré une exception: org.jboss.resteasy.spi.UnhandledException: java.lang.IllegalArgumentException: object is not an instance of declaring class
        at org.jboss.resteasy.core.SynchronousDispatcher.unwrapException(SynchronousDispatcher.java:345) [:6.1.0.Final]
        at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:321) [:6.1.0.Final]
        at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214) [:6.1.0.Final]
        at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190) [:6.1.0.Final]
        at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:534) [:6.1.0.Final]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496) [:6.1.0.Final]
        at org.jboss.resteasy.core.SynchronousDispatcher.invokePropagateNotFound(SynchronousDispatcher.java:155) [:6.1.0.Final]
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:212) [:6.1.0.Final]
        at org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.doFilter(FilterDispatcher.java:59) [:6.1.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
        at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:67) [:6.1.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:274) [:6.1.0.Final]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242) [:6.1.0.Final]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [:6.1.0.Final]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [:6.1.0.Final]
        at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181) [:6.1.0.Final]
        at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285) [:1.1.0.Final]
        at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261) [:1.1.0.Final]
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88) [:6.1.0.Final]
        at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100) [:6.1.0.Final]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159) [:6.1.0.Final]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [:6.1.0.Final]
        at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158) [:6.1.0.Final]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [:6.1.0.Final]
        at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53) [:6.1.0.Final]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362) [:6.1.0.Final]
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [:6.1.0.Final]
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) [:6.1.0.Final]
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951) [:6.1.0.Final]
        at java.lang.Thread.run(Thread.java:662) [:1.6.0_24]
        Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]
        at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]
        at org.jboss.weld.util.reflection.SecureReflections$13.work(SecureReflections.java:305) [:6.1.0.Final]
        at org.jboss.weld.util.reflection.SecureReflectionAccess.run(SecureReflectionAccess.java:54) [:6.1.0.Final]
        at org.jboss.weld.util.reflection.SecureReflectionAccess.runAsInvocation(SecureReflectionAccess.java:163) [:6.1.0.Final]
        at org.jboss.weld.util.reflection.SecureReflections.invoke(SecureReflections.java:299) [:6.1.0.Final]
        at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:125) [:6.1.0.Final]
        at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:62) [:6.1.0.Final]
        at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:125) [:6.1.0.Final]
        at com.beaufume.mockup.SampleResource$Proxy$$$_Weld$Proxy$.getContent(SampleResource$Proxy$$$_Weld$Proxy$.java) [:]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_24]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_24]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_24]
        at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_24]
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140) [:6.1.0.Final]
        at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255) [:6.1.0.Final]
        at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220) [:6.1.0.Final]
        at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209) [:6.1.0.Final]
        at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519) [:6.1.0.Final]
        ... 26 more

        Attachments

        1. mockup1.war
          4 kB
        2. mockup2.war
          4 kB
        3. mockup-sources.zip
          2 kB

          Activity

            People

            Assignee:
            marius.bogoevici Marius Bogoevici (Inactive)
            Reporter:
            fbeaufume Tom Tom (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated: