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

public abstract Class WebSocketClientHandshaker

extends Object
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker00, io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker07, io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker13, io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker08
Imports
io.netty.buffer.Unpooled, io.netty.channel.Channel, .ChannelFuture, .ChannelFutureListener, .ChannelHandler, .ChannelHandlerContext, .ChannelInboundHandlerAdapter, .ChannelOutboundInvoker, .ChannelPipeline, .ChannelPromise, io.netty.handler.codec.http.DefaultFullHttpResponse, .EmptyHttpHeaders, .FullHttpRequest, .FullHttpResponse, .HttpClientCodec, .HttpContentDecompressor, .HttpHeaderNames, .HttpHeaders, .HttpObject, .HttpObjectAggregator, .HttpRequestEncoder, .HttpResponse, .HttpResponseDecoder, .HttpScheme, .LastHttpContent, io.netty.util.NetUtil, .ReferenceCountUtil, io.netty.util.internal.ObjectUtil, java.net.URI, java.nio.channels.ClosedChannelException, java.util.Locale, java.util.concurrent.Future, .TimeUnit, java.util.concurrent.atomic.AtomicIntegerFieldUpdater

Base class for web socket client handshake implementations

Field Summary

Modifier and TypeField and Description
private final boolean
private volatile String
protected final HttpHeaders
protected static final int
private final String
private static final AtomicIntegerFieldUpdater<WebSocketClientHandshaker>
private volatile boolean
private volatile int
private volatile long
protected final boolean
private volatile boolean
private static final String
private static final String
private final int
private final URI
private final WebSocketVersion

Constructor Summary

AccessConstructor and Description
protected
WebSocketClientHandshaker(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
uri
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
)

Base constructor

protected
WebSocketClientHandshaker(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
uri
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
,
long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
)

Base constructor

protected
WebSocketClientHandshaker(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
uri
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
,
long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
,
boolean
Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
absoluteUpgradeUrl
)

Base constructor

protected
WebSocketClientHandshaker(URI
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
uri
,
WebSocketVersion
Version of web socket specification to use to connect to the server
version
,
String
Sub protocol request sent to the server.
subprotocol
,
HttpHeaders
Map of custom headers to add to the client request
customHeaders
,
int
Maximum length of a frame's payload
maxFramePayloadLength
,
long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
,
boolean
Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
absoluteUpgradeUrl
,
boolean
Allows to generate the `Origin`|`Sec-WebSocket-Origin` header value for handshake request according to the given webSocketURL
generateOriginHeader
)

Base constructor

Method Summary

Modifier and TypeMethod and Description
public String
actualSubprotocol()

Returns the subprotocol response sent by the server.

public ChannelFuture
close(Channel
Channel
channel
,
CloseWebSocketFrame
Closing Frame that was received
frame
)

Performs the closing handshake.

public ChannelFuture
close(Channel
Channel
channel
,
CloseWebSocketFrame
Closing Frame that was received
frame
,
ChannelPromise
the ChannelPromise to be notified when the closing handshake is done
promise
)

Performs the closing handshake When called from within a ChannelHandler you most likely want to use close(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise).

public ChannelFuture
close(ChannelHandlerContext ctx, CloseWebSocketFrame
Closing Frame that was received
frame
)

Performs the closing handshake

public ChannelFuture
close(ChannelHandlerContext ctx, CloseWebSocketFrame
Closing Frame that was received
frame
,
ChannelPromise
the ChannelPromise to be notified when the closing handshake is done
promise
)

Performs the closing handshake

private ChannelFuture
close0(final ChannelOutboundInvoker invoker, final Channel channel, CloseWebSocketFrame frame, ChannelPromise promise)

public String
expectedSubprotocol()

Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor

public final void
finishHandshake(Channel
Channel
channel
,
FullHttpResponse
HTTP response containing the closing handshake details
response
)

Validates and finishes the opening handshake initiated by handshake}.

public long
public ChannelFuture
handshake(Channel
Channel
channel
)

Begins the opening handshake

public final ChannelFuture
handshake(Channel
Channel
channel
,
final ChannelPromise
the ChannelPromise to be notified when the opening handshake is sent
promise
)

Begins the opening handshake

protected boolean
isForceCloseComplete()

Flag to indicate if the closing handshake was initiated because of timeout.

public boolean
isHandshakeComplete()

Flag to indicate if the opening handshake is complete

public 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.

public final ChannelFuture

Returns:

future the ChannelFuture which is notified once the handshake completes.
processHandshake
(final Channel
Channel
channel
,
HttpResponse
HTTP response containing the closing handshake details
response
)

Process the opening handshake initiated by handshake}.

public final ChannelFuture

Returns:

future the ChannelFuture which is notified once the handshake completes.
processHandshake
(final Channel
Channel
channel
,
HttpResponse
HTTP response containing the closing handshake details
response
,
final ChannelPromise
the ChannelPromise to notify once the handshake completes.
promise
)

Process the opening handshake initiated by handshake}.

private void
setActualSubprotocol(String actualSubprotocol)

public WebSocketClientHandshaker
setForceCloseTimeoutMillis(long
Close the connection if it was not closed by the server after timeout specified
forceCloseTimeoutMillis
)

Sets timeout to close the connection if it was not closed by the server.

private void
protected String
upgradeUrl(URI wsURL)

Return the constructed raw path for the give URI.

public URI
uri()

Returns the URI to the web socket.

protected abstract void
verify(FullHttpResponse response)

Verify the FullHttpResponse and throws a WebSocketHandshakeException if something is wrong.

public WebSocketVersion
version()

Version of the web socket specification that is being used

pack-priv static CharSequence
pack-priv static CharSequence
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

absoluteUpgradeUrlback to summary
private final boolean absoluteUpgradeUrl
actualSubprotocolback to summary
private volatile String actualSubprotocol
customHeadersback to summary
protected final HttpHeaders customHeaders
DEFAULT_FORCE_CLOSE_TIMEOUT_MILLISback to summary
protected static final int DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS
expectedSubprotocolback to summary
private final String expectedSubprotocol
FORCE_CLOSE_INIT_UPDATERback to summary
private static final AtomicIntegerFieldUpdater<WebSocketClientHandshaker> FORCE_CLOSE_INIT_UPDATER
forceCloseCompleteback to summary
private volatile boolean forceCloseComplete
forceCloseInitback to summary
private volatile int forceCloseInit
forceCloseTimeoutMillisback to summary
private volatile long forceCloseTimeoutMillis
generateOriginHeaderback to summary
protected final boolean generateOriginHeader
handshakeCompleteback to summary
private volatile boolean handshakeComplete
HTTP_SCHEME_PREFIXback to summary
private static final String HTTP_SCHEME_PREFIX
HTTPS_SCHEME_PREFIXback to summary
private static final String HTTPS_SCHEME_PREFIX
maxFramePayloadLengthback to summary
private final int maxFramePayloadLength
uriback to summary
private final URI uri
versionback to summary
private final WebSocketVersion version

Constructor Detail

WebSocketClientHandshakerback to summary
protected WebSocketClientHandshaker(URI uri, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength)

Base constructor

Parameters
uri:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

WebSocketClientHandshakerback to summary
protected WebSocketClientHandshaker(URI uri, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis)

Base constructor

Parameters
uri:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

WebSocketClientHandshakerback to summary
protected WebSocketClientHandshaker(URI uri, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl)

Base constructor

Parameters
uri:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

absoluteUpgradeUrl:boolean

Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP

WebSocketClientHandshakerback to summary
protected WebSocketClientHandshaker(URI uri, WebSocketVersion version, String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl, boolean generateOriginHeader)

Base constructor

Parameters
uri:URI

URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.

version:WebSocketVersion

Version of web socket specification to use to connect to the server

subprotocol:String

Sub protocol request sent to the server.

customHeaders:HttpHeaders

Map of custom headers to add to the client request

maxFramePayloadLength:int

Maximum length of a frame's payload

forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

absoluteUpgradeUrl:boolean

Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP

generateOriginHeader:boolean

Allows to generate the `Origin`|`Sec-WebSocket-Origin` header value for handshake request according to the given webSocketURL

Method Detail

actualSubprotocolback to summary
public String actualSubprotocol()

Returns the subprotocol response sent by the server. Only available after end of handshake. Null if no subprotocol was requested or confirmed by the server.

closeback to summary
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame)

Performs the closing handshake. When called from within a ChannelHandler you most likely want to use close(ChannelHandlerContext, CloseWebSocketFrame).

Parameters
channel:Channel

Channel

frame:CloseWebSocketFrame

Closing Frame that was received

closeback to summary
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise)

Performs the closing handshake When called from within a ChannelHandler you most likely want to use close(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise).

Parameters
channel:Channel

Channel

frame:CloseWebSocketFrame

Closing Frame that was received

promise:ChannelPromise

the ChannelPromise to be notified when the closing handshake is done

closeback to summary
public ChannelFuture close(ChannelHandlerContext ctx, CloseWebSocketFrame frame)

Performs the closing handshake

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext to use.

frame:CloseWebSocketFrame

Closing Frame that was received

closeback to summary
public ChannelFuture close(ChannelHandlerContext ctx, CloseWebSocketFrame frame, ChannelPromise promise)

Performs the closing handshake

Parameters
ctx:ChannelHandlerContext

the ChannelHandlerContext to use.

frame:CloseWebSocketFrame

Closing Frame that was received

promise:ChannelPromise

the ChannelPromise to be notified when the closing handshake is done

close0back to summary
private ChannelFuture close0(final ChannelOutboundInvoker invoker, final Channel channel, CloseWebSocketFrame frame, ChannelPromise promise)
expectedSubprotocolback to summary
public String expectedSubprotocol()

Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor

finishHandshakeback to summary
public final void finishHandshake(Channel channel, FullHttpResponse response)

Validates and finishes the opening handshake initiated by handshake}.

Parameters
channel:Channel

Channel

response:FullHttpResponse

HTTP response containing the closing handshake details

forceCloseTimeoutMillisback to summary
public long forceCloseTimeoutMillis()
handshakeback to summary
public ChannelFuture handshake(Channel channel)

Begins the opening handshake

Parameters
channel:Channel

Channel

handshakeback to summary
public final ChannelFuture handshake(Channel channel, final ChannelPromise promise)

Begins the opening handshake

Parameters
channel:Channel

Channel

promise:ChannelPromise

the ChannelPromise to be notified when the opening handshake is sent

isForceCloseCompleteback to summary
protected boolean isForceCloseComplete()

Flag to indicate if the closing handshake was initiated because of timeout. For testing only.

isHandshakeCompleteback to summary
public boolean isHandshakeComplete()

Flag to indicate if the opening handshake is complete

maxFramePayloadLengthback to summary
public int maxFramePayloadLength()

Returns the max length for any frame's payload

newHandshakeRequestback to summary
protected abstract FullHttpRequest newHandshakeRequest()

Returns a new {@link FullHttpRequest) which will be used for the handshake.

newWebsocketDecoderback to summary
protected abstract WebSocketFrameDecoder newWebsocketDecoder()

Returns the decoder to use after handshake is complete.

newWebSocketEncoderback to summary
protected abstract WebSocketFrameEncoder newWebSocketEncoder()

Returns the encoder to use after the handshake is complete.

processHandshakeback to summary
public final ChannelFuture processHandshake(final Channel channel, HttpResponse response)

Process the opening handshake initiated by handshake}.

Parameters
channel:Channel

Channel

response:HttpResponse

HTTP response containing the closing handshake details

Returns:ChannelFuture

future the ChannelFuture which is notified once the handshake completes.

processHandshakeback to summary
public final ChannelFuture processHandshake(final Channel channel, HttpResponse response, final ChannelPromise promise)

Process the opening handshake initiated by handshake}.

Parameters
channel:Channel

Channel

response:HttpResponse

HTTP response containing the closing handshake details

promise:ChannelPromise

the ChannelPromise to notify once the handshake completes.

Returns:ChannelFuture

future the ChannelFuture which is notified once the handshake completes.

setActualSubprotocolback to summary
private void setActualSubprotocol(String actualSubprotocol)
setForceCloseTimeoutMillisback to summary
public WebSocketClientHandshaker setForceCloseTimeoutMillis(long forceCloseTimeoutMillis)

Sets timeout to close the connection if it was not closed by the server.

Parameters
forceCloseTimeoutMillis:long

Close the connection if it was not closed by the server after timeout specified

setHandshakeCompleteback to summary
private void setHandshakeComplete()
upgradeUrlback to summary
protected String upgradeUrl(URI wsURL)

Return the constructed raw path for the give URI.

uriback to summary
public URI uri()

Returns the URI to the web socket. e.g. "ws://myhost.com/path"

verifyback to summary
protected abstract void verify(FullHttpResponse response)

Verify the FullHttpResponse and throws a WebSocketHandshakeException if something is wrong.

versionback to summary
public WebSocketVersion version()

Version of the web socket specification that is being used

websocketHostValueback to summary
pack-priv static CharSequence websocketHostValue(URI wsURL)
websocketOriginValueback to summary
pack-priv static CharSequence websocketOriginValue(URI wsURL)