public class HttpChunkAggregator extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler
ChannelHandler that aggregates an HttpMessage
and its following HttpChunks into a single HttpMessage with
no following HttpChunks. It is useful when you don't want to take
care of HTTP messages whose transfer encoding is 'chunked'. Insert this
handler after HttpMessageDecoder in the ChannelPipeline:
ChannelPipelinep = ...; ... p.addLast("decoder", newHttpRequestDecoder()); p.addLast("aggregator", newHttpChunkAggregator(1048576)); ... p.addLast("encoder", newHttpResponseEncoder()); p.addLast("handler", new HttpRequestHandler());
ChannelHandler.Sharable| Modifier and Type | Field and Description |
|---|---|
private static ChannelBuffer |
CONTINUE |
private ChannelHandlerContext |
ctx |
private HttpMessage |
currentMessage |
static int |
DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS |
private int |
maxContentLength |
private int |
maxCumulationBufferComponents |
private boolean |
tooLongFrameFound |
| Constructor and Description |
|---|
HttpChunkAggregator(int maxContentLength)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterAdd(ChannelHandlerContext ctx) |
void |
afterRemove(ChannelHandlerContext ctx) |
protected void |
appendToCumulation(ChannelBuffer input) |
void |
beforeAdd(ChannelHandlerContext ctx) |
void |
beforeRemove(ChannelHandlerContext ctx) |
int |
getMaxCumulationBufferComponents()
Returns the maximum number of components in the cumulation buffer.
|
void |
messageReceived(ChannelHandlerContext ctx,
MessageEvent e)
Invoked when a message object (e.g:
ChannelBuffer) was received
from a remote peer. |
void |
setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
Sets the maximum number of components in the cumulation buffer.
|
channelBound, channelClosed, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, exceptionCaught, handleUpstream, writeCompletepublic static final int DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
private static final ChannelBuffer CONTINUE
private final int maxContentLength
private HttpMessage currentMessage
private boolean tooLongFrameFound
private ChannelHandlerContext ctx
private int maxCumulationBufferComponents
public HttpChunkAggregator(int maxContentLength)
maxContentLength - the maximum length of the aggregated content.
If the length of the aggregated content exceeds this value,
a TooLongFrameException will be raised.public final int getMaxCumulationBufferComponents()
DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS.public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
and its minimum allowed value is 2.public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
SimpleChannelUpstreamHandlerChannelBuffer) was received
from a remote peer.messageReceived in class SimpleChannelUpstreamHandlerjava.lang.Exceptionprotected void appendToCumulation(ChannelBuffer input)
public void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
beforeAdd in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
afterAdd in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
beforeRemove in interface LifeCycleAwareChannelHandlerjava.lang.Exceptionpublic void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
afterRemove in interface LifeCycleAwareChannelHandlerjava.lang.Exception