我正在使用Restlet Java开发 Web 服务。
为此,我想保护一些 Web 服务免受未经授权的客户端的攻击。所以我写了Filter类。在那个过滤器类中,我想获取请求的标头 。但我收到以下错误 -
java.lang.ClassCastException: org.restlet.engine.http.HttpRequest cannot be cast to javax.servlet.http.HttpServletRequest
编码是 -
public class MyFilter extends Filter {
@Override
protected int beforeHandle(Request request, Response response) {
int result = STOP;
HttpServletRequest httpReq = (HttpServletRequest) request;
String user_token = httpReq.getHeader("auth");
if(user_token.equals("xyz")) {
result = CONTINUE;
}
return result;
}
}
请建议我一种在 Java Restlet 中访问 Request 标头值的方法?