Interface WebSocketExchange<A extends ExchangeContext>
- Type Parameters:
A- the type of the exchange context
Represents a WebSocket exchange between a client and a server.
A WebSocket exchange is bidirectional and as a result provided an WebSocketExchange.Inbound and an WebSocketExchange.Outbound exposing WebSocket frames and messages respectively received and sent by the server.
A WebSocket exchange is created from the HTTP server exchange (see Exchange.webSocket(java.lang.String...)) once the WebSocket opening handshake has completed. It is processed in a
WebSocketExchangeHandler specified in the WebSocket.
- Since:
- 1.5
- Author:
- Jeremy Kuhn
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceRepresents the inbound part of a WebSocket exchange.static interfaceRepresents the outbound part of a WebSocket exchange. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidclose()Closes the WebSocket with the normal status (1000).default voidclose(short code) Closes the WebSocket with the specified status code.voidCloses the WebSocket with specified status code and reason.default voidclose(WebSocketStatus status) Closes the WebSocket with the specified status.default voidclose(WebSocketStatus status, String reason) Closes the WebSocket with specified status and reason.default voidCloses the WebSocket with the normal status (1000) and the specified reason.context()Returns the context attached to the exchange.Specifies a finalizer to the WebSocket exchange which completes once the exchange is closed.Returns the subprotocol that was negotiated with the client during the opening handshake.inbound()Returns the inbound part of the WebSocket exchange.outbound()Returns the outbound part of the WebSocket exchange.request()Returns the original HTTP upgrade request.
-
Method Details
-
request
Request request()Returns the original HTTP upgrade request.
- Returns:
- the HTTP request
-
context
A context()Returns the context attached to the exchange.
- Returns:
- the exchange context or null
-
getSubProtocol
String getSubProtocol()Returns the subprotocol that was negotiated with the client during the opening handshake.
Note that the handshake will fail and the WebSocket connection closed if no subprotocols could have been negotiated.
- Returns:
- a subprotocol or null if no subprotocol was specified by both client and server
-
inbound
WebSocketExchange.Inbound inbound()Returns the inbound part of the WebSocket exchange.
This basically corresponds to the stream of WebSocket frames sent by the client to the server.
- Returns:
- the inbound part
-
outbound
WebSocketExchange.Outbound outbound()Returns the outbound part of the WebSocket exchange.
This basically corresponds to the stream of WebSocket frames sent by the server to the client.
- Returns:
- the outbound part
-
close
default void close()Closes the WebSocket with the normal status (
1000).If the WebSocket was already closed, this method does nothing.
-
close
Closes the WebSocket with the specified status.
If the WebSocket was already closed, this method does nothing.
- Parameters:
status- a WebSocket close status
-
close
default void close(short code) Closes the WebSocket with the specified status code.
If the WebSocket was already closed, this method does nothing.
- Parameters:
code- a WebSocket close status code
-
close
Closes the WebSocket with the normal status (
1000) and the specified reason.A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reasonexceeds this limit, the reason shall be truncated.If the WebSocket was already closed, this method does nothing.
- Parameters:
reason- a close reason
-
close
Closes the WebSocket with specified status and reason.
A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reasonexceeds this limit, the reason shall be truncated.If the WebSocket was already closed, this method does nothing.
- Parameters:
status- a WebSocket close statusreason- a WebSocket close status code
-
close
Closes the WebSocket with specified status code and reason.
A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reasonexceeds this limit, the reason shall be truncated.A WebSocket close frame must have a payload length of 125 bytes or less, when
code + reasonexceeds this limit, the reason shall be truncated.If the WebSocket was already closed, this method does nothing.
- Parameters:
code- a WebSocket close status codereason- a WebSocket close status code
-
finalizer
Specifies a finalizer to the WebSocket exchange which completes once the exchange is closed.
- Parameters:
finalizer- a finalizer- Returns:
- the WebSocket exchange
-