Restlet无法解析GET请求的有效负载

时间:2012-07-12 21:01:43

标签: java rest restlet

我在java中使用Restlet作为一个简单的客户端来调用tastypie提供的RESTful服务(python django)

我通过tcpmon监视有效负载,我看到后面的有效负载被返回但是我无法获取有效负载中的数据。

客户电话

ClientResource resource = new ClientResource("http://localhost/someplace/");
String rep = resource.get(String.class);

有效载荷

HTTP/1.0 200 OK
Date: Thu, 12 Jul 2012 20:22:12 GMT
Server: WSGIServer/0.1 Python/2.7.1
Vary: Cookie
Content-Type: application/json; charset=utf-8
Set-Cookie:  sessionid=63c5ea23113073e489cb8920819f37d; expires=Thu, 26-Jul-2012 20:22:12 GMT;           httponly; Max-Age=1209600; Path=/

{"jsonData": "someData"}

当我调试到restlet时,我注意到由于缺少长度,chunkEncoding或连接头,InboundWay.createEntity(..)正在将数据设置为EmptyRepresentation。为什么是这样?为什么我不能直接传输数据?

有人知道为什么会这样吗?有更好的客户吗?到目前为止,尝试过球衣和Resteasy的成功有限。 (jeresy有一个错误,它试图标记并重置autoCloseSteam,而resteasy只是一个痛苦的用作客户端)我希望不必编写HTTPClient。

在我的意见中,对RESTLET做了一些非常愚蠢的事情,看起来更多了。

它正在查找响应头并尝试查找它是否知道大小,或者是否知道其chunkedEncoding,或者是否指定了Connection:closed。否则它不会尝试解析有效​​载荷......有谁知道这是为什么?我没有意识到这些标题是以任何方式所必需的。为什么我们不能在未指定连接关闭时使用ClosingInputStream ...

Restlet代码

public Representation createInboundEntity(Series<Parameter> headers) {
        Representation result = null;
        long contentLength = HeaderUtils.getContentLength(headers);
        boolean chunkedEncoding = HeaderUtils.isChunkedEncoding(headers);
        // In some cases there is an entity without a content-length header
        boolean connectionClosed = HeaderUtils.isConnectionClose(headers);

        // Create the representation
        if ((contentLength != Representation.UNKNOWN_SIZE && contentLength != 0)
                || chunkedEncoding || connectionClosed) {
            InputStream inboundEntityStream = getInboundEntityStream(
                    contentLength, chunkedEncoding);
            ReadableByteChannel inboundEntityChannel = getInboundEntityChannel(
                    contentLength, chunkedEncoding);
...

0 个答案:

没有答案