How does Restlet handle the HTTP Accept header?

The Restlet framework is supposed to handle automatic content negotiation; however, it doesn't seem to do it properly.

When a client sends and HTTP GET request with the Accept header with a value, Restlet doesn't automatically negotiates the content.

Does anyone know how the Accept header is treated?


There are 1 answer(s) to this question.

Hi Steve,

The Restlet API has extensive support for the "Accept" header. The information is parsed and available via the Request.getClientInfo().getAcceptedMediaTypes() : List> method.

Now, in order to automatically negotiate content for you, the Restlet engine needs to have information about the available variants. This is the purpose org.restlet.resource.Resource class in Restlet 1.1 and the new org.restlet.resource.ServerResource class in the Restlet 2.0 version being developed.

In Restlet 1.1, you create a subclass of Resource, declare variants like this:

getVariants().add(new Variant(MediaType.TEXT_PLAIN));

getVariants().add(new Variant(MediaType.APPLICATION_XML));

Then override the represent(Variant) method like this:

public Representation represent(Variant){



  else if(...)


Best regards, Jerome

PS: please use our mailing list for future questions and look in the archives:

Related Questions

Related restlet Video tutorials from Youtube.

Post you comment here

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

There are 0 comment(s) to this page.

The questions and answers taken from's public data dump which is licensed under the cc-wiki license.
Logo, website design and layout ©2011