Class WebSocketHandlerImpl
- java.lang.Object
-
- com.microsoft.azure.proton.transport.ws.impl.WebSocketHandlerImpl
-
- All Implemented Interfaces:
WebSocketHandler
public class WebSocketHandlerImpl extends Object implements WebSocketHandler
Implementation forWebSocketHandler.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.microsoft.azure.proton.transport.ws.WebSocketHandler
WebSocketHandler.WebSocketMessageType, WebSocketHandler.WebsocketTuple
-
-
Constructor Summary
Constructors Constructor Description WebSocketHandlerImpl()Creates a new instance of WebSocketHandlerImpl.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcalculateHeaderSize(int payloadSize)Gets the size of the header.voidcreatePong(ByteBuffer ping, ByteBuffer pong)Creates the pong for the "keep-alive", heart beat, network status probing when connecting in a web socket.protected byte[]createRandomMaskingKey()Returns a set of random bytes.StringcreateUpgradeRequest(String hostName, String webSocketPath, String webSocketQuery, int webSocketPort, String webSocketProtocol, Map<String,String> additionalHeaders)Creates an HTTP request to upgrade to use web sockets.protected WebSocketUpgradecreateWebSocketUpgrade(String hostName, String webSocketPath, String webSocketQuery, int webSocketPort, String webSocketProtocol, Map<String,String> additionalHeaders)Creates the initial Connection: upgrade request to use WebSocket.WebSocketHandler.WebsocketTupleunwrapBuffer(ByteBuffer srcBuffer)Unwraps the layer from the buffer.BooleanvalidateUpgradeReply(ByteBuffer buffer)Validates the response.voidwrapBuffer(ByteBuffer srcBuffer, ByteBuffer dstBuffer)Wraps the source buffer with additional contents from the web socket.
-
-
-
Method Detail
-
createUpgradeRequest
public String createUpgradeRequest(String hostName, String webSocketPath, String webSocketQuery, int webSocketPort, String webSocketProtocol, Map<String,String> additionalHeaders)
Creates an HTTP request to upgrade to use web sockets.- Specified by:
createUpgradeRequestin interfaceWebSocketHandler- Parameters:
hostName- Name of the host.webSocketPath- Path for the websocket.webSocketQuery- Query for the web socket.webSocketPort- Port for web socket.webSocketProtocol- Protocol to use for web sockets.additionalHeaders- Any additional headers to add to the HTTP upgrade request.- Returns:
- Represents the HTTP request.
-
createPong
public void createPong(ByteBuffer ping, ByteBuffer pong)
Creates the pong for the "keep-alive", heart beat, network status probing when connecting in a web socket.- Specified by:
createPongin interfaceWebSocketHandler- Parameters:
ping- The source buffer to read from.pong- The destination buffer with the pong.- See Also:
- Ping and pong
-
validateUpgradeReply
public Boolean validateUpgradeReply(ByteBuffer buffer)
Validates the response.- Specified by:
validateUpgradeReplyin interfaceWebSocketHandler- Parameters:
buffer- ByteBuffer to read from.- Returns:
- True if the response is valid, otherwise, false.
-
wrapBuffer
public void wrapBuffer(ByteBuffer srcBuffer, ByteBuffer dstBuffer)
Wraps the source buffer with additional contents from the web socket.- Specified by:
wrapBufferin interfaceWebSocketHandler- Parameters:
srcBuffer- Source buffer to wrap input.dstBuffer- Output buffer that bytes are written to.
-
unwrapBuffer
public WebSocketHandler.WebsocketTuple unwrapBuffer(ByteBuffer srcBuffer)
Unwraps the layer from the buffer.- Specified by:
unwrapBufferin interfaceWebSocketHandler- Parameters:
srcBuffer- The source buffer.- Returns:
- The current chunk for the web socket when reading.
-
createWebSocketUpgrade
protected WebSocketUpgrade createWebSocketUpgrade(String hostName, String webSocketPath, String webSocketQuery, int webSocketPort, String webSocketProtocol, Map<String,String> additionalHeaders)
Creates the initial Connection: upgrade request to use WebSocket.- Parameters:
hostName- host name to send the request towebSocketPath- path on the request url where WebSocketUpgrade will be sent towebSocketQuery- query on the request url where WebSocketUpgrade will be sent towebSocketPort- port on the request url where WebSocketUpgrade will be sent towebSocketProtocol- value for Sec-WebSocket-Protocol header on the WebSocketUpgrade requestadditionalHeaders- any additional headers to be part of the WebSocketUpgrade request- Returns:
- The upgrade request.
-
createRandomMaskingKey
protected byte[] createRandomMaskingKey()
Returns a set of random bytes.- Returns:
- a random set of 4 bytes.
-
calculateHeaderSize
public int calculateHeaderSize(int payloadSize)
Description copied from interface:WebSocketHandlerGets the size of the header.- Specified by:
calculateHeaderSizein interfaceWebSocketHandler- Parameters:
payloadSize- Size of the payload.- Returns:
- The size of the header.
-
-