Interface WebSocketUpgrade

All Superinterfaces:
WebSocketUpgrade
All Known Implementing Classes:
UpgradeToWebSocketLowLevel

public interface WebSocketUpgrade extends WebSocketUpgrade
An attribute that will be added to an WebSocket upgrade HttpRequest that enables a request handler to upgrade this connection to a WebSocket connection and registers a WebSocket handler.

This is a low-level API. You might want to use handleWebSocketMessages instead as documented at https://pekko.apache.org/docs/pekko-http/current/server-side/websocket-support.html#routing-support

  • Method Details

    • createScalaFlow

      org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,org.apache.pekko.NotUsed> createScalaFlow(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,?> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,?> outSource)
      Java API

      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • getRequestedProtocols

      Iterable<String> getRequestedProtocols()
      Java API
      Specified by:
      getRequestedProtocols in interface WebSocketUpgrade
      Returns:
      (undocumented)
    • handleMessages

      HttpResponse handleMessages(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,Object> handlerFlow, scala.Option<String> subprotocol)
      The high-level interface to create a WebSocket server based on "messages".

      Returns a response to return in a request handler that will signal the low-level HTTP implementation to upgrade the connection to WebSocket and use the supplied handler to handle incoming WebSocket messages.

      Optionally, a subprotocol out of the ones requested by the client can be chosen.

      Parameters:
      handlerFlow - (undocumented)
      subprotocol - (undocumented)
      Returns:
      (undocumented)
    • handleMessages

      HttpResponse handleMessages(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,Object> handlerFlow, scala.Option<String> subprotocol, boolean compressionEnabled)
      The high-level interface to create a WebSocket server based on "messages".

      Returns a response to return in a request handler that will signal the low-level HTTP implementation to upgrade the connection to WebSocket and use the supplied handler to handle incoming WebSocket messages.

      Optionally, a subprotocol out of the ones requested by the client can be chosen. The compressionEnabled flag allows declining negotiated WebSocket compression for this accepted WebSocket.

      Parameters:
      handlerFlow - (undocumented)
      subprotocol - (undocumented)
      compressionEnabled - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessages

      HttpResponse handleMessages(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,Object> handlerFlow, scala.Function1<Message,Object> shouldCompress)
      The high-level interface to create a WebSocket server based on "messages".

      If permessage-deflate is negotiated, shouldCompress is evaluated synchronously once for each outbound text or binary message. The result applies to every fragment of that message. Returning true compresses the message and returning false sends it uncompressed. The filter is not invoked for control frames or when compression was not negotiated, and it does not affect inbound messages or whether compression is negotiated.

      The filter should be fast and non-blocking; if it throws, the WebSocket stream fails. For streamed messages, the complete payload and its final size are not available when the filter is evaluated.

      Parameters:
      handlerFlow - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessages

      HttpResponse handleMessages(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,Object> handlerFlow, scala.Option<String> subprotocol, scala.Function1<Message,Object> shouldCompress)
      The high-level interface to create a WebSocket server based on "messages".

      Optionally, a subprotocol out of the ones requested by the client can be chosen. If permessage-deflate is negotiated, shouldCompress is evaluated synchronously once for each outbound text or binary message. The result applies to every fragment of that message. Returning true compresses the message and returning false sends it uncompressed. The filter is not invoked for control frames or when compression was not negotiated, and it does not affect inbound messages or whether compression is negotiated.

      The filter should be fast and non-blocking; if it throws, the WebSocket stream fails. For streamed messages, the complete payload and its final size are not available when the filter is evaluated.

      Parameters:
      handlerFlow - (undocumented)
      subprotocol - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,?> handlerFlow)
      Java API
      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      handlerFlow - (undocumented)
      Returns:
      (undocumented)
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,?> handlerFlow, boolean compressionEnabled)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      handlerFlow - (undocumented)
      compressionEnabled - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,?> handlerFlow, Predicate<Message> shouldCompress)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      handlerFlow - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,?> handlerFlow, String subprotocol)
      Java API
      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      handlerFlow - (undocumented)
      subprotocol - (undocumented)
      Returns:
      (undocumented)
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,?> handlerFlow, String subprotocol, boolean compressionEnabled)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      handlerFlow - (undocumented)
      subprotocol - (undocumented)
      compressionEnabled - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.FlowShape<Message,Message>,?> handlerFlow, String subprotocol, Predicate<Message> shouldCompress)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      handlerFlow - (undocumented)
      subprotocol - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,?> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,?> outSource)
      Java API
      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      Returns:
      (undocumented)
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,?> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,?> outSource, boolean compressionEnabled)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      compressionEnabled - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,?> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,?> outSource, Predicate<Message> shouldCompress)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,?> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,?> outSource, String subprotocol)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      subprotocol - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,?> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,?> outSource, String subprotocol, boolean compressionEnabled)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      subprotocol - (undocumented)
      compressionEnabled - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWith

      HttpResponse handleMessagesWith(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,?> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,?> outSource, String subprotocol, Predicate<Message> shouldCompress)
      Java API

      Specified by:
      handleMessagesWith in interface WebSocketUpgrade
      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      subprotocol - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWithSinkSource

      HttpResponse handleMessagesWithSinkSource(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,Object> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,Object> outSource, scala.Option<String> subprotocol)
      The high-level interface to create a WebSocket server based on "messages".

      Returns a response to return in a request handler that will signal the low-level HTTP implementation to upgrade the connection to WebSocket and use the supplied inSink to consume messages received from the client and the supplied outSource to produce message to sent to the client.

      Optionally, a subprotocol out of the ones requested by the client can be chosen.

      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      subprotocol - (undocumented)
      Returns:
      (undocumented)
    • handleMessagesWithSinkSource

      HttpResponse handleMessagesWithSinkSource(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,Object> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,Object> outSource, scala.Option<String> subprotocol, boolean compressionEnabled)
      The high-level interface to create a WebSocket server based on "messages".

      Returns a response to return in a request handler that will signal the low-level HTTP implementation to upgrade the connection to WebSocket and use the supplied inSink to consume messages received from the client and the supplied outSource to produce message to sent to the client.

      Optionally, a subprotocol out of the ones requested by the client can be chosen. The compressionEnabled flag allows declining negotiated WebSocket compression for this accepted WebSocket.

      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      subprotocol - (undocumented)
      compressionEnabled - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWithSinkSource

      HttpResponse handleMessagesWithSinkSource(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,Object> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,Object> outSource, scala.Function1<Message,Object> shouldCompress)
      The high-level interface to create a WebSocket server based on "messages".

      If permessage-deflate is negotiated, shouldCompress is evaluated synchronously once for each outbound text or binary message. The result applies to every fragment of that message. Returning true compresses the message and returning false sends it uncompressed. The filter is not invoked for control frames or when compression was not negotiated, and it does not affect inbound messages or whether compression is negotiated.

      The filter should be fast and non-blocking; if it throws, the WebSocket stream fails. For streamed messages, the complete payload and its final size are not available when the filter is evaluated.

      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleMessagesWithSinkSource

      HttpResponse handleMessagesWithSinkSource(org.apache.pekko.stream.Graph<org.apache.pekko.stream.SinkShape<Message>,Object> inSink, org.apache.pekko.stream.Graph<org.apache.pekko.stream.SourceShape<Message>,Object> outSource, scala.Option<String> subprotocol, scala.Function1<Message,Object> shouldCompress)
      The high-level interface to create a WebSocket server based on "messages".

      Optionally, a subprotocol out of the ones requested by the client can be chosen. If permessage-deflate is negotiated, shouldCompress is evaluated synchronously once for each outbound text or binary message. The result applies to every fragment of that message. Returning true compresses the message and returning false sends it uncompressed. The filter is not invoked for control frames or when compression was not negotiated, and it does not affect inbound messages or whether compression is negotiated.

      The filter should be fast and non-blocking; if it throws, the WebSocket stream fails. For streamed messages, the complete payload and its final size are not available when the filter is evaluated.

      Parameters:
      inSink - (undocumented)
      outSource - (undocumented)
      subprotocol - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • requestedProtocols

      scala.collection.immutable.Seq<String> requestedProtocols()
      A sequence of protocols the client accepts.

      See http://tools.ietf.org/html/rfc6455#section-1.9

      Returns:
      (undocumented)