JAX-RS过滤器在过滤请求时将ContainerRequestContext作为参数,但在实际的服务控制器中,我见过的大多数示例都以HttpServletRequest的形式获取其上下文,如
private HttpServletRequest httpServletRequest;
@Context
public void setHttpServletRequest(HttpServletRequest httpServletRequest) {
this.httpServletRequest = httpServletRequest;
}
有趣的是我可以在像
这样的过滤器中的ContainerRequestContext上设置属性public void filter(ContainerRequestContext context){
context.setProperty("MyProperty", "theValue");
}
然后在控制器中通过HttpServletRequest检索它,如
@POST
public Response post(Object param){
if("theValue".equals(httpServletRequest.getProperty("MyProperty"))){
// This works and evaluates true
}
}
那么,ContainerRequestContext和HttpServletRequest是如何相关的呢?哪个是第一个,另一个是如何从中创建/更新的?
对于Response上下文/ servletRequest对象,它是否也都一样?