glassfish
  1. glassfish
  2. GLASSFISH-15794

JAX-RS injection broken for library @Providers

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 3.1_b37
    • Fix Version/s: 3.1.1_b05
    • Component/s: cdi
    • Labels:
      None
    • Environment:

      JDK6U23

      Description

      The following provider:

      @Provider
      @ApplicationScoped
      public class MyExceptionMapper implements ExceptionMapper<NullPointerException>
      {
      @Context
      private SecurityContext securityContext;
      @Context
      private Providers providers;
      @Context
      private ServletConfig servletConfig;
      @Context
      private ServletContext servletContext;
      @Inject
      private Foo cdiFieldInjection;

      does not get injected when bundled inside a library (a jar in WEB-INF/lib)

      Note that CDI injection (@Inject) works as expected.

        Issue Links

          Activity

          Hide
          Sivakumar Thyagarajan added a comment -

          I will also wait for Roberto's comments, but please find my analysis below.

          I see the following output when I access http://localhost:8080/test/api/test/exception after I deploy test.war on GF3.1 trunk build.
          > SecurityContext:false,Providers:false,ServletConfig:false,ServletContext:false,CDI field injection:true

          For this test.war, we are passing the following BDA structure to Weld:
          – BDA structure –
          [#|2011-02-03T22:21:03.414+0530|FINE|glassfish3.2|org.glassfish.weld.DeploymentImpl|_ThreadID=21;_ThreadName=Thread-1;ClassName=org.glassfish.weld.DeploymentImpl;MethodName=getBeanDeploymentArchives;|DeploymentImpl::getBDAs. Returning
          [|ID: test, bdaType= WAR, accessibleBDAs #:18, [WEB-INF/lib/test,,,,,,,,,,,,,,,,,,], Bean Classes #: 2,[org.jboss.seam.rest.test.compat.MyApplication, org.jboss.seam.rest.test.compat.Resource], ejbs=[]

          ---->ID: WEB-INF/lib/test, bdaType= JAR, accessibleBDAs #:1, [test,], Bean Classes #: 2,[org.jboss.seam.rest.test.compat.provider.Foo, org.jboss.seam.rest.test.compat.provider.MyExceptionMapper], ejbs=[]
          ---->ID: com.sun.jersey.server.impl.cdi.CDIExtension, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.server.impl.cdi.CDIExtension], ejbs=[]
          ---->ID: org.glassfish.osgicdi.impl.OSGiServiceExtension, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[org.glassfish.osgicdi.impl.OSGiServiceExtension], ejbs=[]
          ---->ID: javax.ws.rs.core.Application, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[javax.ws.rs.core.Application], ejbs=[]
          ---->ID: javax.ws.rs.core.HttpHeaders, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[javax.ws.rs.core.HttpHeaders], ejbs=[]
          ---->ID: javax.ws.rs.ext.Providers, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[javax.ws.rs.ext.Providers], ejbs=[]
          ---->ID: javax.ws.rs.core.Request, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[javax.ws.rs.core.Request], ejbs=[]
          ---->ID: javax.ws.rs.core.SecurityContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[javax.ws.rs.core.SecurityContext], ejbs=[]
          ---->ID: javax.ws.rs.core.UriInfo, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[javax.ws.rs.core.UriInfo], ejbs=[]
          ---->ID: com.sun.jersey.spi.container.ExceptionMapperContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.spi.container.ExceptionMapperContext], ejbs=[]
          ---->ID: com.sun.jersey.api.core.ExtendedUriInfo, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.api.core.ExtendedUriInfo], ejbs=[]
          ---->ID: com.sun.jersey.core.util.FeaturesAndProperties, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.core.util.FeaturesAndProperties], ejbs=[]
          ---->ID: com.sun.jersey.api.core.HttpContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.api.core.HttpContext], ejbs=[]
          ---->ID: com.sun.jersey.api.core.HttpRequestContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.api.core.HttpRequestContext], ejbs=[]
          ---->ID: com.sun.jersey.api.core.HttpResponseContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.api.core.HttpResponseContext], ejbs=[]
          ---->ID: com.sun.jersey.spi.MessageBodyWorkers, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.spi.MessageBodyWorkers], ejbs=[]
          ---->ID: com.sun.jersey.api.core.ResourceContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.api.core.ResourceContext], ejbs=[]
          ---->ID: com.sun.jersey.spi.container.WebApplication, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1,[com.sun.jersey.spi.container.WebApplication], ejbs=[]
          – BDA structure –

          I think we are hitting the issue at http://java.net/jira/browse/GLASSFISH-15721.
          The problem described in that issue is this. If a bundled library (WEB-INF/lib/jar) in a WAR is also a bean archive(ie includes beans.xml), we consider them as two different bean deployment archives[BDAs] (correctly as per the spec and Weld SPI) and provide them to Weld for deployment. We ensure that the accessibility between the BDAs(ie whether Beans in a BDA are visible and accessible by another) are correct. However in this scenario (WAR and WEB-INF/lib/.jar), these BDAs would have cyclic dependencies between each other, and Weld is having a problem handling this (http://issues.jboss.org/browse/WELD-846).

          Due to this, we have excluded this scenario from being supported in 3.1, as we would need a fix in Weld and a corresponding Weld integration as well to correctly fix this in 3.1.

          In this issue's scenario as well, we have the Provider class, in the WEB-INF/lib/test.jar, performing an Injection of Context that is a Bean from another extension (Jersey CDI extension). The Jersey CDI extension is not an accessible BeanManager for the WEB-INF/lib/test.jar BDA and hence its Beans(Context) is not available for injection.

          The workaround, in 3.1, is to repackage the application and bundle(extract) the Provider classes in the WEB-INF/classes directory,

          Show
          Sivakumar Thyagarajan added a comment - I will also wait for Roberto's comments, but please find my analysis below. I see the following output when I access http://localhost:8080/test/api/test/exception after I deploy test.war on GF3.1 trunk build. > SecurityContext:false,Providers:false,ServletConfig:false,ServletContext:false,CDI field injection:true For this test.war, we are passing the following BDA structure to Weld: – BDA structure – [#|2011-02-03T22:21:03.414+0530|FINE|glassfish3.2|org.glassfish.weld.DeploymentImpl|_ThreadID=21;_ThreadName=Thread-1;ClassName=org.glassfish.weld.DeploymentImpl;MethodName=getBeanDeploymentArchives;|DeploymentImpl::getBDAs. Returning [|ID: test, bdaType= WAR, accessibleBDAs #:18, [WEB-INF/lib/test,,,,,,,,,,,,,,,,,,] , Bean Classes #: 2, [org.jboss.seam.rest.test.compat.MyApplication, org.jboss.seam.rest.test.compat.Resource] , ejbs=[] ---->ID: WEB-INF/lib/test, bdaType= JAR, accessibleBDAs #:1, [test,] , Bean Classes #: 2, [org.jboss.seam.rest.test.compat.provider.Foo, org.jboss.seam.rest.test.compat.provider.MyExceptionMapper] , ejbs=[] ---->ID: com.sun.jersey.server.impl.cdi.CDIExtension, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.server.impl.cdi.CDIExtension] , ejbs=[] ---->ID: org.glassfish.osgicdi.impl.OSGiServiceExtension, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [org.glassfish.osgicdi.impl.OSGiServiceExtension] , ejbs=[] ---->ID: javax.ws.rs.core.Application, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [javax.ws.rs.core.Application] , ejbs=[] ---->ID: javax.ws.rs.core.HttpHeaders, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [javax.ws.rs.core.HttpHeaders] , ejbs=[] ---->ID: javax.ws.rs.ext.Providers, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [javax.ws.rs.ext.Providers] , ejbs=[] ---->ID: javax.ws.rs.core.Request, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [javax.ws.rs.core.Request] , ejbs=[] ---->ID: javax.ws.rs.core.SecurityContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [javax.ws.rs.core.SecurityContext] , ejbs=[] ---->ID: javax.ws.rs.core.UriInfo, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [javax.ws.rs.core.UriInfo] , ejbs=[] ---->ID: com.sun.jersey.spi.container.ExceptionMapperContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.spi.container.ExceptionMapperContext] , ejbs=[] ---->ID: com.sun.jersey.api.core.ExtendedUriInfo, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.api.core.ExtendedUriInfo] , ejbs=[] ---->ID: com.sun.jersey.core.util.FeaturesAndProperties, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.core.util.FeaturesAndProperties] , ejbs=[] ---->ID: com.sun.jersey.api.core.HttpContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.api.core.HttpContext] , ejbs=[] ---->ID: com.sun.jersey.api.core.HttpRequestContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.api.core.HttpRequestContext] , ejbs=[] ---->ID: com.sun.jersey.api.core.HttpResponseContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.api.core.HttpResponseContext] , ejbs=[] ---->ID: com.sun.jersey.spi.MessageBodyWorkers, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.spi.MessageBodyWorkers] , ejbs=[] ---->ID: com.sun.jersey.api.core.ResourceContext, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.api.core.ResourceContext] , ejbs=[] ---->ID: com.sun.jersey.spi.container.WebApplication, bdaType= UNKNOWN, accessibleBDAs #:0, [], Bean Classes #: 1, [com.sun.jersey.spi.container.WebApplication] , ejbs=[] – BDA structure – I think we are hitting the issue at http://java.net/jira/browse/GLASSFISH-15721 . The problem described in that issue is this. If a bundled library (WEB-INF/lib/ jar) in a WAR is also a bean archive(ie includes beans.xml), we consider them as two different bean deployment archives [BDAs] (correctly as per the spec and Weld SPI) and provide them to Weld for deployment. We ensure that the accessibility between the BDAs(ie whether Beans in a BDA are visible and accessible by another) are correct. However in this scenario (WAR and WEB-INF/lib/ .jar), these BDAs would have cyclic dependencies between each other, and Weld is having a problem handling this ( http://issues.jboss.org/browse/WELD-846 ). Due to this, we have excluded this scenario from being supported in 3.1, as we would need a fix in Weld and a corresponding Weld integration as well to correctly fix this in 3.1. In this issue's scenario as well, we have the Provider class, in the WEB-INF/lib/test.jar, performing an Injection of Context that is a Bean from another extension (Jersey CDI extension). The Jersey CDI extension is not an accessible BeanManager for the WEB-INF/lib/test.jar BDA and hence its Beans(Context) is not available for injection. The workaround, in 3.1, is to repackage the application and bundle(extract) the Provider classes in the WEB-INF/classes directory,
          Hide
          robc added a comment -

          I'd like to add that this is a regression: on GF3.1 b34, the web page displays the expected message, i.e.

          SecurityContext:true,Providers:true,ServletConfig:true,ServletContext:true,CDI field injection:true

          The server log shows that the beans in the jar are discovered and processed correctly on b34:

          Handling BeforeBeanDiscovery event
          Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.MyApplication
          Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.Resource
          Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.provider.Foo
          Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.provider.MyExceptionMapper
          recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.ws.rs.core.SecurityContext,null,false)
          recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.ws.rs.ext.Providers,null,false)
          recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.servlet.ServletConfig,null,false)
          recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.servlet.ServletContext,null,false)
          replaced annotated type for class org.jboss.seam.rest.test.compat.provider.MyExceptionMapper
          Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.provider.MyExceptionMapper
          Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.provider.MyExceptionMapper
          found injection point interface javax.ws.rs.core.SecurityContext @javax.ws.rs.core.Context()
          found injection point interface javax.servlet.ServletContext @javax.ws.rs.core.Context()
          found injection point class org.jboss.seam.rest.test.compat.provider.Foo @javax.enterprise.inject.Default()
          found injection point interface javax.servlet.ServletConfig @javax.ws.rs.core.Context()
          found injection point interface javax.ws.rs.ext.Providers @javax.ws.rs.core.Context()
          Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.MyApplication
          Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.MyApplication
          Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.provider.Foo
          Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.provider.Foo
          Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.Resource
          Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.Resource
          Handling ProcessAnnotatedType event for com.sun.jersey.server.impl.cdi.CDIExtension
          Handling AfterBeanDiscovery event

          Show
          robc added a comment - I'd like to add that this is a regression: on GF3.1 b34, the web page displays the expected message, i.e. SecurityContext:true,Providers:true,ServletConfig:true,ServletContext:true,CDI field injection:true The server log shows that the beans in the jar are discovered and processed correctly on b34: — Handling BeforeBeanDiscovery event Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.MyApplication Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.Resource Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.provider.Foo Handling ProcessAnnotatedType event for org.jboss.seam.rest.test.compat.provider.MyExceptionMapper recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.ws.rs.core.SecurityContext,null,false) recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.ws.rs.ext.Providers,null,false) recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.servlet.ServletConfig,null,false) recorded DiscoveredParameter(@javax.ws.rs.core.Context(),interface javax.servlet.ServletContext,null,false) replaced annotated type for class org.jboss.seam.rest.test.compat.provider.MyExceptionMapper Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.provider.MyExceptionMapper Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.provider.MyExceptionMapper found injection point interface javax.ws.rs.core.SecurityContext @javax.ws.rs.core.Context() found injection point interface javax.servlet.ServletContext @javax.ws.rs.core.Context() found injection point class org.jboss.seam.rest.test.compat.provider.Foo @javax.enterprise.inject.Default() found injection point interface javax.servlet.ServletConfig @javax.ws.rs.core.Context() found injection point interface javax.ws.rs.ext.Providers @javax.ws.rs.core.Context() Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.MyApplication Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.MyApplication Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.provider.Foo Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.provider.Foo Handling ProcessInjectionTarget event for org.jboss.seam.rest.test.compat.Resource Handling ProcessManagedBean event for org.jboss.seam.rest.test.compat.Resource Handling ProcessAnnotatedType event for com.sun.jersey.server.impl.cdi.CDIExtension Handling AfterBeanDiscovery event —
          Hide
          Sivakumar Thyagarajan added a comment -

          Adding 3_1_exclude as we are dependent on a Weld side change for this scenario to work.

          robc: Yes, until 3.1 b34, GF's BDA processing for this WAR, was returning a single BDA for the WAR and this scenario worked then. Since b34, we have fixed the BDAs being returned to the structure outlined in the comment above, and that is why this change in behaviour occurs.

          Show
          Sivakumar Thyagarajan added a comment - Adding 3_1_exclude as we are dependent on a Weld side change for this scenario to work. robc: Yes, until 3.1 b34, GF's BDA processing for this WAR, was returning a single BDA for the WAR and this scenario worked then. Since b34, we have fixed the BDAs being returned to the structure outlined in the comment above, and that is why this change in behaviour occurs.
          Hide
          Sivakumar Thyagarajan added a comment -

          Duplicate of GLASSFISH-15721.

          Show
          Sivakumar Thyagarajan added a comment - Duplicate of GLASSFISH-15721 .
          Hide
          Sivakumar Thyagarajan added a comment -

          This issue is a duplicate of GLASSFISH-15721.

          This issue has been fixed since the integration of Weld 1.1.1.Final (that fixes root cause WELD-846) into GlassFish 3.1.1(b4+) and GlassFish trunk.

          Confirmed manually that this test case works. While I visit http://localhost:8080/test/api/test/exception with GlassFish 3.1.1_b05 or the trunk build, I see the following output:
          SecurityContext:true,Providers:true,ServletConfig:true,ServletContext:true,CDI field injection:true
          and no exceptions.

          Show
          Sivakumar Thyagarajan added a comment - This issue is a duplicate of GLASSFISH-15721 . This issue has been fixed since the integration of Weld 1.1.1.Final (that fixes root cause WELD-846) into GlassFish 3.1.1(b4+) and GlassFish trunk. Confirmed manually that this test case works. While I visit http://localhost:8080/test/api/test/exception with GlassFish 3.1.1_b05 or the trunk build, I see the following output: SecurityContext:true,Providers:true,ServletConfig:true,ServletContext:true,CDI field injection:true and no exceptions.

            People

            • Assignee:
              Sivakumar Thyagarajan
              Reporter:
              Jozef Hartinger
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: