Restlet 2.2.1数据用JsonpFilter截断

时间:2014-05-20 02:02:23

标签: json jsonp restlet

我正面临一个问题,如果回调参数存在,我正在尝试返回JsonP表示。

为此,我使用内置的JsonpFilter:

JsonpFilter jsonpFilter = new JsonpFilter(getContext());
authorizer.setNext(jsonpFilter);
jsonpFilter.setNext(router2);

一切都很好,直到我看到我的数据被截断。只缺少几个字符,与过滤器添加的字符数相匹配(test({status:200,body:{

这是完整的堆栈跟踪:

INFO: 2014-05-19    18:58:08    127.0.0.1   didier.baquier@gmail.com    127.0.0.1   8889    GET /v1/customers/16021 callback=test   200 1962    0   32  http://127.0.0.1:8889   Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.137 Safari/537.36    -
19 mai 2014 18:58:08 org.restlet.engine.adapter.ServerAdapter commit
GRAVE: An exception occured writing the response entity
java.io.IOException: Closed
    at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:602)
    at java.io.FilterOutputStream.write(FilterOutputStream.java:60)
    at java.io.FilterOutputStream.write(FilterOutputStream.java:108)
    at org.restlet.engine.io.IoUtils.copy(IoUtils.java:107)
    at org.restlet.ext.json.JsonpRepresentation.write(JsonpRepresentation.java:149)
    at org.restlet.engine.adapter.ServerCall.writeResponseBody(ServerCall.java:519)
    at org.restlet.engine.adapter.ServerCall.sendResponse(ServerCall.java:463)
    at org.restlet.ext.servlet.internal.ServletCall.sendResponse(ServletCall.java:430)
    at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:196)
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
    at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1118)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
2014-05-19 18:58:08.347:WARN::Committed before 500 An exception occured writing the response entity
19 mai 2014 18:58:08 org.restlet.engine.adapter.HttpServerHelper handle
ATTENTION: Error while handling an HTTP server call: 
19 mai 2014 18:58:08 org.restlet.engine.adapter.HttpServerHelper handle
INFO: Error while handling an HTTP server call
java.lang.IllegalStateException: Committed
    at org.mortbay.jetty.Response.resetBuffer(Response.java:1023)
    at org.mortbay.jetty.Response.sendError(Response.java:240)
    at org.restlet.ext.servlet.internal.ServletCall.sendResponse(ServletCall.java:397)
    at org.restlet.engine.adapter.ServerAdapter.commit(ServerAdapter.java:214)
    at org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:153)
    at org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1118)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

我在这里缺少什么?我查看了JsonPRepresentation,返回大小的方法对我来说很好。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

无法找出根本原因,我最终根据该代码重新编写了我自己的过滤器https://code.jd.com/zhangdaiscott/jeecg/blob/master/src/jeecg/rest/core/JsonPFilter.java