3

我从客户端应用程序接收 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)
4

1 回答 1

6

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

于 2012-08-31T14:42:29.067 回答