When using Restlet library to invoke RESTful method, sometimes you need to parse the request header for further use. And luckily, though there is explicit ways to solve this problem, we can still get what we need.
Calling getRequestAttributes().get("org.restlet.http.headers"); will return all the headers in the request. However, the type of returned result is "org.restlet.data.Form". Consequently, we need to convert it into the Form format, and then using the getFirstValue("") method to retrieve the value. One catch there is the key is always start with capital letter, for instant even is "location" in the header, you have to use "Location" instead.
Form headers = (Form) getRequestAttributes().get("org.restlet.http.headers");
location = headers.getFirstValue("Location");
It returns Series instead of Form
ReplyDeleteorg.restlet.util.Series cannot be cast to org.restlet.data.Form
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteSeries restletHeaders = (Series)getRequestAttributes().get("org.restlet.http.headers");
ReplyDeletelocation = headers.getFirstValue("Location");
OK thanks for this post it's quite informative and I have learned new things.
ReplyDeleteappvn app