Uploaded image for project: 'JBoss Enterprise Application Platform'
  1. JBoss Enterprise Application Platform
  2. JBEAP-24194

[GSS](7.4.z) RESTEASY-3256 - CDI managed beans do not inject @Context injection targets

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 7.4.10.CR1, 7.4.10.GA
    • 7.4.7.GA
    • REST
    • None

    Description

      In a provider that is not annotated with @Provider and is a CDI managed bean, the @Context injection targets are left null. An example would be a filter that is installed via a feature.

      @Provider
      public class FilterRegistrationFeature implements Feature {
          @Override
          public boolean configure(FeatureContext context) {
              context.register(TestFilter.class);
              return true;
          }
      }
      
      import javax.ws.rs.container.ResourceInfo;
      
      @ApplicationScoped
      public class TestFilter implements ContainerRequestFilter {
      
          @Context
          HttpServletRequest request;
      
          @Context
          UriInfo uriInfo;
      
          @Context
          ResourceInfo resourceInfo;
      
          @Inject
          HttpServletRequest injectedRequest;
      
          @Inject
          TestBean testBean;
      
          public void filter(ContainerRequestContext requestContext) {
              System.out.println("request " + request);
              System.out.println("injectedRequest " + injectedRequest);
              System.out.println("uriInfo " + uriInfo);
              System.out.println("testBean " + testBean);
          }
      }
      

      In this case the request and uriInfo are both null. In RESTEasy 6.1+ you can just @Inject these types. However, with 5.x and lower that is not possible. The JavaDoc for Configurable.register(Class) indicates:

      As opposed to component instances registered via register(Object) method, the lifecycle of components registered using this class-based register(...) method is fully managed by the JAX-RS implementation or any underlying IoC container supported by the implementation.

      Attachments

        Issue Links

          Activity

            People

              jperkins-rhn James Perkins
              rhn-support-bmaxwell Brad Maxwell
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: