Question

I'm trying to implement a ContainerRequestFilter that checks some stuff. Ultimately, it shall extract the common name from a SSL client certificate, but I'm not there yet. The filter runs on a Grizzly HTTP Server (Grizzly 2.3.8, no servlet container) and sits in front of a JAX-RS resource (Jersey 2.6).

When I'm trying to inject org.glassfish.grizzly.http.server.Request into the filter, it is null.

import org.glassfish.grizzly.http.server.Request;

@Provider
@Priority(Priorities.AUTHENTICATION)    // somewhat early
@SkpSecureClient    // name the filter with my own annotation
public class SecureClientFilter implements ContainerRequestFilter {

  private final Logger log = LoggerFactory.getLogger(this.getClass());

  @Context
  Request request;

  @Override
  public void filter(ContainerRequestContext requestContext) throws IOException {

    if (request == null) {
      log.debug("Unable to inject 'request'");
      // I always end up here
    } else if (request.isSecure()) {
      log.warn("Request is not secure!");
      // do something, e.g. abort request
    } else  {
      log.debug("Request is secure!");
    }
  }
}

Injecting the request into a JAX-RS resource, the injection is successful and I can work with it.

What am I doing wrong?

Was it helpful?

Solution

I think it's a bug in Jersey. Just filed an issue https://java.net/jira/browse/JERSEY-2462

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top