Setting a custom Content-Range Header using Restlet

最后都变了- 提交于 2019-12-12 06:25:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!