Class WebSocketFrameAggregator
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.handler.codec.MessageToMessageDecoder<WebSocketFrame>
io.netty.handler.codec.MessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>
io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator
- All Implemented Interfaces:
ChannelHandler, ChannelInboundHandler
public class WebSocketFrameAggregator
extends MessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>
Handler that aggregate fragmented WebSocketFrame's.
Be aware if PING/PONG/CLOSE frames are send in the middle of a fragmented
WebSocketFrame they will
just get forwarded to the next handler in the pipeline.-
Nested Class Summary
Nested classes/interfaces inherited from interface ChannelHandler
ChannelHandler.Sharable -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected WebSocketFramebeginAggregation(WebSocketFrame start, ByteBuf content) Creates a new aggregated message from the specified start message and the specified content.protected booleanDetermine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.protected booleanDetermine if all objects for the current request/response should be ignored or not.protected booleanReturnstrueif and only if the specified message is already aggregated.protected booleanisContentLengthInvalid(WebSocketFrame start, int maxContentLength) Determine if the messagestart's content length is known, and if it greater thanmaxContentLength.protected booleanReturnstrueif and only if the specified message is a content message.protected booleanReturnstrueif and only if the specified message is the last content message.protected booleanReturnstrueif and only if the specified message is a start message.protected ObjectnewContinueResponse(WebSocketFrame start, int maxContentLength, ChannelPipeline pipeline) Returns the 'continue response' for the specified start message if necessary.Methods inherited from class MessageAggregator
acceptInboundMessage, aggregate, channelInactive, channelReadComplete, ctx, decode, finishAggregation, handleOversizedMessage, handlerAdded, handlerRemoved, isHandlingOversizedMessage, maxContentLength, maxCumulationBufferComponents, releaseCurrentMessage, setMaxCumulationBufferComponentsMethods inherited from class MessageToMessageDecoder
channelReadMethods inherited from class ChannelInboundHandlerAdapter
channelActive, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class ChannelHandlerAdapter
ensureNotSharable, isSharable
-
Constructor Details
-
WebSocketFrameAggregator
public WebSocketFrameAggregator(int maxContentLength) Creates a new instance- Parameters:
maxContentLength- If the size of the aggregated frame exceeds this value, aTooLongFrameExceptionis thrown.
-
-
Method Details
-
isStartMessage
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is a start message. Typically, this method is implemented as a singlereturnstatement withinstanceof:return msg instanceof MyStartMessage;
- Specified by:
isStartMessagein classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Throws:
Exception
-
isContentMessage
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is a content message. Typically, this method is implemented as a singlereturnstatement withinstanceof:return msg instanceof MyContentMessage;
- Specified by:
isContentMessagein classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Throws:
Exception
-
isLastContentMessage
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is the last content message. Typically, this method is implemented as a singlereturnstatement withinstanceof:return msg instanceof MyLastContentMessage;
or withinstanceofand boolean field check:return msg instanceof MyContentMessage invalid input: '&'invalid input: '&' msg.isLastFragment();
- Specified by:
isLastContentMessagein classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Throws:
Exception
-
isAggregated
Description copied from class:MessageAggregatorReturnstrueif and only if the specified message is already aggregated. If this method returnstrue, this handler will simply forward the message to the next handler as-is.- Specified by:
isAggregatedin classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Throws:
Exception
-
isContentLengthInvalid
Description copied from class:MessageAggregatorDetermine if the messagestart's content length is known, and if it greater thanmaxContentLength.- Specified by:
isContentLengthInvalidin classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Parameters:
start- The message which may indicate the content length.maxContentLength- The maximum allowed content length.- Returns:
trueif the messagestart's content length is known, and if it greater thanmaxContentLength.falseotherwise.
-
newContinueResponse
protected Object newContinueResponse(WebSocketFrame start, int maxContentLength, ChannelPipeline pipeline) Description copied from class:MessageAggregatorReturns the 'continue response' for the specified start message if necessary. For example, this method is useful to handle an HTTP 100-continue header.- Specified by:
newContinueResponsein classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Returns:
- the 'continue response', or
nullif there's no message to send
-
closeAfterContinueResponse
Description copied from class:MessageAggregatorDetermine if the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.- Specified by:
closeAfterContinueResponsein classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Parameters:
msg- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline).- Returns:
trueif the channel should be closed after the result ofMessageAggregator.newContinueResponse(Object, int, ChannelPipeline)is written.falseotherwise.- Throws:
Exception
-
ignoreContentAfterContinueResponse
Description copied from class:MessageAggregatorDetermine if all objects for the current request/response should be ignored or not. Messages will stop being ignored the next timeMessageAggregator.isContentMessage(Object)returnstrue.- Specified by:
ignoreContentAfterContinueResponsein classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Parameters:
msg- The return value fromMessageAggregator.newContinueResponse(Object, int, ChannelPipeline).- Returns:
trueif all objects for the current request/response should be ignored or not.falseotherwise.- Throws:
Exception
-
beginAggregation
Description copied from class:MessageAggregatorCreates a new aggregated message from the specified start message and the specified content. If the start message implementsByteBufHolder, its content is appended to the specifiedcontent. This aggregator will continue to append the received content to the specifiedcontent.- Specified by:
beginAggregationin classMessageAggregator<WebSocketFrame, WebSocketFrame, ContinuationWebSocketFrame, WebSocketFrame>- Throws:
Exception
-