Class Handshake
- java.lang.Object
-
- io.undertow.websockets.core.protocol.Handshake
-
- Direct Known Subclasses:
Hybi07Handshake
public abstract class Handshake extends java.lang.ObjectAbstract base class for doing a WebSocket Handshake.- Author:
- Mike Brock
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanallowExtensionsprotected java.util.Set<ExtensionHandshake>availableExtensionsprotected java.util.Set<java.lang.String>subprotocols
-
Constructor Summary
Constructors Modifier Constructor Description protectedHandshake(WebSocketVersion version, java.lang.String hashAlgorithm, java.lang.String magicNumber, java.util.Set<java.lang.String> subprotocols)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddExtension(ExtensionHandshake extension)Add a new WebSocket Extension handshake to the list of available extensions.abstract WebSocketChannelcreateChannel(WebSocketHttpExchange exchange, org.xnio.StreamConnection channel, ByteBufferPool pool)Create theWebSocketChannelfrom theWebSocketHttpExchangejava.lang.StringgetHashAlgorithm()Return the algorithm that is used to hash during the handshakejava.lang.StringgetMagicNumber()Return the magic number which will be mixed inWebSocketVersiongetVersion()Return the version for which theHandshakecan be used.protected static java.lang.StringgetWebSocketLocation(WebSocketHttpExchange exchange)Return the full url of the websocket location of the givenWebSocketHttpExchangevoidhandshake(WebSocketHttpExchange exchange)Issue the WebSocket upgradeprotected abstract voidhandshakeInternal(WebSocketHttpExchange exchange)protected java.util.List<ExtensionFunction>initExtensions(WebSocketHttpExchange exchange)Create theExtensionFunctionlist associated with the negotiated extensions defined in the exchange's response.abstract booleanmatches(WebSocketHttpExchange exchange)Returntrueif this implementation can be used to issue a handshake.protected voidperformUpgrade(WebSocketHttpExchange exchange)Perform the upgrade using no payloadprotected voidperformUpgrade(WebSocketHttpExchange exchange, byte[] data)convenience method to perform the upgradeprotected java.util.List<WebSocketExtension>selectedExtension(java.util.List<WebSocketExtension> extensionList)protected voidselectExtensions(WebSocketHttpExchange exchange)protected voidselectSubprotocol(WebSocketHttpExchange exchange)Selects the first matching supported sub protocol and add it the the headers of the exchange.protected java.lang.StringsupportedSubprotols(java.lang.String[] requestedSubprotocolArray)protected voidupgradeChannel(WebSocketHttpExchange exchange, byte[] data)
-
-
-
Field Detail
-
subprotocols
protected final java.util.Set<java.lang.String> subprotocols
-
availableExtensions
protected java.util.Set<ExtensionHandshake> availableExtensions
-
allowExtensions
protected boolean allowExtensions
-
-
Constructor Detail
-
Handshake
protected Handshake(WebSocketVersion version, java.lang.String hashAlgorithm, java.lang.String magicNumber, java.util.Set<java.lang.String> subprotocols)
-
-
Method Detail
-
getVersion
public WebSocketVersion getVersion()
Return the version for which theHandshakecan be used.
-
getHashAlgorithm
public java.lang.String getHashAlgorithm()
Return the algorithm that is used to hash during the handshake
-
getMagicNumber
public java.lang.String getMagicNumber()
Return the magic number which will be mixed in
-
getWebSocketLocation
protected static java.lang.String getWebSocketLocation(WebSocketHttpExchange exchange)
Return the full url of the websocket location of the givenWebSocketHttpExchange
-
handshake
public final void handshake(WebSocketHttpExchange exchange)
Issue the WebSocket upgrade- Parameters:
exchange- TheWebSocketHttpExchangefor which the handshake and upgrade should occur.
-
handshakeInternal
protected abstract void handshakeInternal(WebSocketHttpExchange exchange)
-
matches
public abstract boolean matches(WebSocketHttpExchange exchange)
Returntrueif this implementation can be used to issue a handshake.
-
createChannel
public abstract WebSocketChannel createChannel(WebSocketHttpExchange exchange, org.xnio.StreamConnection channel, ByteBufferPool pool)
Create theWebSocketChannelfrom theWebSocketHttpExchange
-
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 java.lang.String supportedSubprotols(java.lang.String[] requestedSubprotocolArray)
-
selectedExtension
protected java.util.List<WebSocketExtension> selectedExtension(java.util.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 newExtensionHandshake
-
initExtensions
protected final java.util.List<ExtensionFunction> initExtensions(WebSocketHttpExchange exchange)
Create theExtensionFunctionlist associated with the negotiated extensions defined in the exchange's response.- Parameters:
exchange- the exchange used to retrieve negotiated extensions- Returns:
- a list of
ExtensionFunctionwith the implementation of the extensions
-
-