public class HttpObjectAggregator extends MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
ChannelHandler
,其将HttpMessage
及其后续的HttpContent
汇总为单个FullHttpRequest
或FullHttpResponse
(取决于是否用于处理请求或响应)而没有以下HttpContent
。
当您不想处理传输编码为“分块”的HTTP消息时,它非常有用。
插入后,该处理器HttpResponseDecoder
在ChannelPipeline
如果被用来处理响应,或之后HttpRequestDecoder
和HttpResponseEncoder
在ChannelPipeline
如果被用来处理请求。
ChannelPipeline
p = ...; ... p.addLast("decoder", newHttpRequestDecoder
()); p.addLast("encoder", newHttpResponseEncoder
()); p.addLast("aggregator", newHttpObjectAggregator
(1048576)); ... p.addLast("handler", new HttpRequestHandler());
为了方便起见,可以考虑把一个HttpServerCodec
的前HttpObjectAggregator
,因为它的功能既是HttpRequestDecoder
和HttpResponseEncoder
。
HttpObjectAggregator
最终可能会发送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
Constructor and Description |
---|
HttpObjectAggregator(int maxContentLength)
创建一个新的实例。
|
HttpObjectAggregator(int maxContentLength, boolean closeOnExpectationFailed)
创建一个新的实例。
|
Modifier and Type | Method and Description |
---|---|
protected void |
aggregate(FullHttpMessage aggregated, HttpContent content)
将指定内容消息提供的信息传输到指定的聚合消息。
|
protected FullHttpMessage |
beginAggregation(HttpMessage start, ByteBuf content)
根据指定的开始消息和指定的内容创建新的聚合消息。
|
protected boolean |
closeAfterContinueResponse(java.lang.Object msg)
在写入
MessageAggregator.newContinueResponse(Object, int, ChannelPipeline) 的结果后,确定通道是否应该关闭。
|
protected void |
finishAggregation(FullHttpMessage aggregated)
当指定的
aggregated 消息即将传递给管道中的下一个处理程序时调用。
|
protected void |
handleOversizedMessage(ChannelHandlerContext ctx, HttpMessage oversized)
当传入请求超过最大内容长度时调用。
|
protected boolean |
ignoreContentAfterContinueResponse(java.lang.Object msg)
确定当前请求/响应的所有对象是否应该被忽略。
|
protected boolean |
isAggregated(HttpObject msg)
当且仅当指定的消息已经聚合时返回
true 。
|
protected boolean |
isContentLengthInvalid(HttpMessage start, int maxContentLength)
确定消息
start 的内容长度是否已知,并且是否大于
maxContentLength 。
|
protected boolean |
isContentMessage(HttpObject msg)
当且仅当指定的消息是内容消息时返回
true 。
|
protected boolean |
isLastContentMessage(HttpContent msg)
当且仅当指定的消息是最后一个内容消息时才返回
true 。
|
protected boolean |
isStartMessage(HttpObject msg)
当且仅当指定的消息是开始消息时返回
true 。
|
protected java.lang.Object |
newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline)
如有必要,返回指定开始消息的'continue response'。
|
acceptInboundMessage, channelInactive, channelReadComplete, ctx, decode, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, setMaxCumulationBufferComponents
channelRead
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggered
ensureNotSharable, isSharable
public HttpObjectAggregator(int maxContentLength)
maxContentLength
- 聚合内容的最大长度(以字节为单位)。
如果聚集内容的长度超过此值,则将调用handleOversizedMessage(ChannelHandlerContext, HttpMessage)
。
public HttpObjectAggregator(int maxContentLength, boolean closeOnExpectationFailed)
maxContentLength
- 聚合内容的最大长度(以字节为单位)。
如果聚合内容的长度超过此值,则将调用handleOversizedMessage(ChannelHandlerContext, HttpMessage)
。
closeOnExpectationFailed
- 如果检测到100连续响应但内容长度过大,则true
表示关闭连接。
否则连接将保持打开状态,数据将被消耗并丢弃,直到收到下一个请求。
protected boolean isStartMessage(HttpObject msg) throws java.lang.Exception
MessageAggregator
true
。
通常,这种方法是作为一个return
声明与instanceof
:
return msg instanceof MyStartMessage;
isStartMessage
在课堂上
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
java.lang.Exception
protected boolean isContentMessage(HttpObject msg) throws java.lang.Exception
MessageAggregator
true
。
通常,这种方法是作为一个return
声明与instanceof
:
return msg instanceof MyContentMessage;
isContentMessage
类
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
java.lang.Exception
protected boolean isLastContentMessage(HttpContent msg) throws java.lang.Exception
MessageAggregator
true
。
通常,此方法是作为一个return
声明与instanceof
:
return msg instanceof MyLastContentMessage;
或者用instanceof
和布尔字段检查:
return msg instanceof MyContentMessage && msg.isLastFragment();
isLastContentMessage
在课堂上
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
java.lang.Exception
protected boolean isAggregated(HttpObject msg) throws java.lang.Exception
MessageAggregator
true
。
如果此方法返回true
,则此处理程序将仅将消息按true
转发给下一个处理程序。
isAggregated
在类
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
java.lang.Exception
protected boolean isContentLengthInvalid(HttpMessage start, int maxContentLength)
MessageAggregator
start
的内容长度是否已知,并且是否大于
maxContentLength
。
isContentLengthInvalid
在课堂上
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
start
- 可能指示内容长度的消息。
maxContentLength
- 允许的最大内容长度。
true
如果消息start
的内容长度已知,并且它大于maxContentLength
。
false
否则。
protected java.lang.Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline)
MessageAggregator
newContinueResponse
在课程
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
null
如果没有消息要发送
protected boolean closeAfterContinueResponse(java.lang.Object msg)
MessageAggregator
MessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
的结果之后,确定通道是否应该关闭。
closeAfterContinueResponse
在课堂上
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
msg
-从返回值
MessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
。
true
如果在写入MessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
的结果后关闭通道。
false
否则。
protected boolean ignoreContentAfterContinueResponse(java.lang.Object msg)
MessageAggregator
MessageAggregator.isContentMessage(Object)
返回true
时,消息将不再被忽略。
ignoreContentAfterContinueResponse
在课堂上
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
msg
-从返回值
MessageAggregator.newContinueResponse(Object, int, ChannelPipeline)
。
true
如果当前请求/响应的所有对象都应该被忽略。
false
否则。
protected FullHttpMessage beginAggregation(HttpMessage start, ByteBuf content) throws java.lang.Exception
MessageAggregator
beginAggregation
在类
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
java.lang.Exception
protected void aggregate(FullHttpMessage aggregated, HttpContent content) throws java.lang.Exception
MessageAggregator
aggregated
。
aggregate
在课程
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
java.lang.Exception
protected void finishAggregation(FullHttpMessage aggregated) throws java.lang.Exception
MessageAggregator
aggregated
消息即将传递给管道中的下一个处理程序时调用。
finishAggregation
在类
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
java.lang.Exception
protected void handleOversizedMessage(ChannelHandlerContext ctx, HttpMessage oversized) throws java.lang.Exception
MessageAggregator
exceptionCaught()
事件与TooLongFrameException
。
handleOversizedMessage
,等级
MessageAggregator<HttpObject,HttpMessage,HttpContent,FullHttpMessage>
ctx
- ChannelHandlerContext
oversized
-
oversized
积累的信息,其类型为
S
或
O
java.lang.Exception
Copyright © 2008–2018 The Netty Project. All rights reserved.