2014-03-25 37 views
3

我试图执行ContainerRequestFilter来检查一些内容。最终,它将从SSL客户端证书中提取通用名称,但我还没有。过滤器运行在Grizzly HTTP Server(Grizzly 2.3.8,没有servlet容器)上,并位于JAX-RS资源(Jersey 2.6)的前面。Grizzly/Jersey:向ContainerRequestFilter注入的请求为空

当我试图将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资源,注入成功,我可以使用它。

我在做什么错?

回答

1

我认为这是泽西岛的一个bug。 刚刚提交了问题 https://java.net/jira/browse/JERSEY-2462

+0

谢谢。在票证中,您指的是相关(但是是固定的)问题https://java.net/jira/browse/JERSEY-1960。我可以确认将我的代码切换到一个servlet容器的工作。我会等待修复,然后切换回来。 – Hank