Top Description Fields Constructors Methods
io.netty5.handler.codec.http.websocketx

public Class WebSocketServerProtocolHandler

extends WebSocketProtocolHandler
Class Inheritance
Imports
io.netty5.channel.Channel, .ChannelFutureListeners, .ChannelHandler, .ChannelHandlerContext, .ChannelPipeline, io.netty5.handler.codec.http.DefaultFullHttpResponse, .FullHttpResponse, .HttpResponseStatus, io.netty5.util.AttributeKey, io.netty5.util.concurrent.Promise, java.util.Objects

This handler does all the heavy lifting for you to run a websocket server.

It takes care of websocket handshaking as well as processing of control frames (Close, Ping, Pong). Text and Binary data frames are passed to the next handler in the pipeline (implemented by you) for processing.

See io.netty5.example.http.websocketx.html5.WebSocketServer for usage.

The implementation of this handler assumes that you just want to run a websocket server and not process other types HTTP requests (like GET and POST). If you wish to support both HTTP requests and websockets in the one server, refer to the io.netty5.example.http.websocketx.server.WebSocketServer example.

To know once a handshake was done you can intercept the ChannelHandler#channelInboundEvent(ChannelHandlerContext, Object) and check if the event was instance of WebSocketServerHandshakeCompletionEvent, the event will contain extra information about the handshake such as the request and selected subprotocol.

Field Summary

Modifier and TypeField and Description
private static final AttributeKey<WebSocketServerHandshaker>
private final WebSocketServerProtocolConfig

Constructor Summary

AccessConstructor and Description
public
WebSocketServerProtocolHandler(WebSocketServerProtocolConfig
Server protocol configuration.
serverConfig
)

Base constructor

public
public
WebSocketServerProtocolHandler(String websocketPath, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith)

public
WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis)

public
WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis, WebSocketDecoderConfig decoderConfig)

Method Summary

Modifier and TypeMethod and Description
protected WebSocketServerHandshakeException
buildHandshakeException(String message)

Overrides io.netty5.handler.codec.http.websocketx.WebSocketProtocolHandler.buildHandshakeException.

Returns a WebSocketHandshakeException that depends on which client or server pipeline this handler belongs.
public void
protected void
decodeAndClose(ChannelHandlerContext ctx, WebSocketFrame
the message to decode to another one
frame
)

Overrides io.netty5.handler.codec.http.websocketx.WebSocketProtocolHandler.decodeAndClose.

Decode from one message to another.
pack-priv static WebSocketServerHandshaker
public void
handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.
pack-priv static void
Inherited from io.netty5.handler.codec.http.websocketx.WebSocketProtocolHandler:
closecloseSentdecodewrite

Field Detail

HANDSHAKER_ATTR_KEYback to summary
private static final AttributeKey<WebSocketServerHandshaker> HANDSHAKER_ATTR_KEY
serverConfigback to summary
private final WebSocketServerProtocolConfig serverConfig

Constructor Detail

WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(WebSocketServerProtocolConfig serverConfig)

Base constructor

Parameters
serverConfig:WebSocketServerProtocolConfig

Server protocol configuration.

WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, boolean checkStartsWith, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean allowExtensions, int maxFrameSize, boolean allowMaskMismatch, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis)
WebSocketServerProtocolHandlerback to summary
public WebSocketServerProtocolHandler(String websocketPath, String subprotocols, boolean checkStartsWith, boolean dropPongFrames, long handshakeTimeoutMillis, WebSocketDecoderConfig decoderConfig)

Method Detail

buildHandshakeExceptionback to summary
protected WebSocketServerHandshakeException buildHandshakeException(String message)

Overrides io.netty5.handler.codec.http.websocketx.WebSocketProtocolHandler.buildHandshakeException.

Doc from io.netty5.handler.codec.http.websocketx.WebSocketProtocolHandler.buildHandshakeException.

Returns a WebSocketHandshakeException that depends on which client or server pipeline this handler belongs. Should be overridden in implementation otherwise a default exception is used.

Annotations
@Override
channelExceptionCaughtback to summary
public void channelExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception

Overrides io.netty5.handler.codec.http.websocketx.WebSocketProtocolHandler.channelExceptionCaught.

Overrides default io.netty5.channel.ChannelHandler.channelExceptionCaught.

Doc from io.netty5.channel.ChannelHandler.channelExceptionCaught.

Gets called if a Throwable was thrown when handling inbound events.

Annotations
@Override
decodeAndCloseback to summary
protected void decodeAndClose(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception

Overrides io.netty5.handler.codec.http.websocketx.WebSocketProtocolHandler.decodeAndClose.

Doc from io.netty5.handler.codec.MessageToMessageDecoder.decodeAndClose.

Decode from one message to another. This method will be called for each written message that can be handled by this decoder.

The message will not be automatically disposed of after this call. Instead, the responsibility of ensuring that messages are disposed of falls upon the implementor of this method.

Subclasses that wish to have incoming messages automatically disposed of should instead override the decodeAndClose(ChannelHandlerContext, Object) method.

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext which this MessageToMessageDecoder belongs to

frame:WebSocketFrame

the message to decode to another one

Annotations
@Override
Exceptions
Exception:
is thrown if an error occurs
getHandshakerback to summary
pack-priv static WebSocketServerHandshaker getHandshaker(Channel channel)
handlerAddedback to summary
public void handlerAdded(ChannelHandlerContext ctx)

Overrides default io.netty5.channel.ChannelHandler.handlerAdded.

Doc from io.netty5.channel.ChannelHandler.handlerAdded.

Gets called after the ChannelHandler was added to the actual context and it's ready to handle events.

Annotations
@Override
setHandshakerback to summary
pack-priv static void setHandshaker(Channel channel, WebSocketServerHandshaker handshaker)