adamfisk/LittleProxy — Issue #24: Error with chunked requests throwing NullPointerException
Author: myleshorton
Created: 2012-02-28 19:36:36+00:00
State: open

From Petr Ferschmann in the forum:

java.lang.NullPointerException
at org.littleshoot.proxy.HttpRequestHandler.processChunk(HttpRequestHandler.java:227)
at org.littleshoot.proxy.HttpRequestHandler.messageReceived(HttpRequestHandler.java:208)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.unfoldAndFireMessageReceived(ReplayingDecoder.java:520)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:506)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:443)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:302)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:321)
at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:299)
at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:216)

It is because of the separation of messages in org.jboss.netty.handler.codec.http.HttpRequestDecoder (see parameter maxChunkSize).
Problem is that connection to the server is not yet established and we receive data (it splits content into chunks). If you use maxChunkSize large enough you may not find such a error. Or if you use real chunks.

Here is patch:

Index: org/littleshoot/proxy/HttpRequestHandler.java
===================================================================
--- org/littleshoot/proxy/HttpRequestHandler.java (revision 22737)
+++ org/littleshoot/proxy/HttpRequestHandler.java (working copy)
@@ -315,7 +314,6 @@
else {
log.info("Establishing new connection");
final ChannelFuture cf;
+ ctx.getChannel().setReadable(false);
try {
cf = newChannelFuture(request, inboundChannel, hostAndPort);
} catch (final UnknownHostException e) {
@@ -348,15 +345,8 @@
log.info("Finished write: "+wcf+ " to: "+
request.getMethod()+" "+
request.getUri());
+
+ ctx.getChannel().setReadable(true);
}
});
+ currentChannelFuture = wf;
}
else {
log.info("Could not connect to " + hostAndPort,