Class ReactorNettyWebSocketClient

java.lang.Object
org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient
All Implemented Interfaces:
WebSocketClient

public class ReactorNettyWebSocketClient extends Object implements WebSocketClient
WebSocketClient implementation for use with Reactor Netty.
Since:
5.0
Author:
Rossen Stoyanchev
  • Constructor Details

    • ReactorNettyWebSocketClient

      public ReactorNettyWebSocketClient()
      Default constructor.
    • ReactorNettyWebSocketClient

      public ReactorNettyWebSocketClient(reactor.netty.http.client.HttpClient httpClient)
      Constructor that accepts an existing HttpClient builder with a default WebsocketClientSpec.Builder.
      Since:
      5.1
    • ReactorNettyWebSocketClient

      public ReactorNettyWebSocketClient(reactor.netty.http.client.HttpClient httpClient, Supplier<reactor.netty.http.client.WebsocketClientSpec.Builder> builderSupplier)
      Constructor that accepts an existing HttpClient builder and a pre-configured WebsocketClientSpec.Builder.
      Since:
      5.3
  • Method Details

    • getHttpClient

      public reactor.netty.http.client.HttpClient getHttpClient()
      Return the configured HttpClient.
    • getWebsocketClientSpec

      public reactor.netty.http.client.WebsocketClientSpec getWebsocketClientSpec()
      Build an instance of WebsocketClientSpec that reflects the current configuration. This can be used to check the configured parameters except for sub-protocols which depend on the WebSocketHandler that is used for a given upgrade.
      Since:
      5.3
    • setMaxFramePayloadLength

      @Deprecated public void setMaxFramePayloadLength(int maxFramePayloadLength)
      Deprecated.
      as of 5.3 in favor of providing a supplier of WebsocketClientSpec.Builder with a constructor argument
      Configure the maximum allowable frame payload length. Setting this value to your application's requirement may reduce denial of service attacks using long data frames.

      Corresponds to the argument with the same name in the constructor of WebSocketServerHandshakerFactory in Netty.

      By default set to 65536 (64K).

      Parameters:
      maxFramePayloadLength - the max length for frames.
      Since:
      5.2
    • getMaxFramePayloadLength

      @Deprecated public int getMaxFramePayloadLength()
      Deprecated.
      as of 5.3 in favor of getWebsocketClientSpec()
      Return the configured maxFramePayloadLength.
      Since:
      5.2
    • setHandlePing

      @Deprecated public void setHandlePing(boolean handlePing)
      Deprecated.
      as of 5.3 in favor of providing a supplier of WebsocketClientSpec.Builder with a constructor argument
      Configure whether to let ping frames through to be handled by the WebSocketHandler given to the execute method. By default, Reactor Netty automatically replies with pong frames in response to pings. This is useful in a proxy for allowing ping and pong frames through.

      By default this is set to false in which case ping frames are handled automatically by Reactor Netty. If set to true, ping frames will be passed through to the WebSocketHandler.

      Parameters:
      handlePing - whether to let Ping frames through for handling
      Since:
      5.2.4
    • getHandlePing

      @Deprecated public boolean getHandlePing()
      Deprecated.
      as of 5.3 in favor of getWebsocketClientSpec()
      Return the configured setHandlePing(boolean).
      Since:
      5.2.4
    • execute

      public reactor.core.publisher.Mono<Void> execute(URI url, WebSocketHandler handler)
      Description copied from interface: WebSocketClient
      Execute a handshake request to the given url and handle the resulting WebSocket session with the given handler.
      Specified by:
      execute in interface WebSocketClient
      Parameters:
      url - the handshake url
      handler - the handler of the WebSocket session
      Returns:
      completion Mono<Void> to indicate the outcome of the WebSocket session handling.
    • execute

      public reactor.core.publisher.Mono<Void> execute(URI url, HttpHeaders requestHeaders, WebSocketHandler handler)
      Description copied from interface: WebSocketClient
      A variant of WebSocketClient.execute(URI, WebSocketHandler) with custom headers.
      Specified by:
      execute in interface WebSocketClient
      Parameters:
      url - the handshake url
      requestHeaders - custom headers for the handshake request
      handler - the handler of the WebSocket session
      Returns:
      completion Mono<Void> to indicate the outcome of the WebSocket session handling.