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.ObjectBase class for web socket client handshake implementations
-
-
Field Summary
Fields Modifier and Type Field Description protected HttpHeaderscustomHeadersprotected static intDEFAULT_FORCE_CLOSE_TIMEOUT_MILLISprotected booleangenerateOriginHeader
-
Constructor Summary
Constructors Modifier Constructor Description protectedWebSocketClientHandshaker(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
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringactualSubprotocol()Returns the subprotocol response sent by the server.ChannelFutureclose(ChannelHandlerContext ctx, CloseWebSocketFrame frame)Performs the closing handshakeChannelFutureclose(ChannelHandlerContext ctx, CloseWebSocketFrame frame, ChannelPromise promise)Performs the closing handshakeChannelFutureclose(Channel channel, CloseWebSocketFrame frame)Performs the closing handshake.ChannelFutureclose(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise)Performs the closing handshake When called from within aChannelHandleryou most likely want to useclose(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise).java.lang.StringexpectedSubprotocol()Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructorvoidfinishHandshake(Channel channel, FullHttpResponse response)Validates and finishes the opening handshake initiated byhandshake(io.netty.channel.Channel)}.longforceCloseTimeoutMillis()ChannelFuturehandshake(Channel channel)Begins the opening handshakeChannelFuturehandshake(Channel channel, ChannelPromise promise)Begins the opening handshakeprotected booleanisForceCloseComplete()Flag to indicate if the closing handshake was initiated because of timeout.booleanisHandshakeComplete()Flag to indicate if the opening handshake is completeintmaxFramePayloadLength()Returns the max length for any frame's payloadprotected abstract FullHttpRequestnewHandshakeRequest()Returns a new {@link FullHttpRequest) which will be used for the handshake.protected abstract WebSocketFrameDecodernewWebsocketDecoder()Returns the decoder to use after handshake is complete.protected abstract WebSocketFrameEncodernewWebSocketEncoder()Returns the encoder to use after the handshake is complete.ChannelFutureprocessHandshake(Channel channel, HttpResponse response)Process the opening handshake initiated byhandshake(io.netty.channel.Channel)}.ChannelFutureprocessHandshake(Channel channel, HttpResponse response, ChannelPromise promise)Process the opening handshake initiated byhandshake(io.netty.channel.Channel)}.WebSocketClientHandshakersetForceCloseTimeoutMillis(long forceCloseTimeoutMillis)Sets timeout to close the connection if it was not closed by the server.protected 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. e.g.protected abstract voidverify(FullHttpResponse response)Verify theFullHttpResponseand throws aWebSocketHandshakeExceptionif something is wrong.WebSocketVersionversion()Version of the web socket specification that is being used
-
-
-
Field Detail
-
DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS
protected static final int DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS
- See Also:
- Constant Field Values
-
customHeaders
protected final HttpHeaders customHeaders
-
generateOriginHeader
protected final boolean generateOriginHeader
-
-
Constructor Detail
-
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 Detail
-
uri
public java.net.URI uri()
Returns the URI to the web socket. e.g. "ws://myhost.com/path"
-
version
public WebSocketVersion 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
-
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.
-
forceCloseTimeoutMillis
public long forceCloseTimeoutMillis()
-
isForceCloseComplete
protected boolean isForceCloseComplete()
Flag to indicate if the closing handshake was initiated because of timeout. For testing only.
-
setForceCloseTimeoutMillis
public WebSocketClientHandshaker setForceCloseTimeoutMillis(long forceCloseTimeoutMillis)
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
public ChannelFuture handshake(Channel channel)
Begins the opening handshake- Parameters:
channel- Channel
-
handshake
public final ChannelFuture handshake(Channel channel, ChannelPromise promise)
Begins the opening handshake- Parameters:
channel- Channelpromise- theChannelPromiseto be notified when the opening handshake is sent
-
newHandshakeRequest
protected abstract FullHttpRequest newHandshakeRequest()
Returns a new {@link FullHttpRequest) which will be used for the handshake.
-
finishHandshake
public final void finishHandshake(Channel channel, FullHttpResponse response)
Validates and finishes the opening handshake initiated byhandshake(io.netty.channel.Channel)}.- Parameters:
channel- Channelresponse- HTTP response containing the closing handshake details
-
processHandshake
public final ChannelFuture processHandshake(Channel channel, HttpResponse response)
Process the opening handshake initiated byhandshake(io.netty.channel.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(io.netty.channel.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
protected abstract void verify(FullHttpResponse response)
Verify theFullHttpResponseand throws aWebSocketHandshakeExceptionif something is wrong.
-
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.
-
close
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame)
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
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise)
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
public ChannelFuture close(ChannelHandlerContext ctx, CloseWebSocketFrame frame)
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
-
upgradeUrl
protected java.lang.String upgradeUrl(java.net.URI wsURL)
Return the constructed raw path for the giveURI.
-
-