public abstract class WebSocketServerHandshaker
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.nio.channels.ClosedChannelException |
CLOSED_CHANNEL_EXCEPTION |
protected static InternalLogger |
logger |
private int |
maxFramePayloadLength |
private java.lang.String |
selectedSubprotocol |
static java.lang.String |
SUB_PROTOCOL_WILDCARD
Use this as wildcard to support all requested sub-protocols
|
private java.lang.String[] |
subprotocols |
private java.lang.String |
uri |
private WebSocketVersion |
version |
Modifier | Constructor and Description |
---|---|
protected |
WebSocketServerHandshaker(WebSocketVersion version,
java.lang.String uri,
java.lang.String subprotocols,
int maxFramePayloadLength)
Constructor specifying the destination web socket location
|
Modifier and Type | Method and Description |
---|---|
ChannelFuture |
close(Channel channel,
CloseWebSocketFrame frame)
Performs the closing handshake
|
ChannelFuture |
close(Channel channel,
CloseWebSocketFrame frame,
ChannelPromise promise)
Performs the closing handshake
|
ChannelFuture |
handshake(Channel channel,
FullHttpRequest req)
Performs the opening handshake.
|
ChannelFuture |
handshake(Channel channel,
FullHttpRequest req,
HttpHeaders responseHeaders,
ChannelPromise promise)
Performs the opening handshake
When call this method you MUST NOT retain the
FullHttpRequest which is passed in. |
ChannelFuture |
handshake(Channel channel,
HttpRequest req)
Performs the opening handshake.
|
ChannelFuture |
handshake(Channel channel,
HttpRequest req,
HttpHeaders responseHeaders,
ChannelPromise promise)
Performs the opening handshake
When call this method you MUST NOT retain the
HttpRequest which is passed in. |
int |
maxFramePayloadLength()
Gets the maximum length for any frame's payload.
|
protected abstract FullHttpResponse |
newHandshakeResponse(FullHttpRequest req,
HttpHeaders responseHeaders)
Returns a new {@link FullHttpResponse) which will be used for as response to the handshake request.
|
protected abstract WebSocketFrameDecoder |
newWebsocketDecoder()
Returns the decoder to use after handshake is complete.
|
protected abstract WebSocketFrameEncoder |
newWebSocketEncoder()
Returns the encoder to use after the handshake is complete.
|
java.lang.String |
selectedSubprotocol()
Returns the selected subprotocol.
|
protected java.lang.String |
selectSubprotocol(java.lang.String requestedSubprotocols)
Selects the first matching supported sub protocol
|
java.util.Set<java.lang.String> |
subprotocols()
Returns the CSV of supported sub protocols
|
java.lang.String |
uri()
Returns the URL of the web socket
|
WebSocketVersion |
version()
Returns the version of the specification being supported
|
protected static final InternalLogger logger
private static final java.nio.channels.ClosedChannelException CLOSED_CHANNEL_EXCEPTION
private final java.lang.String uri
private final java.lang.String[] subprotocols
private final WebSocketVersion version
private final int maxFramePayloadLength
private java.lang.String selectedSubprotocol
public static final java.lang.String SUB_PROTOCOL_WILDCARD
protected WebSocketServerHandshaker(WebSocketVersion version, java.lang.String uri, java.lang.String subprotocols, int maxFramePayloadLength)
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 payloadpublic java.lang.String uri()
public java.util.Set<java.lang.String> subprotocols()
public WebSocketVersion version()
public int maxFramePayloadLength()
public ChannelFuture handshake(Channel channel, FullHttpRequest req)
FullHttpRequest
which is passed in.channel
- Channelreq
- HTTP RequestChannelFuture
which is notified once the opening handshake completespublic final ChannelFuture handshake(Channel channel, FullHttpRequest req, HttpHeaders responseHeaders, ChannelPromise promise)
FullHttpRequest
which is passed in.channel
- Channelreq
- HTTP RequestresponseHeaders
- Extra headers to add to the handshake response or null
if no extra headers should be addedpromise
- the ChannelPromise
to be notified when the opening handshake is doneChannelFuture
which is notified when the opening handshake is donepublic ChannelFuture handshake(Channel channel, HttpRequest req)
FullHttpRequest
which is passed in.channel
- Channelreq
- HTTP RequestChannelFuture
which is notified once the opening handshake completespublic final ChannelFuture handshake(Channel channel, HttpRequest req, HttpHeaders responseHeaders, ChannelPromise promise)
HttpRequest
which is passed in.channel
- Channelreq
- HTTP RequestresponseHeaders
- Extra headers to add to the handshake response or null
if no extra headers should be addedpromise
- the ChannelPromise
to be notified when the opening handshake is doneChannelFuture
which is notified when the opening handshake is doneprotected abstract FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders responseHeaders)
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame)
channel
- Channelframe
- Closing Frame that was receivedpublic ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise)
channel
- Channelframe
- Closing Frame that was receivedpromise
- the ChannelPromise
to be notified when the closing handshake is doneprotected java.lang.String selectSubprotocol(java.lang.String requestedSubprotocols)
requestedSubprotocols
- CSV of protocols to be supported. e.g. "chat, superchat"public java.lang.String selectedSubprotocol()
This is only available AFTER handshake() has been called.
protected abstract WebSocketFrameDecoder newWebsocketDecoder()
protected abstract WebSocketFrameEncoder newWebSocketEncoder()