Class WebSocketServerExtensionHandler
java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
io.netty.handler.codec.http.websocketx.extensions.WebSocketServerExtensionHandler
- All Implemented Interfaces:
io.netty.channel.ChannelHandler,io.netty.channel.ChannelInboundHandler,io.netty.channel.ChannelOutboundHandler
- Direct Known Subclasses:
WebSocketServerCompressionHandler
public class WebSocketServerExtensionHandler
extends io.netty.channel.ChannelDuplexHandler
This handler negotiates and initializes the WebSocket Extensions.
It negotiates the extensions based on the client desired order,
ensures that the successfully negotiated extensions are consistent between them,
and initializes the channel pipeline with the extension decoder and encoder.
Find a basic implementation for compression extensions at
io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler.
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler
io.netty.channel.ChannelHandler.Sharable -
Constructor Summary
ConstructorsConstructorDescriptionWebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker... extensionHandshakers) Constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidchannelRead(io.netty.channel.ChannelHandlerContext ctx, Object msg) protected voidonHttpRequestChannelRead(io.netty.channel.ChannelHandlerContext ctx, HttpRequest request) This is a method exposed to perform fail-fast checks of user-defined http types.protected voidonHttpResponseWrite(io.netty.channel.ChannelHandlerContext ctx, HttpResponse response, io.netty.channel.ChannelPromise promise) This is a method exposed to perform fail-fast checks of user-defined http types.voidwrite(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) Methods inherited from class io.netty.channel.ChannelDuplexHandler
bind, close, connect, deregister, disconnect, flush, readMethods inherited from class io.netty.channel.ChannelInboundHandlerAdapter
channelActive, channelInactive, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught, userEventTriggeredMethods inherited from class io.netty.channel.ChannelHandlerAdapter
ensureNotSharable, handlerAdded, handlerRemoved, isSharableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.netty.channel.ChannelHandler
handlerAdded, handlerRemoved
-
Constructor Details
-
WebSocketServerExtensionHandler
Constructor- Parameters:
extensionHandshakers- The extension handshaker in priority order. A handshaker could be repeated many times with fallback configuration.
-
-
Method Details
-
channelRead
- Specified by:
channelReadin interfaceio.netty.channel.ChannelInboundHandler- Overrides:
channelReadin classio.netty.channel.ChannelInboundHandlerAdapter- Throws:
Exception
-
onHttpRequestChannelRead
@UnstableApi protected void onHttpRequestChannelRead(io.netty.channel.ChannelHandlerContext ctx, HttpRequest request) throws Exception This is a method exposed to perform fail-fast checks of user-defined http types.eg:
If the user has defined a specificHttpRequesttype i.e.CustomHttpRequestandchannelRead(io.netty.channel.ChannelHandlerContext, java.lang.Object)can receiveLastHttpContent.EMPTY_LAST_CONTENTmsgtypes too, can override it like this:public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg != LastHttpContent.EMPTY_LAST_CONTENT) { if (msg instanceof CustomHttpRequest) { onHttpRequestChannelRead(ctx, (CustomHttpRequest) msg); } else { // if it's handling other HttpRequest types it MUST use onHttpRequestChannelRead again // or have to delegate it to super.channelRead (that can perform redundant checks). // If msg is not implementing HttpRequest, it can call ctx.fireChannelRead(msg) on it // ... super.channelRead(ctx, msg); } } else { // given that msg isn't a HttpRequest type we can just skip calling super.channelRead ctx.fireChannelRead(msg); } }IMPORTANT: It already callsuper.channelRead(ctx, request)before returning.- Throws:
Exception
-
write
public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception - Specified by:
writein interfaceio.netty.channel.ChannelOutboundHandler- Overrides:
writein classio.netty.channel.ChannelDuplexHandler- Throws:
Exception
-
onHttpResponseWrite
@UnstableApi protected void onHttpResponseWrite(io.netty.channel.ChannelHandlerContext ctx, HttpResponse response, io.netty.channel.ChannelPromise promise) throws Exception This is a method exposed to perform fail-fast checks of user-defined http types.eg:
If the user has defined a specificHttpResponsetype i.e.CustomHttpResponseandwrite(io.netty.channel.ChannelHandlerContext, java.lang.Object, io.netty.channel.ChannelPromise)can receiveByteBufmsgtypes too, it can be overridden like this:public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { if (msg != Unpooled.EMPTY_BUFFER invalid input: '&'invalid input: '&' !(msg instanceof ByteBuf)) { if (msg instanceof CustomHttpResponse) { onHttpResponseWrite(ctx, (CustomHttpResponse) msg, promise); } else { // if it's handling other HttpResponse types it MUST use onHttpResponseWrite again // or have to delegate it to super.write (that can perform redundant checks). // If msg is not implementing HttpResponse, it can call ctx.write(msg, promise) on it // ... super.write(ctx, msg, promise); } } else { // given that msg isn't a HttpResponse type we can just skip calling super.write ctx.write(msg, promise); } }IMPORTANT: It already callsuper.write(ctx, response, promise)before returning.- Throws:
Exception
-