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

public abstract Class WebSocketServerHandshaker

extends Object
Class Inheritance
Known Direct Subclasses
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker00, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker07, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker08, io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker13
Imports
java.nio.channels.ClosedChannelException, java.util.Collections, .LinkedHashSet, .Set, io.netty.buffer.Unpooled, io.netty.channel.Channel, .ChannelFuture, .ChannelFutureListener, .ChannelHandler, .ChannelHandlerContext, .ChannelInboundHandlerAdapter, .ChannelOutboundInvoker, .ChannelPipeline, .ChannelPromise, io.netty.handler.codec.http.DefaultFullHttpRequest, .EmptyHttpHeaders, .FullHttpRequest, .FullHttpResponse, .HttpContentCompressor, .HttpHeaders, .HttpObject, .HttpObjectAggregator, .HttpRequest, .HttpRequestDecoder, .HttpResponseEncoder, .HttpServerCodec, .HttpUtil, .LastHttpContent, io.netty.util.ReferenceCountUtil, io.netty.util.internal.EmptyArrays, .ObjectUtil, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory

Base class for server side web socket opening and closing handshakes

Field Summary

Modifier and TypeField and Description
private final WebSocketDecoderConfig
protected static final InternalLogger
private String
public static final String
SUB_PROTOCOL_WILDCARD

Use this as wildcard to support all requested sub-protocols

private final String[]
private final String
private final WebSocketVersion

Constructor Summary

AccessConstructor and Description
protected
WebSocketServerHandshaker(WebSocketVersion
the protocol version
version
,
String
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
uri
,
String
CSV of supported protocols. Null if sub protocols not supported.
subprotocols
,
int
Maximum length of a frame's payload
maxFramePayloadLength
)

Constructor specifying the destination web socket location

protected
WebSocketServerHandshaker(WebSocketVersion
the protocol version
version
,
String
URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
uri
,
String
CSV of supported protocols. Null if sub protocols not supported.
subprotocols
,
WebSocketDecoderConfig
Frames decoder configuration.
decoderConfig
)

Constructor specifying the destination web socket location

Method Summary

Modifier and TypeMethod and Description
public ChannelFuture
close(Channel
the Channel to use.
channel
,
CloseWebSocketFrame
Closing Frame that was received.
frame
)

Performs the closing handshake.

public ChannelFuture
close(Channel
the Channel to use.
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.

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

Returns:

This decoder configuration.
decoderConfig
()

Gets this decoder configuration.

public ChannelFuture

Returns:

future The ChannelFuture which is notified once the opening handshake completes
handshake
(Channel
Channel
channel
,
FullHttpRequest
HTTP Request
req
)

Performs the opening handshake.

public final ChannelFuture

Returns:

future the ChannelFuture which is notified when the opening handshake is done
handshake
(Channel
Channel
channel
,
FullHttpRequest
HTTP Request
req
,
HttpHeaders
Extra headers to add to the handshake response or null if no extra headers should be added
responseHeaders
,
final ChannelPromise
the ChannelPromise to be notified when the opening handshake is done
promise
)

Performs the opening handshake When call this method you MUST NOT retain the FullHttpRequest which is passed in.

public ChannelFuture

Returns:

future The ChannelFuture which is notified once the opening handshake completes
handshake
(Channel
Channel
channel
,
HttpRequest
HTTP Request
req
)

Performs the opening handshake.

public final ChannelFuture

Returns:

future the ChannelFuture which is notified when the opening handshake is done
handshake
(final Channel
Channel
channel
,
HttpRequest
HTTP Request
req
,
final HttpHeaders
Extra headers to add to the handshake response or null if no extra headers should be added
responseHeaders
,
final ChannelPromise
the ChannelPromise to be notified when the opening handshake is done
promise
)

Performs the opening handshake When call this method you MUST NOT retain the HttpRequest which is passed in.

public int

Returns:

The maximum length for a frame's payload
maxFramePayloadLength
()

Gets the maximum length for any frame's payload.

protected abstract FullHttpResponse
newHandshakeResponse(FullHttpRequest req, HttpHeaders responseHeaders)

Returns a new {@link FullHttpResponse) which will be used for as response to the handshake request.

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 String
selectedSubprotocol()

Returns the selected subprotocol.

protected String

Returns:

First matching supported sub protocol. Null if not found.
selectSubprotocol
(String
CSV of protocols to be supported. e.g. "chat, superchat"
requestedSubprotocols
)

Selects the first matching supported sub protocol

public Set<String>
subprotocols()

Returns the CSV of supported sub protocols

public String
uri()

Returns the URL of the web socket

public WebSocketVersion
version()

Returns the version of the specification being supported

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decoderConfigback to summary
private final WebSocketDecoderConfig decoderConfig
loggerback to summary
protected static final InternalLogger logger
selectedSubprotocolback to summary
private String selectedSubprotocol
SUB_PROTOCOL_WILDCARDback to summary
public static final String SUB_PROTOCOL_WILDCARD

Use this as wildcard to support all requested sub-protocols

subprotocolsback to summary
private final String[] subprotocols
uriback to summary
private final String uri
versionback to summary
private final WebSocketVersion version

Constructor Detail

WebSocketServerHandshakerback to summary
protected WebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, int maxFramePayloadLength)

Constructor specifying the destination web socket location

Parameters
version:WebSocketVersion

the protocol version

uri:String

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

subprotocols:String

CSV of supported protocols. Null if sub protocols not supported.

maxFramePayloadLength:int

Maximum length of a frame's payload

WebSocketServerHandshakerback to summary
protected WebSocketServerHandshaker(WebSocketVersion version, String uri, String subprotocols, WebSocketDecoderConfig decoderConfig)

Constructor specifying the destination web socket location

Parameters
version:WebSocketVersion

the protocol version

uri:String

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

subprotocols:String

CSV of supported protocols. Null if sub protocols not supported.

decoderConfig:WebSocketDecoderConfig

Frames decoder configuration.

Method Detail

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

the Channel to use.

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

the Channel to use.

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(ChannelOutboundInvoker invoker, CloseWebSocketFrame frame, ChannelPromise promise)
decoderConfigback to summary
public WebSocketDecoderConfig decoderConfig()

Gets this decoder configuration.

Returns:WebSocketDecoderConfig

This decoder configuration.

handshakeback to summary
public ChannelFuture handshake(Channel channel, FullHttpRequest req)

Performs the opening handshake. When call this method you MUST NOT retain the FullHttpRequest which is passed in.

Parameters
channel:Channel

Channel

req:FullHttpRequest

HTTP Request

Returns:ChannelFuture

future The ChannelFuture which is notified once the opening handshake completes

handshakeback to summary
public final ChannelFuture handshake(Channel channel, FullHttpRequest req, HttpHeaders responseHeaders, final ChannelPromise promise)

Performs the opening handshake When call this method you MUST NOT retain the FullHttpRequest which is passed in.

Parameters
channel:Channel

Channel

req:FullHttpRequest

HTTP Request

responseHeaders:HttpHeaders

Extra headers to add to the handshake response or null if no extra headers should be added

promise:ChannelPromise

the ChannelPromise to be notified when the opening handshake is done

Returns:ChannelFuture

future the ChannelFuture which is notified when the opening handshake is done

handshakeback to summary
public ChannelFuture handshake(Channel channel, HttpRequest req)

Performs the opening handshake. When call this method you MUST NOT retain the FullHttpRequest which is passed in.

Parameters
channel:Channel

Channel

req:HttpRequest

HTTP Request

Returns:ChannelFuture

future The ChannelFuture which is notified once the opening handshake completes

handshakeback to summary
public final ChannelFuture handshake(final Channel channel, HttpRequest req, final HttpHeaders responseHeaders, final ChannelPromise promise)

Performs the opening handshake When call this method you MUST NOT retain the HttpRequest which is passed in.

Parameters
channel:Channel

Channel

req:HttpRequest

HTTP Request

responseHeaders:HttpHeaders

Extra headers to add to the handshake response or null if no extra headers should be added

promise:ChannelPromise

the ChannelPromise to be notified when the opening handshake is done

Returns:ChannelFuture

future the ChannelFuture which is notified when the opening handshake is done

maxFramePayloadLengthback to summary
public int maxFramePayloadLength()

Gets the maximum length for any frame's payload.

Returns:int

The maximum length for a frame's payload

newHandshakeResponseback to summary
protected abstract FullHttpResponse newHandshakeResponse(FullHttpRequest req, HttpHeaders responseHeaders)

Returns a new {@link FullHttpResponse) which will be used for as response to the handshake request.

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.

selectedSubprotocolback to summary
public String selectedSubprotocol()

Returns the selected subprotocol. Null if no subprotocol has been selected.

This is only available AFTER handshake() has been called.

selectSubprotocolback to summary
protected String selectSubprotocol(String requestedSubprotocols)

Selects the first matching supported sub protocol

Parameters
requestedSubprotocols:String

CSV of protocols to be supported. e.g. "chat, superchat"

Returns:String

First matching supported sub protocol. Null if not found.

subprotocolsback to summary
public Set<String> subprotocols()

Returns the CSV of supported sub protocols

uriback to summary
public String uri()

Returns the URL of the web socket

versionback to summary
public WebSocketVersion version()

Returns the version of the specification being supported