public class HttpObjectAggregator extends MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
ChannelHandler that aggregates an HttpMessage
and its following HttpContents into a single FullHttpRequest
or FullHttpResponse (depending on if it used to handle requests or responses)
with no following HttpContents. It is useful when you don't want to take
care of HTTP messages whose transfer encoding is 'chunked'. Insert this
handler after HttpObjectDecoder in the ChannelPipeline:
Be aware that you need to have theChannelPipelinep = ...; ... p.addLast("encoder", newHttpResponseEncoder()); p.addLast("decoder", newHttpRequestDecoder()); p.addLast("aggregator", newHttpObjectAggregator(1048576)); ... p.addLast("handler", new HttpRequestHandler());
HttpResponseEncoder or HttpRequestEncoder
before the HttpObjectAggregator in the ChannelPipeline.ChannelHandler.Sharable, ChannelHandler.Skip| Constructor and Description |
|---|
HttpObjectAggregator(int maxContentLength)
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
aggregate(FullHttpMessage aggregated,
HttpContent content)
Transfers the information provided by the specified content message to the specified aggregated message.
|
protected FullHttpMessage |
beginAggregation(HttpMessage start,
ByteBuf content)
Creates a new aggregated message from the specified start message and the specified content.
|
protected long |
contentLength(HttpMessage start)
Retrieves the length of the whole content from the specified start message.
|
protected void |
finishAggregation(FullHttpMessage aggregated)
Invoked when the specified
aggregated message is about to be passed to the next handler in the pipeline. |
protected void |
handleOversizedMessage(ChannelHandlerContext ctx,
HttpMessage oversized)
Invoked when an incoming request exceeds the maximum content length.
|
protected boolean |
hasContentLength(HttpMessage start)
Returns
true if and only if the specified start message already contains the information about the
length of the whole content. |
protected boolean |
isAggregated(HttpObject msg)
Returns
true if and only if the specified message is already aggregated. |
protected boolean |
isContentMessage(HttpObject msg)
Returns
true if and only if the specified message is a content message. |
protected boolean |
isLastContentMessage(HttpContent msg)
Returns
true if and only if the specified message is the last content message. |
protected boolean |
isStartMessage(HttpObject msg)
Returns
true if and only if the specified message is a start message. |
protected Object |
newContinueResponse(HttpMessage start)
Returns the 'continue response' for the specified start message if necessary.
|
acceptInboundMessage, channelInactive, ctx, decode, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, setMaxCumulationBufferComponentschannelReadbind, channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, isSharable, read, userEventTriggered, writepublic HttpObjectAggregator(int maxContentLength)
maxContentLength - the maximum length of the aggregated content.
If the length of the aggregated content exceeds this value,
handleOversizedMessage(ChannelHandlerContext, HttpMessage)
will be called.protected boolean isStartMessage(HttpObject msg) throws Exception
MessageAggregatortrue if and only if the specified message is a start message. Typically, this method is
implemented as a single return statement with instanceof:
return msg instanceof MyStartMessage;
isStartMessage in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean isContentMessage(HttpObject msg) throws Exception
MessageAggregatortrue if and only if the specified message is a content message. Typically, this method is
implemented as a single return statement with instanceof:
return msg instanceof MyContentMessage;
isContentMessage in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean isLastContentMessage(HttpContent msg) throws Exception
MessageAggregatortrue if and only if the specified message is the last content message. Typically, this method is
implemented as a single return statement with instanceof:
return msg instanceof MyLastContentMessage;or with
instanceof and boolean field check:
return msg instanceof MyContentMessage && msg.isLastFragment();
isLastContentMessage in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean isAggregated(HttpObject msg) throws Exception
MessageAggregatortrue if and only if the specified message is already aggregated. If this method returns
true, this handler will simply forward the message to the next handler as-is.isAggregated in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected boolean hasContentLength(HttpMessage start) throws Exception
MessageAggregatortrue if and only if the specified start message already contains the information about the
length of the whole content.hasContentLength in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected long contentLength(HttpMessage start) throws Exception
MessageAggregatorMessageAggregator.hasContentLength(Object) returned true.contentLength in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected Object newContinueResponse(HttpMessage start) throws Exception
MessageAggregatornewContinueResponse in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>null if there's no message to sendExceptionprotected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws Exception
MessageAggregatorByteBufHolder, its content is appended to the specified content.
This aggregator will continue to append the received content to the specified content.beginAggregation in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected void aggregate(FullHttpMessage aggregated, HttpContent content) throws Exception
MessageAggregatoraggregated.aggregate in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected void finishAggregation(FullHttpMessage aggregated) throws Exception
MessageAggregatoraggregated message is about to be passed to the next handler in the pipeline.finishAggregation in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>Exceptionprotected void handleOversizedMessage(ChannelHandlerContext ctx, HttpMessage oversized) throws Exception
MessageAggregatorexceptionCaught() event with a TooLongFrameException.handleOversizedMessage in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>ctx - the ChannelHandlerContextoversized - the accumulated message up to this point, whose type is S or OExceptionCopyright © 2008–2015 The Netty Project. All rights reserved.