我正在尝试实现检查某些内容的ContainerRequestFilter
。最终,它将从SSL客户端证书中提取通用名称,但我还没有。该过滤器在Grizzly HTTP Server(Grizzly 2.3.8,没有servlet容器)上运行,并且位于JAX-RS资源(Jersey 2.6)之前。
当我尝试将org.glassfish.grizzly.http.server.Request
注入过滤器时,它为空。
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!");
}
}
}
将请求注入JAX-RS资源,注入成功,我可以使用它。
我做错了什么?