JaxRS:HttpServletRequest在ContainerRequestFilter中为null

时间:2017-08-17 10:54:32

标签: java-ee jax-rs

我创建了这个过滤器:

@Provider
@PreMatching
public class BearerFilter implements ContainerRequestFilter
{
    @Context private HttpServletRequest request;

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException
    {
        this.request.getHeaders();
    }
}

达到filter方法时,this.request属性为null

我正在使用jaxrs而我正在使用此oltu library。它需要an HttpServletRequest object

这是我的休息申请:

@ApplicationPath(value = "cmng")
public class RestApplication extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new HashSet<Class<?>>();

        resources.add(AccountEndpoint.class);

        return resources;
    }

    @Override
    public Set<Object> getSingletons() {
        Set<Object> singletons = new HashSet<Object>();

        singletons.add(new CORSFilter());
        singletons.add(new BearerFilter());

        return singletons;
    }
}

0 个答案:

没有答案