Restlet – Read HTTP Headers

Problem: How to read HTTP Headers in Restlet? Also we need to get Date from HTTP Headers.

Series<Parameter> headers = (Series<Parameter>) getRequest().getAttributes().get("org.restlet.http.headers");
Set<String> headerNames = headers.getNames();
for(String headerName:headerNames)
{
	System.out.println( "name==>"+headerName+" value==>"+ headers.getFirstValue(headerName));
}

Output:

name==>accept-encoding value==>gzip,deflate
name==>connection value==>keep-alive
name==>accept-language value==>en-us,en;q=0.5
name==>host value==>localhost:8080
name==>accept-charset value==>ISO-8859-1,utf-8;q=0.7,*;q=0.7
name==>user-agent value==>Mozilla/5.0 (Windows; U; Windows NT 4.x; en-US; rv:1.x.x.x) Gecko/23423423 Firefox/2.4.6
name==>accept value==>text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
name==>keep-alive value==>300

Observation: Date is missing when tried from Browser.
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

When tried from Restlet Client, it is working.

Form attributes = new Form();  
attributes.add( "message.date", "Mar-03-2010 10:30 AM" );
request.getAttributes().put( "org.restlet.http.headers", attributes );

Final Solution:
It is difficult to depend on HTTP Headers when clients are from Flex and other applications.
Easiest way is add Query String parameter like &date=123123123123123

Reference:
http://www.restlet.org/documentation/1.0/faq
http://wiki.restlet.org/docs_2.0/13-restlet/27-restlet/130-restlet.html
http://en.wikipedia.org/wiki/List_of_HTTP_headers

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s