Top Description Fields Constructors Methods
io.netty.handler.codec.http.websocketx.extensions

public Class WebSocketServerExtensionHandler

extends ChannelDuplexHandler
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler
Static Imports
io.netty.util.internal.ObjectUtil.checkNonEmpty

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.

Field Summary

Modifier and TypeField and Description
private final List<WebSocketServerExtensionHandshaker>
private final Queue<List<WebSocketServerExtension>>

Constructor Summary

AccessConstructor and Description
public
WebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker...
The extension handshaker in priority order. A handshaker could be repeated many times with fallback configuration.
extensionHandshakers
)

Constructor

Method Summary

Modifier and TypeMethod and Description
public void
private void
handlePotentialUpgrade(final ChannelHandlerContext ctx, ChannelPromise promise, HttpResponse httpResponse, final List<WebSocketServerExtension> validExtensionsList)

protected void
onHttpRequestChannelRead(ChannelHandlerContext ctx, HttpRequest request)

This is a method exposed to perform fail-fast checks of user-defined http types.

protected void
onHttpResponseWrite(ChannelHandlerContext ctx, HttpResponse response, ChannelPromise promise)

This is a method exposed to perform fail-fast checks of user-defined http types.

public void
write(final ChannelHandlerContext
the ChannelHandlerContext for which the write operation is made
ctx
,
Object
the message to write
msg
,
ChannelPromise
the ChannelPromise to notify once the operation completes
promise
)

Overrides io.netty.channel.ChannelDuplexHandler.write.

Implements io.netty.channel.ChannelOutboundHandler.write.

Calls ChannelHandlerContext#write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline.
Inherited from io.netty.channel.ChannelDuplexHandler:
bindcloseconnectderegisterdisconnectflushread

Field Detail

extensionHandshakersback to summary
private final List<WebSocketServerExtensionHandshaker> extensionHandshakers
validExtensionsback to summary
private final Queue<List<WebSocketServerExtension>> validExtensions

Constructor Detail

WebSocketServerExtensionHandlerback to summary
public WebSocketServerExtensionHandler(WebSocketServerExtensionHandshaker... extensionHandshakers)

Constructor

Parameters
extensionHandshakers:WebSocketServerExtensionHandshaker[]

The extension handshaker in priority order. A handshaker could be repeated many times with fallback configuration.

Method Detail

channelReadback to summary
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception

Overrides io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Implements io.netty.channel.ChannelInboundHandler.channelRead.

Doc from io.netty.channel.ChannelInboundHandlerAdapter.channelRead.

Calls ChannelHandlerContext#fireChannelRead(Object) to forward to the next ChannelInboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Annotations
@Override
handlePotentialUpgradeback to summary
private void handlePotentialUpgrade(final ChannelHandlerContext ctx, ChannelPromise promise, HttpResponse httpResponse, final List<WebSocketServerExtension> validExtensionsList)
onHttpRequestChannelReadback to summary
protected void onHttpRequestChannelRead(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 specific HttpRequest type i.e.CustomHttpRequest and channelRead can receive LastHttpContent#EMPTY_LAST_CONTENT msg types 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 Note

It already call super.channelRead(ctx, request) before returning.

Annotations
@UnstableApi
onHttpResponseWriteback to summary
protected void onHttpResponseWrite(ChannelHandlerContext ctx, HttpResponse response, 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 specific HttpResponse type i.e.CustomHttpResponse and write can receive ByteBuf msg types too, it can be overridden like this:

    public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        if (msg != Unpooled.EMPTY_BUFFER && !(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 Note

It already call super.write(ctx, response, promise) before returning.

Annotations
@UnstableApi
writeback to summary
public void write(final ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception

Overrides io.netty.channel.ChannelDuplexHandler.write.

Implements io.netty.channel.ChannelOutboundHandler.write.

Doc from io.netty.channel.ChannelDuplexHandler.write.

Calls ChannelHandlerContext#write(Object, ChannelPromise) to forward to the next ChannelOutboundHandler in the ChannelPipeline. Sub-classes may override this method to change behavior.

Parameters
ctx:ChannelHandlerContext

Doc from io.netty.channel.ChannelOutboundHandler.write.

the ChannelHandlerContext for which the write operation is made

msg:Object

Doc from io.netty.channel.ChannelOutboundHandler.write.

the message to write

promise:ChannelPromise

Doc from io.netty.channel.ChannelOutboundHandler.write.

the ChannelPromise to notify once the operation completes

Annotations
@Override
Exceptions
Exception:

Doc from io.netty.channel.ChannelOutboundHandler.write.

thrown if an error occurs