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
AChannelHandlerthat aggregates anHttpMessageand its followingHttpChunks into a singleHttpMessagewith no followingHttpChunks. It is useful when you don't want to take care of HTTP messages whose transfer encoding is 'chunked'. Insert this handler afterHttpMessageDecoderin theChannelPipeline:ChannelPipelinep = ...; ... 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 ChannelBufferCONTINUEprivate ChannelHandlerContextctxprivate HttpMessagecurrentMessagestatic intDEFAULT_MAX_COMPOSITEBUFFER_COMPONENTSprivate intmaxContentLengthprivate intmaxCumulationBufferComponentsprivate booleantooLongFrameFound
-
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 voidafterAdd(ChannelHandlerContext ctx)voidafterRemove(ChannelHandlerContext ctx)protected voidappendToCumulation(ChannelBuffer input)voidbeforeAdd(ChannelHandlerContext ctx)voidbeforeRemove(ChannelHandlerContext ctx)intgetMaxCumulationBufferComponents()Returns the maximum number of components in the cumulation buffer.voidmessageReceived(ChannelHandlerContext ctx, MessageEvent e)Invoked when a message object (e.g:ChannelBuffer) was received from a remote peer.voidsetMaxCumulationBufferComponents(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, aTooLongFrameExceptionwill 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_COMPONENTSand its minimum allowed value is2.
-
messageReceived
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws java.lang.Exception
Description copied from class:SimpleChannelUpstreamHandlerInvoked when a message object (e.g:ChannelBuffer) was received from a remote peer.- Overrides:
messageReceivedin classSimpleChannelUpstreamHandler- Throws:
java.lang.Exception
-
appendToCumulation
protected void appendToCumulation(ChannelBuffer input)
-
beforeAdd
public void beforeAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeAddin interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
afterAdd
public void afterAdd(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterAddin interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
beforeRemove
public void beforeRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
beforeRemovein interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
afterRemove
public void afterRemove(ChannelHandlerContext ctx) throws java.lang.Exception
- Specified by:
afterRemovein interfaceLifeCycleAwareChannelHandler- Throws:
java.lang.Exception
-
-