我创建了这个过滤器:
@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;
}
}