2012-08-31 105 views
3

我从客户端应用接收JSON数据,但一旦在一段时间的HTTP内容长度超过64K,并且收到以下错误:Netty的:与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) 

这又导致在我的应用下面的错误,这表明,只有数据的第一个64K从HTTP请求读:

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) 
+0

你可以请发布完整的stacktrace? –

+0

使用堆栈跟踪编辑原始帖子。 –

回答

6

好的,然后在HttpChunkAggregator的构造函数中指定一个不同的最大内容长度。这应该做的伎俩..

+0

对不起,迟到的回应,但是,是的。这就是诀窍:) –

相关问题