Class WebSocketServerHandshaker
java.lang.Object
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker
- Direct Known Subclasses:
WebSocketServerHandshaker00, WebSocketServerHandshaker07, WebSocketServerHandshaker08, WebSocketServerHandshaker13
Base class for server side web socket opening and closing handshakes
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final InternalLoggerstatic final StringUse this as wildcard to support all requested sub-protocols -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, int maxFramePayloadLength) Constructor specifying the destination web socket locationprotectedWebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, WebSocketDecoderConfig decoderConfig) Constructor specifying the destination web socket location -
Method Summary
Modifier and TypeMethodDescriptionclose(ChannelHandlerContext ctx, CloseWebSocketFrame frame) Performs the closing handshake.close(ChannelHandlerContext ctx, CloseWebSocketFrame frame, ChannelPromise promise) Performs the closing handshake.close(Channel channel, CloseWebSocketFrame frame) Performs the closing handshake.close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) Performs the closing handshake.Gets this decoder configuration.handshake(Channel channel, FullHttpRequest req) Performs the opening handshake.final ChannelFuturehandshake(Channel channel, FullHttpRequest req, HttpHeaders responseHeaders, ChannelPromise promise) Performs the opening handshake When call this method you MUST NOT retain theFullHttpRequestwhich is passed in.handshake(Channel channel, HttpRequest req) Performs the opening handshake.final ChannelFuturehandshake(Channel channel, HttpRequest req, HttpHeaders responseHeaders, ChannelPromise promise) Performs the opening handshake When call this method you MUST NOT retain theHttpRequestwhich is passed in.intGets the maximum length for any frame's payload.protected abstract FullHttpResponsenewHandshakeResponse(FullHttpRequest req, HttpHeaders responseHeaders) Returns a newinvalid @link
{@link FullHttpResponse) which will be used for as response to the handshake request.protected abstract WebSocketFrameDecoderReturns the decoder to use after handshake is complete.protected abstract WebSocketFrameEncoderReturns the encoder to use after the handshake is complete.Returns the selected subprotocol.protected StringselectSubprotocol(String requestedSubprotocols) Selects the first matching supported sub protocolReturns the CSV of supported sub protocolsuri()Deprecated.version()Returns the version of the specification being supported
-
Field Details
-
logger
-
SUB_PROTOCOL_WILDCARD
Use this as wildcard to support all requested sub-protocols- See Also:
-
-
Constructor Details
-
WebSocketServerHandshaker
protected WebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, int maxFramePayloadLength) Constructor specifying the destination web socket location- Parameters:
version- the protocol versionuri- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.subprotocols- CSV of supported protocols. Null if sub protocols not supported.maxFramePayloadLength- Maximum length of a frame's payload
-
WebSocketServerHandshaker
protected WebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, WebSocketDecoderConfig decoderConfig) Constructor specifying the destination web socket location- Parameters:
version- the protocol versionuri- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.subprotocols- CSV of supported protocols. Null if sub protocols not supported.decoderConfig- Frames decoder configuration.
-
-
Method Details
-
uri
-
subprotocols
-
version
Returns the version of the specification being supported -
maxFramePayloadLength
public int maxFramePayloadLength()Gets the maximum length for any frame's payload.- Returns:
- The maximum length for a frame's payload
-
decoderConfig
Gets this decoder configuration.- Returns:
- This decoder configuration.
-
handshake
Performs the opening handshake. When call this method you MUST NOT retain theFullHttpRequestwhich is passed in.- Parameters:
channel- Channelreq- HTTP Request- Returns:
- future
The
ChannelFuturewhich is notified once the opening handshake completes
-
handshake
public final ChannelFuture handshake(Channel channel, FullHttpRequest req, HttpHeaders responseHeaders, ChannelPromise promise) Performs the opening handshake When call this method you MUST NOT retain theFullHttpRequestwhich is passed in.- Parameters:
channel- Channelreq- HTTP RequestresponseHeaders- Extra headers to add to the handshake response ornullif no extra headers should be addedpromise- theChannelPromiseto be notified when the opening handshake is done- Returns:
- future
the
ChannelFuturewhich is notified when the opening handshake is done
-
handshake
Performs the opening handshake. When call this method you MUST NOT retain theFullHttpRequestwhich is passed in.- Parameters:
channel- Channelreq- HTTP Request- Returns:
- future
The
ChannelFuturewhich is notified once the opening handshake completes
-
handshake
public final ChannelFuture handshake(Channel channel, HttpRequest req, HttpHeaders responseHeaders, ChannelPromise promise) Performs the opening handshake When call this method you MUST NOT retain theHttpRequestwhich is passed in.- Parameters:
channel- Channelreq- HTTP RequestresponseHeaders- Extra headers to add to the handshake response ornullif no extra headers should be addedpromise- theChannelPromiseto be notified when the opening handshake is done- Returns:
- future
the
ChannelFuturewhich is notified when the opening handshake is done
-
newHandshakeResponse
protected abstract FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders responseHeaders) Returns a newinvalid @link
{@link FullHttpResponse) which will be used for as response to the handshake request. -
close
Performs the closing handshake. When called from within aChannelHandleryou most likely want to useclose(ChannelHandlerContext, CloseWebSocketFrame).- Parameters:
channel- theChannelto use.frame- Closing Frame that was received.
-
close
Performs the closing handshake. When called from within aChannelHandleryou most likely want to useclose(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise).- Parameters:
channel- theChannelto use.frame- Closing Frame that was received.promise- theChannelPromiseto be notified when the closing handshake is done
-
close
Performs the closing handshake.- Parameters:
ctx- theChannelHandlerContextto use.frame- Closing Frame that was received.
-
close
public ChannelFuture close(ChannelHandlerContext ctx, CloseWebSocketFrame frame, ChannelPromise promise) Performs the closing handshake.- Parameters:
ctx- theChannelHandlerContextto use.frame- Closing Frame that was received.promise- theChannelPromiseto be notified when the closing handshake is done.
-
selectSubprotocol
-
selectedSubprotocol
Returns the selected subprotocol. Null if no subprotocol has been selected.This is only available AFTER handshake() has been called.
-
newWebsocketDecoder
Returns the decoder to use after handshake is complete. -
newWebSocketEncoder
Returns the encoder to use after the handshake is complete.
-