我正在从客户端应用程序接收JSON数据,但偶尔HTTP内容长度超过64K,并且收到以下错误:

org.jboss.netty.handler.codec.frame.TooLongFrameException: HTTP content length exceeded 65536 bytes.

我目前有以下相当幼稚的实现方式来读取HTTP内容:
String requestContent = null;
HttpRequest request = (HttpRequest) e.getMessage();
ChannelBuffer content = request.getContent();
if (content.readable()) {
    requestContent = content.toString(CharsetUtil.UTF_8);
}

有没有一种方法可以接收超过64K的数据?

编辑:堆栈跟踪:
Aug 31, 2012 2:35:20 PM org.jboss.netty.channel.SimpleChannelUpstreamHandler
WARNING: EXCEPTION, please implement org.eurekaj.manager.server.router.RouterHandler.exceptionCaught() for proper handling.
org.jboss.netty.handler.codec.frame.TooLongFrameException: HTTP content length exceeded 65536 bytes.
at org.jboss.netty.handler.codec.http.HttpChunkAggregator.messageReceived(HttpChunkAggregator.java:130)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.unfoldAndFireMessageReceived(ReplayingDecoder.java:593)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:584)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:509)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:94)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:372)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:246)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:38)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

这再次在我的应用程序中导致以下错误,该错误指示仅从HTTP请求读取前64K数据:
Caused by: org.json.JSONException: Unterminated string at character 65537
at org.json.JSONTokener.syntaxError(JSONTokener.java:410)
at org.json.JSONTokener.nextString(JSONTokener.java:244)

最佳答案

确定,然后在HttpChunkAggregator的构造函数中指定其他最大内容长度。这应该够了吧..

关于netty - Netty:HTTP内容长度超过64K时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12211045/

10-10 12:56