Deepu Deepu - 2 years ago 127
Java Question

How to access header values of request in Java Restlet?

I am developing web services using Restlet Java.

For this I want to protect some webservices from unauthorized clients. So I have written Filter class. In that Filter class I want to get the headers of the Request. But I am getting the following error -

java.lang.ClassCastException: org.restlet.engine.http.HttpRequest cannot be cast to javax.servlet.http.HttpServletRequest

The coding is -

public class MyFilter extends Filter {

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;

Please suggest me a way to access the header values of Request in Java Restlet?

Answer Source

I solved my problem using

Form headers = (Form) request.getAttributes().get("org.restlet.http.headers");
String user_token = headers.getFirstValue("Location");

I found this link useful.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download