Interface WebSocketExchange<A extends ExchangeContext>

Type Parameters:
A - the type of the exchange context

public interface WebSocketExchange<A extends ExchangeContext>

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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    Represents the inbound part of a WebSocket exchange.
    static interface 
    Represents the outbound part of a WebSocket exchange.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Closes the WebSocket with the normal status (1000).
    default void
    close(short code)
    Closes the WebSocket with the specified status code.
    void
    close(short code, String reason)
    Closes the WebSocket with specified status code and reason.
    default void
    Closes the WebSocket with the specified status.
    default void
    close(WebSocketStatus status, String reason)
    Closes the WebSocket with specified status and reason.
    default void
    close(String reason)
    Closes the WebSocket with the normal status (1000) and the specified reason.
    Returns the context attached to the exchange.
    finalizer(reactor.core.publisher.Mono<Void> finalizer)
    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.
    Returns the inbound part of the WebSocket exchange.
    Returns the outbound part of the WebSocket exchange.
    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

      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

      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

      default void close(WebSocketStatus status)

      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

      default void close(String reason)

      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 + reason exceeds this limit, the reason shall be truncated.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      reason - a close reason
    • close

      default void close(WebSocketStatus status, String reason)

      Closes the WebSocket with specified status and reason.

      A WebSocket close frame must have a payload length of 125 bytes or less, when code + reason exceeds this limit, the reason shall be truncated.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      status - a WebSocket close status
      reason - a WebSocket close status code
    • close

      void close(short code, String reason)

      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 + reason exceeds this limit, the reason shall be truncated.

      A WebSocket close frame must have a payload length of 125 bytes or less, when code + reason exceeds this limit, the reason shall be truncated.

      If the WebSocket was already closed, this method does nothing.

      Parameters:
      code - a WebSocket close status code
      reason - a WebSocket close status code
    • finalizer

      WebSocketExchange<A> finalizer(reactor.core.publisher.Mono<Void> finalizer)

      Specifies a finalizer to the WebSocket exchange which completes once the exchange is closed.

      Parameters:
      finalizer - a finalizer
      Returns:
      the WebSocket exchange