io.undertow.websockets.core.protocol

## Class Handshake

- java.lang.Object
- - io.undertow.websockets.core.protocol.Handshake

Direct Known Subclasses:
  Hybi07Handshake

    public abstract class Handshake
    extends Object

Abstract base class for doing a WebSocket Handshake.

Author:
  Mike Brock

### Field Summary

Fields
`protected boolean` `allowExtensions`
`protected Set<ExtensionHandshake>` `availableExtensions`
`protected Set<String>` `subprotocols`

### Constructor Summary

Constructors
`protected` `Handshake(WebSocketVersion version, String hashAlgorithm, String magicNumber, Set<String> subprotocols)`

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
`void` `addExtension(ExtensionHandshake extension)` Add a new WebSocket Extension handshake to the list of available extensions.
`abstract WebSocketChannel` `createChannel(WebSocketHttpExchange exchange, org.xnio.StreamConnection channel, ByteBufferPool pool)` Create the `WebSocketChannel` from the `WebSocketHttpExchange`
`String` `getHashAlgorithm()` Return the algorithm that is used to hash during the handshake
`String` `getMagicNumber()` Return the magic number which will be mixed in
`WebSocketVersion` `getVersion()` Return the version for which the `Handshake` can be used.
`protected static String` `getWebSocketLocation(WebSocketHttpExchange exchange)` Return the full url of the websocket location of the given `WebSocketHttpExchange`
`void` `handshake(WebSocketHttpExchange exchange)` Issue the WebSocket upgrade
`protected abstract void` `handshakeInternal(WebSocketHttpExchange exchange)`
`protected List<ExtensionFunction>` `initExtensions(WebSocketHttpExchange exchange)` Create the `ExtensionFunction` list associated with the negotiated extensions defined in the exchange's response.
`abstract boolean` `matches(WebSocketHttpExchange exchange)` Return `true` if this implementation can be used to issue a handshake.
`protected void` `performUpgrade(WebSocketHttpExchange exchange)` Perform the upgrade using no payload
`protected void` `performUpgrade(WebSocketHttpExchange exchange, byte[] data)` convenience method to perform the upgrade
`protected List<WebSocketExtension>` `selectedExtension(List<WebSocketExtension> extensionList)`
`protected void` `selectExtensions(WebSocketHttpExchange exchange)`
`protected void` `selectSubprotocol(WebSocketHttpExchange exchange)` Selects the first matching supported sub protocol and add it the the headers of the exchange.
`protected String` `supportedSubprotols(String[] requestedSubprotocolArray)`
`protected void` `upgradeChannel(WebSocketHttpExchange exchange, byte[] data)`

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

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

### Field Detail

#### subprotocols

    protected final Set<String> subprotocols

#### availableExtensions

    protected Set<ExtensionHandshake> availableExtensions

#### allowExtensions

    protected boolean allowExtensions

### Constructor Detail

#### Handshake

    protected Handshake(WebSocketVersion version,
                        String hashAlgorithm,
                        String magicNumber,
                        Set<String> subprotocols)

### Method Detail

#### getVersion

    public WebSocketVersion getVersion()

Return the version for which the `Handshake` can be used.

#### getHashAlgorithm

    public String getHashAlgorithm()

Return the algorithm that is used to hash during the handshake

#### getMagicNumber

    public String getMagicNumber()

Return the magic number which will be mixed in

#### getWebSocketLocation

    protected static String getWebSocketLocation(WebSocketHttpExchange exchange)

Return the full url of the websocket location of the given `WebSocketHttpExchange`

#### handshake

    public final void handshake(WebSocketHttpExchange exchange)

Issue the WebSocket upgrade

Parameters:
  `exchange` - The `WebSocketHttpExchange` for which the handshake and upgrade should occur.

#### handshakeInternal

    protected abstract void handshakeInternal(WebSocketHttpExchange exchange)

#### matches

    public abstract boolean matches(WebSocketHttpExchange exchange)

Return `true` if this implementation can be used to issue a handshake.

#### createChannel

    public abstract WebSocketChannel createChannel(WebSocketHttpExchange exchange,
                                                   org.xnio.StreamConnection channel,
                                                   ByteBufferPool pool)

Create the `WebSocketChannel` from the `WebSocketHttpExchange`

#### performUpgrade

    protected final void performUpgrade(WebSocketHttpExchange exchange,
                                        byte[] data)

convenience method to perform the upgrade

#### upgradeChannel

    protected void upgradeChannel(WebSocketHttpExchange exchange,
                                  byte[] data)

#### performUpgrade

    protected final void performUpgrade(WebSocketHttpExchange exchange)

Perform the upgrade using no payload

#### selectSubprotocol

    protected final void selectSubprotocol(WebSocketHttpExchange exchange)

Selects the first matching supported sub protocol and add it the the headers of the exchange.

#### selectExtensions

    protected final void selectExtensions(WebSocketHttpExchange exchange)

#### supportedSubprotols

    protected String supportedSubprotols(String[] requestedSubprotocolArray)

#### selectedExtension

    protected List<WebSocketExtension> selectedExtension(List<WebSocketExtension> extensionList)

#### addExtension

    public final void addExtension(ExtensionHandshake extension)

Add a new WebSocket Extension handshake to the list of available extensions.

Parameters:
  `extension` - a new `ExtensionHandshake`

#### initExtensions

    protected final List<ExtensionFunction> initExtensions(WebSocketHttpExchange exchange)

Create the `ExtensionFunction` list associated with the negotiated extensions defined in the exchange's response.

Parameters:
  `exchange` - the exchange used to retrieve negotiated extensions
Returns:
  a list of `ExtensionFunction` with the implementation of the extensions