Class WebSocketServerHandshaker
- java.lang.Object
-
- io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker
-
- Direct Known Subclasses:
WebSocketServerHandshaker00
,WebSocketServerHandshaker07
,WebSocketServerHandshaker08
,WebSocketServerHandshaker13
public abstract class WebSocketServerHandshaker extends Object
Base class for server side web socket opening and closing handshakes
-
-
Field Summary
Fields Modifier and Type Field Description protected static io.netty.util.internal.logging.InternalLogger
logger
static String
SUB_PROTOCOL_WILDCARD
Use this as wildcard to support all requested sub-protocols
-
Constructor Summary
Constructors Modifier Constructor Description protected
WebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, int maxFramePayloadLength)
Constructor specifying the destination web socket locationprotected
WebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, WebSocketDecoderConfig decoderConfig)
Constructor specifying the destination web socket location
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description io.netty.channel.ChannelFuture
close(io.netty.channel.ChannelHandlerContext ctx, CloseWebSocketFrame frame)
Performs the closing handshake.io.netty.channel.ChannelFuture
close(io.netty.channel.ChannelHandlerContext ctx, CloseWebSocketFrame frame, io.netty.channel.ChannelPromise promise)
Performs the closing handshake.io.netty.channel.ChannelFuture
close(io.netty.channel.Channel channel, CloseWebSocketFrame frame)
Performs the closing handshake.io.netty.channel.ChannelFuture
close(io.netty.channel.Channel channel, CloseWebSocketFrame frame, io.netty.channel.ChannelPromise promise)
Performs the closing handshake.WebSocketDecoderConfig
decoderConfig()
Gets this decoder configuration.io.netty.channel.ChannelFuture
handshake(io.netty.channel.Channel channel, FullHttpRequest req)
Performs the opening handshake.io.netty.channel.ChannelFuture
handshake(io.netty.channel.Channel channel, FullHttpRequest req, HttpHeaders responseHeaders, io.netty.channel.ChannelPromise promise)
Performs the opening handshake When call this method you MUST NOT retain theFullHttpRequest
which is passed in.io.netty.channel.ChannelFuture
handshake(io.netty.channel.Channel channel, HttpRequest req)
Performs the opening handshake.io.netty.channel.ChannelFuture
handshake(io.netty.channel.Channel channel, HttpRequest req, HttpHeaders responseHeaders, io.netty.channel.ChannelPromise promise)
Performs the opening handshake When call this method you MUST NOT retain theHttpRequest
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.String
selectedSubprotocol()
Returns the selected subprotocol.protected String
selectSubprotocol(String requestedSubprotocols)
Selects the first matching supported sub protocolSet<String>
subprotocols()
Returns the CSV of supported sub protocolsString
uri()
Returns the URL of the web socketWebSocketVersion
version()
Returns the version of the specification being supported
-
-
-
Field Detail
-
logger
protected static final io.netty.util.internal.logging.InternalLogger logger
-
SUB_PROTOCOL_WILDCARD
public static final String SUB_PROTOCOL_WILDCARD
Use this as wildcard to support all requested sub-protocols- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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 Detail
-
uri
public String uri()
Returns the URL of the web socket
-
version
public WebSocketVersion 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
public WebSocketDecoderConfig decoderConfig()
Gets this decoder configuration.- Returns:
- This decoder configuration.
-
handshake
public io.netty.channel.ChannelFuture handshake(io.netty.channel.Channel channel, FullHttpRequest req)
Performs the opening handshake. When call this method you MUST NOT retain theFullHttpRequest
which is passed in.- Parameters:
channel
- Channelreq
- HTTP Request- Returns:
- future
The
ChannelFuture
which is notified once the opening handshake completes
-
handshake
public final io.netty.channel.ChannelFuture handshake(io.netty.channel.Channel channel, FullHttpRequest req, HttpHeaders responseHeaders, io.netty.channel.ChannelPromise promise)
Performs the opening handshake When call this method you MUST NOT retain theFullHttpRequest
which is passed in.- Parameters:
channel
- Channelreq
- HTTP RequestresponseHeaders
- Extra headers to add to the handshake response ornull
if no extra headers should be addedpromise
- theChannelPromise
to be notified when the opening handshake is done- Returns:
- future
the
ChannelFuture
which is notified when the opening handshake is done
-
handshake
public io.netty.channel.ChannelFuture handshake(io.netty.channel.Channel channel, HttpRequest req)
Performs the opening handshake. When call this method you MUST NOT retain theFullHttpRequest
which is passed in.- Parameters:
channel
- Channelreq
- HTTP Request- Returns:
- future
The
ChannelFuture
which is notified once the opening handshake completes
-
handshake
public final io.netty.channel.ChannelFuture handshake(io.netty.channel.Channel channel, HttpRequest req, HttpHeaders responseHeaders, io.netty.channel.ChannelPromise promise)
Performs the opening handshake When call this method you MUST NOT retain theHttpRequest
which is passed in.- Parameters:
channel
- Channelreq
- HTTP RequestresponseHeaders
- Extra headers to add to the handshake response ornull
if no extra headers should be addedpromise
- theChannelPromise
to be notified when the opening handshake is done- Returns:
- future
the
ChannelFuture
which is notified when the opening handshake is done
-
newHandshakeResponse
protected abstract FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders responseHeaders)
Returns a new {@link FullHttpResponse) which will be used for as response to the handshake request.
-
close
public io.netty.channel.ChannelFuture close(io.netty.channel.Channel channel, CloseWebSocketFrame frame)
Performs the closing handshake. When called from within aChannelHandler
you most likely want to useclose(ChannelHandlerContext, CloseWebSocketFrame)
.- Parameters:
channel
- theChannel
to use.frame
- Closing Frame that was received.
-
close
public io.netty.channel.ChannelFuture close(io.netty.channel.Channel channel, CloseWebSocketFrame frame, io.netty.channel.ChannelPromise promise)
Performs the closing handshake. When called from within aChannelHandler
you most likely want to useclose(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise)
.- Parameters:
channel
- theChannel
to use.frame
- Closing Frame that was received.promise
- theChannelPromise
to be notified when the closing handshake is done
-
close
public io.netty.channel.ChannelFuture close(io.netty.channel.ChannelHandlerContext ctx, CloseWebSocketFrame frame)
Performs the closing handshake.- Parameters:
ctx
- theChannelHandlerContext
to use.frame
- Closing Frame that was received.
-
close
public io.netty.channel.ChannelFuture close(io.netty.channel.ChannelHandlerContext ctx, CloseWebSocketFrame frame, io.netty.channel.ChannelPromise promise)
Performs the closing handshake.- Parameters:
ctx
- theChannelHandlerContext
to use.frame
- Closing Frame that was received.promise
- theChannelPromise
to be notified when the closing handshake is done.
-
selectSubprotocol
protected String selectSubprotocol(String requestedSubprotocols)
Selects the first matching supported sub protocol- Parameters:
requestedSubprotocols
- CSV of protocols to be supported. e.g. "chat, superchat"- Returns:
- First matching supported sub protocol. Null if not found.
-
selectedSubprotocol
public String selectedSubprotocol()
Returns the selected subprotocol. Null if no subprotocol has been selected.This is only available AFTER handshake() has been called.
-
newWebsocketDecoder
protected abstract WebSocketFrameDecoder newWebsocketDecoder()
Returns the decoder to use after handshake is complete.
-
newWebSocketEncoder
protected abstract WebSocketFrameEncoder newWebSocketEncoder()
Returns the encoder to use after the handshake is complete.
-
-