org.jboss.netty.handler.codec.http.websocketx

## Class WebSocketServerHandshaker

- java.lang.Object
- - org.jboss.netty.handler.codec.http.websocketx.WebSocketServerHandshaker

Direct Known Subclasses:
  WebSocketServerHandshaker00, WebSocketServerHandshaker08, WebSocketServerHandshaker13

    public abstract class WebSocketServerHandshaker
    extends Object

Base class for server side web socket opening and closing handshakes

### Field Summary

Fields
`static ChannelFutureListener` `HANDSHAKE_LISTENER` `ChannelFutureListener` which will call `Channels.fireExceptionCaught(org.jboss.netty.channel.ChannelHandlerContext, Throwable)` if the `ChannelFuture` was not successful.

### Constructor Summary

Constructors
`protected` `WebSocketServerHandshaker(WebSocketVersion version, String webSocketUrl, String subprotocols)` Constructor using default values
`protected` `WebSocketServerHandshaker(WebSocketVersion version, String webSocketUrl, String subprotocols, long maxFramePayloadLength)` Constructor specifying the destination web socket location

### Method Summary

Methods
`abstract ChannelFuture` `close(Channel channel, CloseWebSocketFrame frame)` Performs the closing handshake
`long` `getMaxFramePayloadLength()` Returns the max length for any frame's payload
`String` `getSelectedSubprotocol()` Returns the selected subprotocol.
`Set<String>` `getSubprotocols()` Returns the CSV of supported sub protocols
`WebSocketVersion` `getVersion()` Returns the version of the specification being supported
`String` `getWebSocketUrl()` Returns the URL of the web socket
`abstract ChannelFuture` `handshake(Channel channel, HttpRequest req)` Performs the opening handshake
`protected String` `selectSubprotocol(String requestedSubprotocols)` Selects the first matching supported sub protocol
`protected void` `setSelectedSubprotocol(String value)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### HANDSHAKE_LISTENER

    public static final ChannelFutureListener HANDSHAKE_LISTENER

`ChannelFutureListener` which will call `Channels.fireExceptionCaught(org.jboss.netty.channel.ChannelHandlerContext, Throwable)` if the `ChannelFuture` was not successful.

### Constructor Detail

#### WebSocketServerHandshaker

    protected WebSocketServerHandshaker(WebSocketVersion version,
                             String webSocketUrl,
                             String subprotocols)

Constructor using default values

Parameters:
  `version` - the protocol version
  `webSocketUrl` - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
  `subprotocols` - CSV of supported protocols. Null if sub protocols not supported.

#### WebSocketServerHandshaker

    protected WebSocketServerHandshaker(WebSocketVersion version,
                             String webSocketUrl,
                             String subprotocols,
                             long maxFramePayloadLength)

Constructor specifying the destination web socket location

Parameters:
  `version` - the protocol version
  `webSocketUrl` - URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be sent to this URL.
  `subprotocols` - CSV of supported protocols. Null if sub protocols not supported.
  `maxFramePayloadLength` - Maximum length of a frame's payload

### Method Detail

#### getWebSocketUrl

    public String getWebSocketUrl()

Returns the URL of the web socket

#### getSubprotocols

    public Set<String> getSubprotocols()

Returns the CSV of supported sub protocols

#### getVersion

    public WebSocketVersion getVersion()

Returns the version of the specification being supported

#### getMaxFramePayloadLength

    public long getMaxFramePayloadLength()

Returns the max length for any frame's payload

#### handshake

    public abstract ChannelFuture handshake(Channel channel,
                          HttpRequest req)

Performs the opening handshake

Parameters:
  `channel` - Channel
  `req` - HTTP Request

#### close

    public abstract ChannelFuture close(Channel channel,
                      CloseWebSocketFrame frame)

Performs the closing handshake

Parameters:
  `channel` - Channel
  `frame` - Closing Frame that was received

#### selectSubprotocol

    protected String selectSubprotocol(String requestedSubprotocols)

Selects the first matching supported sub protocol

Parameters:
  `requestedSubprotocols` - CSV of protocols to be supported. e.g. "chat, superchat"
Returns:
  First matching supported sub protocol. Null if not found.

#### getSelectedSubprotocol

    public String getSelectedSubprotocol()

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

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

#### setSelectedSubprotocol

    protected void setSelectedSubprotocol(String value)