Class WebSocketClientHandshaker
java.lang.Object
io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker
- Direct Known Subclasses:
WebSocketClientHandshaker00, WebSocketClientHandshaker07, WebSocketClientHandshaker08, WebSocketClientHandshaker13
public abstract class WebSocketClientHandshaker
extends java.lang.Object
Base class for web socket client handshake implementations
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanprivate java.lang.Stringprotected final HttpHeadersprotected static final intprivate final java.lang.Stringprivate static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<WebSocketClientHandshaker> private booleanprivate intprivate longprotected final booleanprivate booleanprivate static final java.lang.Stringprivate static final java.lang.Stringprivate final intprivate final java.net.URIprivate final WebSocketVersion -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedWebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength) Base constructorprotectedWebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis) Base constructorprotectedWebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl) Base constructorprotectedWebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl, boolean generateOriginHeader) Base constructor -
Method Summary
Modifier and TypeMethodDescriptionjava.lang.StringReturns the subprotocol response sent by the server.close(ChannelHandlerContext ctx, CloseWebSocketFrame frame) Performs the closing handshakeclose(ChannelHandlerContext ctx, CloseWebSocketFrame frame, ChannelPromise promise) Performs the closing handshakeclose(Channel channel, CloseWebSocketFrame frame) Performs the closing handshake.close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) Performs the closing handshake When called from within aChannelHandleryou most likely want to useclose(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise).private ChannelFutureclose0(ChannelOutboundInvoker invoker, Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) java.lang.StringReturns the CSV of requested subprotocol(s) sent to the server as specified in the constructorfinal voidfinishHandshake(Channel channel, FullHttpResponse response) Validates and finishes the opening handshake initiated byhandshake(Channel)}.longBegins the opening handshakefinal ChannelFuturehandshake(Channel channel, ChannelPromise promise) Begins the opening handshakeprotected booleanFlag to indicate if the closing handshake was initiated because of timeout.booleanFlag to indicate if the opening handshake is completeintReturns the max length for any frame's payloadprotected abstract FullHttpRequestReturns a newinvalid @link
{@link FullHttpRequest) which will be used for the handshake.protected abstract WebSocketFrameDecoderReturns the decoder to use after handshake is complete.protected abstract WebSocketFrameEncoderReturns the encoder to use after the handshake is complete.final ChannelFutureprocessHandshake(Channel channel, HttpResponse response) Process the opening handshake initiated byhandshake(Channel)}.final ChannelFutureprocessHandshake(Channel channel, HttpResponse response, ChannelPromise promise) Process the opening handshake initiated byhandshake(Channel)}.private voidsetActualSubprotocol(java.lang.String actualSubprotocol) setForceCloseTimeoutMillis(long forceCloseTimeoutMillis) Sets timeout to close the connection if it was not closed by the server.private voidprotected java.lang.StringupgradeUrl(java.net.URI wsURL) Return the constructed raw path for the giveURI.java.net.URIuri()Returns the URI to the web socket.protected abstract voidverify(FullHttpResponse response) Verify theFullHttpResponseand throws aWebSocketHandshakeExceptionif something is wrong.version()Version of the web socket specification that is being used(package private) static java.lang.CharSequencewebsocketHostValue(java.net.URI wsURL) (package private) static java.lang.CharSequencewebsocketOriginValue(java.net.URI wsURL) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
HTTP_SCHEME_PREFIX
private static final java.lang.String HTTP_SCHEME_PREFIX -
HTTPS_SCHEME_PREFIX
private static final java.lang.String HTTPS_SCHEME_PREFIX -
DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS
protected static final int DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS- See Also:
-
uri
private final java.net.URI uri -
version
-
handshakeComplete
private volatile boolean handshakeComplete -
forceCloseTimeoutMillis
private volatile long forceCloseTimeoutMillis -
forceCloseInit
private volatile int forceCloseInit -
FORCE_CLOSE_INIT_UPDATER
private static final java.util.concurrent.atomic.AtomicIntegerFieldUpdater<WebSocketClientHandshaker> FORCE_CLOSE_INIT_UPDATER -
forceCloseComplete
private volatile boolean forceCloseComplete -
expectedSubprotocol
private final java.lang.String expectedSubprotocol -
actualSubprotocol
private volatile java.lang.String actualSubprotocol -
customHeaders
-
maxFramePayloadLength
private final int maxFramePayloadLength -
absoluteUpgradeUrl
private final boolean absoluteUpgradeUrl -
generateOriginHeader
protected final boolean generateOriginHeader
-
-
Constructor Details
-
WebSocketClientHandshaker
protected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength) Base constructor- Parameters:
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 payload
-
WebSocketClientHandshaker
protected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis) Base constructor- Parameters:
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 payloadforceCloseTimeoutMillis- Close the connection if it was not closed by the server after timeout specified
-
WebSocketClientHandshaker
protected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl) Base constructor- Parameters:
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 payloadforceCloseTimeoutMillis- Close the connection if it was not closed by the server after timeout specifiedabsoluteUpgradeUrl- Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTP
-
WebSocketClientHandshaker
protected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl, boolean generateOriginHeader) Base constructor- Parameters:
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 payloadforceCloseTimeoutMillis- Close the connection if it was not closed by the server after timeout specifiedabsoluteUpgradeUrl- Use an absolute url for the Upgrade request, typically when connecting through an HTTP proxy over clear HTTPgenerateOriginHeader- Allows to generate the `Origin`|`Sec-WebSocket-Origin` header value for handshake request according to the given webSocketURL
-
-
Method Details
-
uri
public java.net.URI uri()Returns the URI to the web socket. e.g. "ws://myhost.com/path" -
version
Version of the web socket specification that is being used -
maxFramePayloadLength
public int maxFramePayloadLength()Returns the max length for any frame's payload -
isHandshakeComplete
public boolean isHandshakeComplete()Flag to indicate if the opening handshake is complete -
setHandshakeComplete
private void setHandshakeComplete() -
expectedSubprotocol
public java.lang.String expectedSubprotocol()Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor -
actualSubprotocol
public java.lang.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. -
setActualSubprotocol
private void setActualSubprotocol(java.lang.String actualSubprotocol) -
forceCloseTimeoutMillis
public long forceCloseTimeoutMillis() -
isForceCloseComplete
protected boolean isForceCloseComplete()Flag to indicate if the closing handshake was initiated because of timeout. For testing only. -
setForceCloseTimeoutMillis
Sets timeout to close the connection if it was not closed by the server.- Parameters:
forceCloseTimeoutMillis- Close the connection if it was not closed by the server after timeout specified
-
handshake
Begins the opening handshake- Parameters:
channel- Channel
-
handshake
Begins the opening handshake- Parameters:
channel- Channelpromise- theChannelPromiseto be notified when the opening handshake is sent
-
newHandshakeRequest
Returns a newinvalid @link
{@link FullHttpRequest) which will be used for the handshake. -
finishHandshake
Validates and finishes the opening handshake initiated byhandshake(Channel)}.- Parameters:
channel- Channelresponse- HTTP response containing the closing handshake details
-
processHandshake
Process the opening handshake initiated byhandshake(Channel)}.- Parameters:
channel- Channelresponse- HTTP response containing the closing handshake details- Returns:
- future
the
ChannelFuturewhich is notified once the handshake completes.
-
processHandshake
public final ChannelFuture processHandshake(Channel channel, HttpResponse response, ChannelPromise promise) Process the opening handshake initiated byhandshake(Channel)}.- Parameters:
channel- Channelresponse- HTTP response containing the closing handshake detailspromise- theChannelPromiseto notify once the handshake completes.- Returns:
- future
the
ChannelFuturewhich is notified once the handshake completes.
-
verify
Verify theFullHttpResponseand throws aWebSocketHandshakeExceptionif something is wrong. -
newWebsocketDecoder
Returns the decoder to use after handshake is complete. -
newWebSocketEncoder
Returns the encoder to use after the handshake is complete. -
close
Performs the closing handshake. When called from within aChannelHandleryou most likely want to useclose(ChannelHandlerContext, CloseWebSocketFrame).- Parameters:
channel- Channelframe- 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- Channelframe- Closing Frame that was receivedpromise- 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 receivedpromise- theChannelPromiseto be notified when the closing handshake is done
-
close0
private ChannelFuture close0(ChannelOutboundInvoker invoker, Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) -
upgradeUrl
protected java.lang.String upgradeUrl(java.net.URI wsURL) Return the constructed raw path for the giveURI. -
websocketHostValue
static java.lang.CharSequence websocketHostValue(java.net.URI wsURL) -
websocketOriginValue
static java.lang.CharSequence websocketOriginValue(java.net.URI wsURL)
-