public class HttpObjectAggregator extends MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
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 HttpObjectDecoder
in the ChannelPipeline
:
Be aware that you need to have theChannelPipeline
p = ...; ... 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, setMaxCumulationBufferComponents
channelRead
bind, channelActive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, close, connect, deregister, disconnect, exceptionCaught, flush, isSharable, read, userEventTriggered, write
public 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
MessageAggregator
true
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>
Exception
protected boolean isContentMessage(HttpObject msg) throws Exception
MessageAggregator
true
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>
Exception
protected boolean isLastContentMessage(HttpContent msg) throws Exception
MessageAggregator
true
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>
Exception
protected boolean isAggregated(HttpObject msg) throws Exception
MessageAggregator
true
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>
Exception
protected boolean hasContentLength(HttpMessage start) throws Exception
MessageAggregator
true
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>
Exception
protected long contentLength(HttpMessage start) throws Exception
MessageAggregator
MessageAggregator.hasContentLength(Object)
returned true
.contentLength
in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
Exception
protected Object newContinueResponse(HttpMessage start) throws Exception
MessageAggregator
newContinueResponse
in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
null
if there's no message to sendException
protected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws Exception
MessageAggregator
ByteBufHolder
, 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>
Exception
protected void aggregate(FullHttpMessage aggregated, HttpContent content) throws Exception
MessageAggregator
aggregated
.aggregate
in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
Exception
protected void finishAggregation(FullHttpMessage aggregated) throws Exception
MessageAggregator
aggregated
message is about to be passed to the next handler in the pipeline.finishAggregation
in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
Exception
protected void handleOversizedMessage(ChannelHandlerContext ctx, HttpMessage oversized) throws Exception
MessageAggregator
exceptionCaught()
event with a TooLongFrameException
.handleOversizedMessage
in class MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
ctx
- the ChannelHandlerContext
oversized
- the accumulated message up to this point, whose type is S
or O
Exception
Copyright © 2008–2015 The Netty Project. All rights reserved.