Class HttpChunkAggregator
- java.lang.Object
-
- org.jboss.netty.channel.SimpleChannelUpstreamHandler
-
- org.jboss.netty.handler.codec.http.HttpChunkAggregator
-
- All Implemented Interfaces:
ChannelHandler
,ChannelUpstreamHandler
,LifeCycleAwareChannelHandler
public class HttpChunkAggregator extends SimpleChannelUpstreamHandler implements LifeCycleAwareChannelHandler
AChannelHandler
that aggregates anHttpMessage
and its followingHttpChunk
s into a singleHttpMessage
with no followingHttpChunk
s. It is useful when you don't want to take care of HTTP messages whose transfer encoding is 'chunked'. Insert this handler afterHttpMessageDecoder
in theChannelPipeline
:ChannelPipeline
p = ...; ... p.addLast("decoder", newHttpRequestDecoder
()); p.addLast("aggregator", newHttpChunkAggregator
(1048576)); ... p.addLast("encoder", newHttpResponseEncoder
()); p.addLast("handler", new HttpRequestHandler());
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.jboss.netty.channel.ChannelHandler
ChannelHandler.Sharable
-
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description HttpChunkAggregator(int maxContentLength)
Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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.-
Methods inherited from class org.jboss.netty.channel.SimpleChannelUpstreamHandler
channelBound, channelClosed, channelConnected, channelDisconnected, channelInterestChanged, channelOpen, channelUnbound, childChannelClosed, childChannelOpen, exceptionCaught, handleUpstream, writeComplete
-
-
-
-
Field Detail
-
DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
public static final int DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
- See Also:
- Constant Field Values
-
CONTINUE
private static final ChannelBuffer CONTINUE
-
maxContentLength
private final int maxContentLength
-
currentMessage
private HttpMessage currentMessage
-
tooLongFrameFound
private boolean tooLongFrameFound
-
ctx
private ChannelHandlerContext ctx
-
maxCumulationBufferComponents
private int maxCumulationBufferComponents
-
-
Constructor Detail
-
HttpChunkAggregator
public HttpChunkAggregator(int maxContentLength)
Creates a new instance.- Parameters:
maxContentLength
- the maximum length of the aggregated content. If the length of the aggregated content exceeds this value, aTooLongFrameException
will be raised.
-
-
Method Detail
-
getMaxCumulationBufferComponents
public final int getMaxCumulationBufferComponents()
Returns the maximum number of components in the cumulation buffer. If the number of the components in the cumulation buffer exceeds this value, the components of the cumulation buffer are consolidated into a single component, involving memory copies. The default value of this property isDEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
.
-
setMaxCumulationBufferComponents
public final void setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
Sets the maximum number of components in the cumulation buffer. If the number of the components in the cumulation buffer exceeds this value, the components of the cumulation buffer are consolidated into a single component, involving memory copies. The default value of this property isDEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
and its minimum allowed value is2
.
-
messageReceived
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
Description copied from class:SimpleChannelUpstreamHandler
Invoked when a message object (e.g:ChannelBuffer
) was received from a remote peer.- Overrides:
messageReceived
in classSimpleChannelUpstreamHandler
- Throws:
java.lang.Exception
-
appendToCumulation
protected void appendToCumulation(ChannelBuffer input)
-
beforeAdd
public void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeAdd
in interfaceLifeCycleAwareChannelHandler
- Throws:
java.lang.Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterAdd
in interfaceLifeCycleAwareChannelHandler
- Throws:
java.lang.Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeRemove
in interfaceLifeCycleAwareChannelHandler
- Throws:
java.lang.Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterRemove
in interfaceLifeCycleAwareChannelHandler
- Throws:
java.lang.Exception
-
-