restlet / restlet-framework-java

The first REST API framework for Java
https://restlet.talend.com
Other
654 stars 284 forks source link

Restlet 2.2.1 data truncated with JsonpFilter #920

Open dbaq opened 10 years ago

dbaq commented 10 years ago

I am facing an issue, I am trying to return a JsonP representation if the callback parameter is present.

To do so I am using the JsonpFilter built in:

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

Everything looked fine, until I saw that my data was truncated. Just a few characters are missing, that match the number of character added by the filter (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)

After the filter, if I get the entity as a text, I've got the whole payload. It looks like the HTTP connection is closed when the size of the entity (before the filter) is reached.

Thanks in advance for your help.

jlouvel commented 10 years ago

@clakech Do you have any idea what's going wrong here with the JsonFilter?

jlouvel commented 9 years ago

This issue seems related to the fact the auto quote encoding mixes up the size computation, leading the missing characters on the HTTP client side. The latest commits in branches 2.3 and master should help fix this issue.