使用Restlet设置自定义内容范围标题 [英] Setting a custom Content-Range Header using Restlet

查看:264
本文介绍了使用Restlet设置自定义内容范围标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用restlet 2.0.11通过REST-Web-Interface为基于Dojo的Web应用程序提供数据.

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

根据dojo的文档,使用HTTP的"content-range"标头实现分页,因此dojo希望使用这样的标头:

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

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

这意味着REST-Api提供了100个项目中的前20个.

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

像这样手动设置Content-Range标头

Setting the Content-Range header manually like this

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

导致以下错误:

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

根据restlet的文档,该属性为"message.entity.range"(来源: http://wiki.restlet.org/docs_2.0/130-restlet.html )

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");

似乎有希望的另一种方法是使用restlet的"Representation"对象,因为它具有setRange()方法,但是在请求期间,对象引用为null:

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()

所以我的问题是:如何为Restlet响应设置Content-Range标头?

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

推荐答案

您必须在Representation类中使用等效的Java属性,因此它是getResponse().getEntity().setRange(myRange).

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

这篇关于使用Restlet设置自定义内容范围标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆