public class HttpObjectAggregator extends MessageToMessageDecoder<HttpObject>
ChannelHandler
that aggregates an HttpMessage
and its following HttpContent
s into a single FullHttpRequest
or FullHttpResponse
(depending on if it used to handle requests or responses)
with no following HttpContent
s. It is useful when you don't want to take
care of HTTP messages whose transfer encoding is 'chunked'. Insert this
handler after HttpResponseDecoder
in the ChannelPipeline
if being used to handle
responses, or after HttpRequestDecoder
and HttpResponseEncoder
in the
ChannelPipeline
if being used to handle requests.
ChannelPipeline
p = ...; ... p.addLast("decoder", newHttpRequestDecoder
()); p.addLast("encoder", newHttpResponseEncoder
()); p.addLast("aggregator", newHttpObjectAggregator
(1048576)); ... p.addLast("handler", new HttpRequestHandler());
For convenience, consider putting a HttpServerCodec
before the HttpObjectAggregator
as it functions as both a HttpRequestDecoder
and a HttpResponseEncoder
.
HttpObjectAggregator
may end up sending a HttpResponse
:
Response Status | Condition When Sent |
---|---|
100 Continue | A '100-continue' expectation is received and the 'content-length' doesn't exceed maxContentLength |
417 Expectation Failed | A '100-continue' expectation is received and the 'content-length' exceeds maxContentLength |
413 Request Entity Too Large | Either the 'content-length' or the bytes received so far exceed maxContentLength |
ChannelHandler.Sharable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS |
Constructor and Description |
---|
HttpObjectAggregator(int maxContentLength)
Creates a new instance.
|
HttpObjectAggregator(int maxContentLength,
boolean closeOnExpectationFailed)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
channelInactive(ChannelHandlerContext ctx)
Calls
ChannelHandlerContext.fireChannelInactive() to forward
to the next ChannelInboundHandler in the ChannelPipeline . |
protected void |
decode(ChannelHandlerContext ctx,
HttpObject msg,
java.util.List<java.lang.Object> out)
Decode from one message to an other.
|
int |
getMaxCumulationBufferComponents()
Returns the maximum number of components in the cumulation buffer.
|
void |
handlerAdded(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
handlerRemoved(ChannelHandlerContext ctx)
Do nothing by default, sub-classes may override this method.
|
void |
setMaxCumulationBufferComponents(int maxCumulationBufferComponents)
Sets the maximum number of components in the cumulation buffer.
|
acceptInboundMessage, channelRead
channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, isSharable
public static final int DEFAULT_MAX_COMPOSITEBUFFER_COMPONENTS
public HttpObjectAggregator(int maxContentLength)
maxContentLength
- the maximum length of the aggregated content in bytes.
If the length of the aggregated content exceeds this value,
a TooLongFrameException
will be raised.public HttpObjectAggregator(int maxContentLength, boolean closeOnExpectationFailed)
maxContentLength
- the maximum length of the aggregated content in bytes.
If the length of the aggregated content exceeds this value,
a TooLongFrameException
will be raised.closeOnExpectationFailed
- If a 100-continue response is detected but the content length is too large
then true
means close the connection. otherwise the connection will remain open and data will be
consumed and discarded until the next request is received.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
.protected void decode(ChannelHandlerContext ctx, HttpObject msg, java.util.List<java.lang.Object> out) throws java.lang.Exception
MessageToMessageDecoder
decode
in class MessageToMessageDecoder<HttpObject>
ctx
- the ChannelHandlerContext
which this MessageToMessageDecoder
belongs tomsg
- the message to decode to an other oneout
- the List
to which decoded messages should be addedjava.lang.Exception
- is thrown if an error occurspublic void channelInactive(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelInboundHandlerAdapter
ChannelHandlerContext.fireChannelInactive()
to forward
to the next ChannelInboundHandler
in the ChannelPipeline
.
Sub-classes may override this method to change behavior.channelInactive
in interface ChannelInboundHandler
channelInactive
in class ChannelInboundHandlerAdapter
java.lang.Exception
public void handlerAdded(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerAdded
in interface ChannelHandler
handlerAdded
in class ChannelHandlerAdapter
java.lang.Exception
public void handlerRemoved(ChannelHandlerContext ctx) throws java.lang.Exception
ChannelHandlerAdapter
handlerRemoved
in interface ChannelHandler
handlerRemoved
in class ChannelHandlerAdapter
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.