Top Description Fields Constructors Methods
io.undertow.websockets.core.protocol

public abstract Class Handshake

extends Object
Class Inheritance
Known Direct Subclasses
io.undertow.websockets.core.protocol.version07.Hybi07Handshake
Imports
io.undertow.util.Headers, io.undertow.websockets.WebSocketExtension, io.undertow.websockets.core.WebSocketChannel, .WebSocketVersion, io.undertow.websockets.extensions.ExtensionFunction, .ExtensionHandshake, io.undertow.websockets.spi.WebSocketHttpExchange, org.xnio.IoFuture, .StreamConnection, io.undertow.connector.ByteBufferPool, java.nio.ByteBuffer, java.util.ArrayList, .HashSet, .List, .Set, java.util.regex.Pattern

Abstract base class for doing a WebSocket Handshake.
Author
Mike Brock

Field Summary

Modifier and TypeField and Description
protected boolean
protected Set<ExtensionHandshake>
private static final byte[]
private final String
private final String
private static final Pattern
protected final Set<String>
private final WebSocketVersion

Constructor Summary

AccessConstructor and Description
protected
Handshake(WebSocketVersion version, String hashAlgorithm, String magicNumber, final Set<String> subprotocols)

Method Summary

Modifier and TypeMethod and Description
public final void
addExtension(ExtensionHandshake
a new ExtensionHandshake
extension
)

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

public abstract WebSocketChannel
public String
getHashAlgorithm()

Return the algorithm that is used to hash during the handshake

public String
getMagicNumber()

Return the magic number which will be mixed in

public 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

public final void
handshake(final WebSocketHttpExchange
The WebSocketHttpExchange for which the handshake and upgrade should occur.
exchange
)

Issue the WebSocket upgrade

protected abstract void
protected final List<ExtensionFunction>

Returns:

a list of ExtensionFunction with the implementation of the extensions
initExtensions
(final WebSocketHttpExchange
the exchange used to retrieve negotiated extensions
exchange
)

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

public abstract boolean
matches(WebSocketHttpExchange exchange)

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

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

convenience method to perform the upgrade

protected final void
performUpgrade(final WebSocketHttpExchange exchange)

Perform the upgrade using no payload

protected List<WebSocketExtension>
protected final void
protected final void
selectSubprotocol(final 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(final WebSocketHttpExchange exchange, final byte[] data)

private static void
writePayload(final WebSocketHttpExchange exchange, final ByteBuffer payload)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowExtensionsback to summary
protected boolean allowExtensions
availableExtensionsback to summary
protected Set<ExtensionHandshake> availableExtensions
EMPTYback to summary
private static final byte[] EMPTY
hashAlgorithmback to summary
private final String hashAlgorithm
magicNumberback to summary
private final String magicNumber
PATTERNback to summary
private static final Pattern PATTERN
subprotocolsback to summary
protected final Set<String> subprotocols
versionback to summary
private final WebSocketVersion version

Constructor Detail

Handshakeback to summary
protected Handshake(WebSocketVersion version, String hashAlgorithm, String magicNumber, final Set<String> subprotocols)

Method Detail

addExtensionback to summary
public final void addExtension(ExtensionHandshake extension)

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

Parameters
extension:ExtensionHandshake

a new ExtensionHandshake

createChannelback to summary
public abstract WebSocketChannel createChannel(WebSocketHttpExchange exchange, final StreamConnection channel, final ByteBufferPool pool)

Create the WebSocketChannel from the WebSocketHttpExchange

getHashAlgorithmback to summary
public String getHashAlgorithm()

Return the algorithm that is used to hash during the handshake

getMagicNumberback to summary
public String getMagicNumber()

Return the magic number which will be mixed in

getVersionback to summary
public WebSocketVersion getVersion()

Return the version for which the Handshake can be used.

getWebSocketLocationback to summary
protected static String getWebSocketLocation(WebSocketHttpExchange exchange)

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

handshakeback to summary
public final void handshake(final WebSocketHttpExchange exchange)

Issue the WebSocket upgrade

Parameters
exchange:WebSocketHttpExchange

The WebSocketHttpExchange for which the handshake and upgrade should occur.

handshakeInternalback to summary
protected abstract void handshakeInternal(final WebSocketHttpExchange exchange)
initExtensionsback to summary
protected final List<ExtensionFunction> initExtensions(final WebSocketHttpExchange exchange)

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

Parameters
exchange:WebSocketHttpExchange

the exchange used to retrieve negotiated extensions

Returns:List<ExtensionFunction>

a list of ExtensionFunction with the implementation of the extensions

matchesback to summary
public abstract boolean matches(WebSocketHttpExchange exchange)

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

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

convenience method to perform the upgrade

performUpgradeback to summary
protected final void performUpgrade(final WebSocketHttpExchange exchange)

Perform the upgrade using no payload

selectedExtensionback to summary
protected List<WebSocketExtension> selectedExtension(List<WebSocketExtension> extensionList)
selectExtensionsback to summary
protected final void selectExtensions(final WebSocketHttpExchange exchange)
selectSubprotocolback to summary
protected final void selectSubprotocol(final WebSocketHttpExchange exchange)

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

supportedSubprotolsback to summary
protected String supportedSubprotols(String[] requestedSubprotocolArray)
upgradeChannelback to summary
protected void upgradeChannel(final WebSocketHttpExchange exchange, final byte[] data)
writePayloadback to summary
private static void writePayload(final WebSocketHttpExchange exchange, final ByteBuffer payload)