public abstract class WebSocketClientHandshaker
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
actualSubprotocol |
private static java.nio.channels.ClosedChannelException |
CLOSED_CHANNEL_EXCEPTION |
protected HttpHeaders |
customHeaders |
private java.lang.String |
expectedSubprotocol |
private boolean |
handshakeComplete |
private int |
maxFramePayloadLength |
private java.net.URI |
uri |
private WebSocketVersion |
version |
Modifier | Constructor and Description |
---|---|
protected |
WebSocketClientHandshaker(java.net.URI uri,
WebSocketVersion version,
java.lang.String subprotocol,
HttpHeaders customHeaders,
int maxFramePayloadLength)
Base constructor
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
actualSubprotocol()
Returns the subprotocol response sent by the server.
|
ChannelFuture |
close(Channel channel,
CloseWebSocketFrame frame)
Performs the closing handshake
|
ChannelFuture |
close(Channel channel,
CloseWebSocketFrame frame,
ChannelPromise promise)
Performs the closing handshake
|
java.lang.String |
expectedSubprotocol()
Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor
|
void |
finishHandshake(Channel channel,
FullHttpResponse response)
Validates and finishes the opening handshake initiated by
handshake(io.netty.channel.Channel) }. |
ChannelFuture |
handshake(Channel channel)
Begins the opening handshake
|
ChannelFuture |
handshake(Channel channel,
ChannelPromise promise)
Begins the opening handshake
|
boolean |
isHandshakeComplete()
Flag to indicate if the opening handshake is complete
|
int |
maxFramePayloadLength()
Returns the max length for any frame's payload
|
protected abstract FullHttpRequest |
newHandshakeRequest()
Returns a new {@link FullHttpRequest) which will be used for the handshake.
|
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.
|
ChannelFuture |
processHandshake(Channel channel,
HttpResponse response)
Process the opening handshake initiated by
handshake(io.netty.channel.Channel) }. |
ChannelFuture |
processHandshake(Channel channel,
HttpResponse response,
ChannelPromise promise)
Process the opening handshake initiated by
handshake(io.netty.channel.Channel) }. |
(package private) static java.lang.String |
rawPath(java.net.URI wsURL)
Return the constructed raw path for the give
URI . |
private void |
setActualSubprotocol(java.lang.String actualSubprotocol) |
private void |
setHandshakeComplete() |
java.net.URI |
uri()
Returns the URI to the web socket.
|
protected abstract void |
verify(FullHttpResponse response)
Verfiy the
FullHttpResponse and throws a WebSocketHandshakeException if something is wrong. |
WebSocketVersion |
version()
Version of the web socket specification that is being used
|
(package private) static java.lang.CharSequence |
websocketOriginValue(java.lang.String host,
int wsPort) |
(package private) static int |
websocketPort(java.net.URI wsURL) |
private static final java.nio.channels.ClosedChannelException CLOSED_CHANNEL_EXCEPTION
private final java.net.URI uri
private final WebSocketVersion version
private volatile boolean handshakeComplete
private final java.lang.String expectedSubprotocol
private volatile java.lang.String actualSubprotocol
protected final HttpHeaders customHeaders
private final int maxFramePayloadLength
protected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength)
uri
- URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
sent to this URL.version
- Version of web socket specification to use to connect to the serversubprotocol
- Sub protocol request sent to the server.customHeaders
- Map of custom headers to add to the client requestmaxFramePayloadLength
- Maximum length of a frame's payloadpublic java.net.URI uri()
public WebSocketVersion version()
public int maxFramePayloadLength()
public boolean isHandshakeComplete()
private void setHandshakeComplete()
public java.lang.String expectedSubprotocol()
public java.lang.String actualSubprotocol()
private void setActualSubprotocol(java.lang.String actualSubprotocol)
public ChannelFuture handshake(Channel channel)
channel
- Channelpublic final ChannelFuture handshake(Channel channel, ChannelPromise promise)
channel
- Channelpromise
- the ChannelPromise
to be notified when the opening handshake is sentprotected abstract FullHttpRequest newHandshakeRequest()
public final void finishHandshake(Channel channel, FullHttpResponse response)
handshake(io.netty.channel.Channel)
}.channel
- Channelresponse
- HTTP response containing the closing handshake detailspublic final ChannelFuture processHandshake(Channel channel, HttpResponse response)
handshake(io.netty.channel.Channel)
}.channel
- Channelresponse
- HTTP response containing the closing handshake detailsChannelFuture
which is notified once the handshake completes.public final ChannelFuture processHandshake(Channel channel, HttpResponse response, ChannelPromise promise)
handshake(io.netty.channel.Channel)
}.channel
- Channelresponse
- HTTP response containing the closing handshake detailspromise
- the ChannelPromise
to notify once the handshake completes.ChannelFuture
which is notified once the handshake completes.protected abstract void verify(FullHttpResponse response)
FullHttpResponse
and throws a WebSocketHandshakeException
if something is wrong.protected abstract WebSocketFrameDecoder newWebsocketDecoder()
protected abstract WebSocketFrameEncoder newWebSocketEncoder()
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 donestatic java.lang.String rawPath(java.net.URI wsURL)
URI
.static int websocketPort(java.net.URI wsURL)
static java.lang.CharSequence websocketOriginValue(java.lang.String host, int wsPort)