title: Dependency injection into ResourceFilter not working?
body: <p>I have a bunch of JAX-RS resources that provide an API for a new WebService. In order to understand what's happening, I'd like to store information about each request in a data warehouse. In my mind, this is a perfect example for a cross-cutting concern, which could be implemented by a <code>ResourceFilter</code>, right?</p>
  
  <p>So I built a <code>DataWarehouseService</code> which is supposed to store stuff in the DB:</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class DataWarehouseService {
  
      public void logApiCall(ContainerRequest cr) {
          // get interesting fields from request, store in DB
          ...
      }
  }
  </code></pre>
  
  <p>And here's my filter:</p>
  
  <pre><code>public class LoggingResourceFilter implements ResourceFilter {
  
      Logger log = Logger.getLogger(this.getClass().getName());
  
      @EJB
      DataWarehouseService dwh;
  
      @Override
      public ContainerRequestFilter getRequestFilter() {
  
          return new ContainerRequestFilter() {
              @Override
              public ContainerRequest filter(ContainerRequest cr) {
                  log.info("Incoming request: "+
                          cr.getHeaderValue("user-agent") +" "+
                          cr.getMethod() +" "+
                          cr.getPath()
                          );
  
                  dwh.logApiRequest(cr);
                  return cr;
              }
          };
      }
  
      @Override
      public ContainerResponseFilter getResponseFilter() {
          return null;
      }
  }
  </code></pre>
  
  <p>I inject the filter into my JAX-RS resources via annotation <code>@ResourceFilters(LoggingResourceFilter.class)</code> on class-level.</p>
  
  <p>The Filter-injection works fine, when I access one of the JAX-RS resources, the log statement ("Incoming request: ...") gets executed. But immediately afterwards, the call to the injected <code>DataWarehouseService</code>'s <code>dwh.logApiRequest(cr)</code> fails with a Nullpointer - obviously the injection failed?!</p>
  
  <p>What's the problem here? I thought, <code>ResourceFilters</code> are managed and can use CDI. Am I wrong? </p>
  
  <p>All of this runs on Glassfish 3.1.1, Jersey 1.8 is the JAX-RS provider. Would it make a difference if I used <code>@Inject</code>?</p>