public abstract class WebSocketClientHandshaker
extends java.lang.Object
限定符和类型 | 字段和说明 |
---|---|
protected HttpHeaders |
customHeaders |
protected static int |
DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS |
protected boolean |
generateOriginHeader |
限定符 | 构造器和说明 |
---|---|
protected |
WebSocketClientHandshaker(java.net.URI uri,
WebSocketVersion version,
java.lang.String subprotocol,
HttpHeaders customHeaders,
int maxFramePayloadLength)
Base constructor
|
protected |
WebSocketClientHandshaker(java.net.URI uri,
WebSocketVersion version,
java.lang.String subprotocol,
HttpHeaders customHeaders,
int maxFramePayloadLength,
long forceCloseTimeoutMillis)
Base constructor
|
protected |
WebSocketClientHandshaker(java.net.URI uri,
WebSocketVersion version,
java.lang.String subprotocol,
HttpHeaders customHeaders,
int maxFramePayloadLength,
long forceCloseTimeoutMillis,
boolean absoluteUpgradeUrl)
Base constructor
|
protected |
WebSocketClientHandshaker(java.net.URI uri,
WebSocketVersion version,
java.lang.String subprotocol,
HttpHeaders customHeaders,
int maxFramePayloadLength,
long forceCloseTimeoutMillis,
boolean absoluteUpgradeUrl,
boolean generateOriginHeader)
Base constructor
|
限定符和类型 | 方法和说明 |
---|---|
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
When called from within a
ChannelHandler you most likely want to use
close(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise) . |
ChannelFuture |
close(ChannelHandlerContext ctx,
CloseWebSocketFrame frame)
Performs the closing handshake
|
ChannelFuture |
close(ChannelHandlerContext ctx,
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) }. |
long |
forceCloseTimeoutMillis() |
ChannelFuture |
handshake(Channel channel)
Begins the opening handshake
|
ChannelFuture |
handshake(Channel channel,
ChannelPromise promise)
Begins the opening handshake
|
protected boolean |
isForceCloseComplete()
Flag to indicate if the closing handshake was initiated because of timeout.
|
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) }. |
WebSocketClientHandshaker |
setForceCloseTimeoutMillis(long forceCloseTimeoutMillis)
Sets timeout to close the connection if it was not closed by the server.
|
protected java.lang.String |
upgradeUrl(java.net.URI wsURL)
Return the constructed raw path for the give
URI . |
java.net.URI |
uri()
Returns the URI to the web socket. e.g.
|
protected abstract void |
verify(FullHttpResponse response)
Verify the
FullHttpResponse and throws a WebSocketHandshakeException if something is wrong. |
WebSocketVersion |
version()
Version of the web socket specification that is being used
|
protected static final int DEFAULT_FORCE_CLOSE_TIMEOUT_MILLIS
protected final HttpHeaders customHeaders
protected final boolean generateOriginHeader
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 payloadprotected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis)
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 specifiedprotected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl)
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 HTTPprotected WebSocketClientHandshaker(java.net.URI uri, WebSocketVersion version, java.lang.String subprotocol, HttpHeaders customHeaders, int maxFramePayloadLength, long forceCloseTimeoutMillis, boolean absoluteUpgradeUrl, boolean generateOriginHeader)
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 webSocketURLpublic java.net.URI uri()
public WebSocketVersion version()
public int maxFramePayloadLength()
public boolean isHandshakeComplete()
public java.lang.String expectedSubprotocol()
public java.lang.String actualSubprotocol()
public long forceCloseTimeoutMillis()
protected boolean isForceCloseComplete()
public WebSocketClientHandshaker setForceCloseTimeoutMillis(long forceCloseTimeoutMillis)
forceCloseTimeoutMillis
- Close the connection if it was not closed by the server after timeout specifiedpublic 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)
ChannelHandler
you most likely want to use
close(ChannelHandlerContext, CloseWebSocketFrame)
.channel
- Channelframe
- Closing Frame that was receivedpublic ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise)
ChannelHandler
you most likely want to use
close(ChannelHandlerContext, CloseWebSocketFrame, ChannelPromise)
.channel
- Channelframe
- Closing Frame that was receivedpromise
- the ChannelPromise
to be notified when the closing handshake is donepublic ChannelFuture close(ChannelHandlerContext ctx, CloseWebSocketFrame frame)
ctx
- the ChannelHandlerContext
to use.frame
- Closing Frame that was receivedpublic ChannelFuture close(ChannelHandlerContext ctx, CloseWebSocketFrame frame, ChannelPromise promise)
ctx
- the ChannelHandlerContext
to use.frame
- Closing Frame that was receivedpromise
- the ChannelPromise
to be notified when the closing handshake is doneprotected java.lang.String upgradeUrl(java.net.URI wsURL)
URI
.