0

I'm using restlet 2.0.11 to provide data for a Dojo-based web application via a REST-Web-Interface.

According to the documentation of dojo, pagination is realized using the "content-range" header of HTTP, thus dojo expects a header like:

Content-Range: items 0-19/100

(Source: http://dojotoolkit.org/reference-guide/1.7/dojox/data/JsonRestStore.html)

Which means that the REST-Api provides the first 20 of 100 total items.

Setting the Content-Range header manually like this

getResponse().getAttributes().get("org.restlet.http.headers").add(new Parameter("Content-Range", "FooBar")

Results in the following error:

WARNING: Addition of the standard header "Content-Range" is not allowed. Please use the equivalent property in the Restlet API.

According to restlet's documentation the property is "message.entity.range" (Source: http://wiki.restlet.org/docs_2.0/130-restlet.html)

The direct modification of this hash-map was also without success:

getResponse().getAttributes().put("message.entity.range", "FooBat");

Another way which seemed to be promising is using the "Representation"-object of restlet, since it has a setRange() method, but during request time, the object reference is null:

getResponse().getEntity()

So my question is: How to set a Content-Range header to a Restlet response?

Robert Metzger
  • 4,452
  • 23
  • 50

1 Answers1

1

You have to use the equivalent Java properties in the Representation class, so this is getResponse().getEntity().setRange(myRange).

Jerome Louvel
  • 2,882
  • 18
  • 19
  • As I said in my question, getResponse().getEntity() is null. Is there a way to initialize it? – Robert Metzger Jul 01 '12 at 09:13
  • You need to set your response entity first, for example using the StringRepresentation class or any Representation subclass (see Javadocs) – Jerome Louvel Jul 09 '12 at 15:06
  • Thank you for your help. I got it working. (by calling getResponse.setEntity(new StringRepresentation(...)). The next problem I have, is that the Content-Range is hard-coded to start with "bytes ". Dojo requires the header to start with "items ". I think I'm going to send a pull request to restlet with that feature included. – Robert Metzger Jul 10 '12 at 08:54
  • As a follow-up you contributed a nice enhancement here: https://github.com/restlet/restlet-framework-java/pull/618 – Jerome Louvel Jul 12 '12 at 07:19