Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-7501

Cannot inject field in ContainerRequestFilter

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.1.10, 3.2.0
    • 3.1.14, 3.2.1
    • JAX-RS
    • Linux Mint 64 bit, TomEE Plus 7.0.3, JavaEE 7 application using MVC specification and reference implementation(Libs Attached)

    • Unknown

    Description

      Hey folks.

      We found a weird behavior while running MVC specification(JSR 371) on TomEE witch CXF. We have a ContainerRequestFilter defined called JaxRsContextFilter

      @PreMatching
      @Priority(0)
      public class JaxRsContextFilter implements ContainerRequestFilter {
          @Inject
          private JaxRsContextProducer jaxRsContextProducer;
          @Context
          private Configuration configuration;
          @Context
          private HttpServletRequest request;
          @Context
          private HttpServletResponse response;
      
          public JaxRsContextFilter() {
          }
      
          public void filter(ContainerRequestContext requestContext) throws IOException {
              this.jaxRsContextProducer.populate(this.configuration, this.request, this.response);
          }
      }
      

      You can see that we have a JaxRsContextProducer annotated to be injected as a field in our object but when JAXRSUtils is called to run the the container filters it injects the fields annotated as @Context , not the fields annotated with @Inject.

       for (ProviderInfo<ContainerRequestFilter> filter : containerFilters) {
                      try {
                          InjectionUtils.injectContexts(filter.getProvider(), filter, m);
                          filter.getProvider().filter(context);
                      } catch (IOException ex) {
                          throw ExceptionUtils.toInternalServerErrorException(ex, null); 
                      }
      

      It causes our filter(JaxRsContextFilter) to throw a NullPointerException when filtering the request because it uses the producer to perform some actions in this operation.

      I believe this field should be injected as well, not only the @Context fields.

      Attachments

        1. javax-mvc.jar
          17 kB
          Jeyvison Nascimento
        2. ozark.jar
          110 kB
          Jeyvison Nascimento

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            reta Andriy Redko
            jeyvison Jeyvison Nascimento
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment