Class WebSocketClientHandshaker
java.lang.Object
org.jboss.netty.handler.codec.http.websocketx.WebSocketClientHandshaker
- Direct Known Subclasses:
WebSocketClientHandshaker00
,WebSocketClientHandshaker07
,WebSocketClientHandshaker08
,WebSocketClientHandshaker13
Base class for web socket client handshake implementations
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private final String
private boolean
private final long
private final WebSocketVersion
private final URI
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
WebSocketClientHandshaker
(URI webSocketUrl, WebSocketVersion version, String subprotocol, Map<String, String> customHeaders) Base constructor with default valuesprotected
WebSocketClientHandshaker
(URI webSocketUrl, WebSocketVersion version, String subprotocol, Map<String, String> customHeaders, long maxFramePayloadLength) Base constructor -
Method Summary
Modifier and TypeMethodDescriptionabstract void
finishHandshake
(Channel channel, HttpResponse response) Validates and finishes the opening handshake initiated byhandshake(org.jboss.netty.channel.Channel)
}.Returns the subprotocol response sent by the server.Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructorlong
Returns the max length for any frame's payloadVersion of the web socket specification that is being usedReturns the URI to the web socket.abstract ChannelFuture
Begins the opening handshakeboolean
Flag to indicate if the opening handshake is complete(package private) static void
replaceDecoder
(Channel channel, ChannelHandler wsDecoder) Replace the HTTP decoder with a new Web Socket decoder.protected void
setActualSubprotocol
(String actualSubprotocol) protected void
-
Field Details
-
webSocketUrl
-
version
-
handshakeComplete
private volatile boolean handshakeComplete -
expectedSubprotocol
-
actualSubprotocol
-
customHeaders
-
maxFramePayloadLength
private final long maxFramePayloadLength
-
-
Constructor Details
-
WebSocketClientHandshaker
protected WebSocketClientHandshaker(URI webSocketUrl, WebSocketVersion version, String subprotocol, Map<String, String> customHeaders) Base constructor with default values- Parameters:
webSocketUrl
- 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 request
-
WebSocketClientHandshaker
protected WebSocketClientHandshaker(URI webSocketUrl, WebSocketVersion version, String subprotocol, Map<String, String> customHeaders, long maxFramePayloadLength) Base constructor- Parameters:
webSocketUrl
- 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
- CSV of requested subprotocol(s) sent to the server.customHeaders
- Map of custom headers to add to the client requestmaxFramePayloadLength
- Maximum length of a frame's payload
-
-
Method Details
-
getWebSocketUrl
Returns the URI to the web socket. e.g. "ws://myhost.com/path" -
getVersion
Version of the web socket specification that is being used -
getMaxFramePayloadLength
public long getMaxFramePayloadLength()Returns the max length for any frame's payload -
isHandshakeComplete
public boolean isHandshakeComplete()Flag to indicate if the opening handshake is complete -
setHandshakeComplete
protected void setHandshakeComplete() -
getExpectedSubprotocol
Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor -
getActualSubprotocol
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
-
handshake
Begins the opening handshake- Parameters:
channel
- Channel- Throws:
Exception
-
finishHandshake
Validates and finishes the opening handshake initiated byhandshake(org.jboss.netty.channel.Channel)
}.- Parameters:
channel
- Channelresponse
- HTTP response containing the closing handshake details
-
replaceDecoder
Replace the HTTP decoder with a new Web Socket decoder. Note that we do not useChannelPipeline.replace(String, String, ChannelHandler)
, because the server might have sent the first frame immediately after the upgrade response. In such a case, the HTTP decoder might have the first frame in its cumulation buffer and the HTTP decoder will forward it to the next handler. The Web Socket decoder will not receive it if we simply replaced it. For more information, refer toHttpResponseDecoder
and its unit tests.
-