问题
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?
回答1:
You have to use the equivalent Java properties in the Representation class, so this is getResponse().getEntity().setRange(myRange).
来源:https://stackoverflow.com/questions/11263224/setting-a-custom-content-range-header-using-restlet