Class WebSocketDirectives

java.lang.Object
org.apache.pekko.http.javadsl.server.directives.BasicDirectives
org.apache.pekko.http.javadsl.server.directives.CacheConditionDirectives
Direct Known Subclasses:
TimeoutDirectives

public abstract class WebSocketDirectives extends SecurityDirectives
  • Constructor Details

    • WebSocketDirectives

      public WebSocketDirectives()
  • Method Details

    • extractOfferedWsProtocols

      public Route extractOfferedWsProtocols(Function<List<String>,Route> inner)
      Extract the list of WebSocket subprotocols as offered by the client in the Sec-WebSocket-Protocol header if this is a WebSocket request. Rejects with an ExpectedWebSocketRequestRejection, otherwise.
      Parameters:
      inner - (undocumented)
      Returns:
      (undocumented)
    • extractWebSocketUpgrade

      public Route extractWebSocketUpgrade(Function<WebSocketUpgrade,Route> inner)
      Extract the WebSocketUpgrade attribute if this is a WebSocket request. Rejects with an ExpectedWebSocketRequestRejection, otherwise.
      Parameters:
      inner - (undocumented)
      Returns:
      (undocumented)
    • handleWebSocketMessages

      public <T> Route handleWebSocketMessages(org.apache.pekko.stream.javadsl.Flow<Message,Message,T> handler)
      Handles WebSocket requests with the given handler and rejects other requests with an ExpectedWebSocketRequestRejection.
      Parameters:
      handler - (undocumented)
      Returns:
      (undocumented)
    • handleWebSocketMessages

      public <T> Route handleWebSocketMessages(org.apache.pekko.stream.javadsl.Flow<Message,Message,T> handler, Predicate<Message> shouldCompress)
      Handles WebSocket requests with the given handler and selectively compresses outbound messages for which shouldCompress returns true when permessage-deflate was negotiated.

      Parameters:
      handler - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleWebSocketMessagesForOptionalProtocol

      public <T> Route handleWebSocketMessagesForOptionalProtocol(org.apache.pekko.stream.javadsl.Flow<Message,Message,T> handler, Optional<String> subprotocol)
      Handles WebSocket requests with the given handler and rejects other requests with an ExpectedWebSocketRequestRejection.

      If the subprotocol parameter is None any WebSocket request is accepted. If the subprotocol parameter is Some(protocol) a WebSocket request is only accepted if the list of subprotocols supported by the client (as announced in the WebSocket request) contains protocol. If the client did not offer the protocol in question the request is rejected with an UnsupportedWebSocketSubprotocolRejection rejection.

      To support several subprotocols you may chain several handleWebSocketMessagesForOptionalProtocol routes.

      Parameters:
      handler - (undocumented)
      subprotocol - (undocumented)
      Returns:
      (undocumented)
    • handleWebSocketMessagesForOptionalProtocol

      public <T> Route handleWebSocketMessagesForOptionalProtocol(org.apache.pekko.stream.javadsl.Flow<Message,Message,T> handler, Optional<String> subprotocol, Predicate<Message> shouldCompress)
      Handles WebSocket requests with the given handler and selectively compresses outbound messages for which shouldCompress returns true when permessage-deflate was negotiated.

      Parameters:
      handler - (undocumented)
      subprotocol - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0
    • handleWebSocketMessagesForProtocol

      public <T> Route handleWebSocketMessagesForProtocol(org.apache.pekko.stream.javadsl.Flow<Message,Message,T> handler, String subprotocol)
      Handles WebSocket requests with the given handler if the given subprotocol is offered in the request and rejects other requests with an ExpectedWebSocketRequestRejection or an UnsupportedWebSocketSubprotocolRejection.
      Parameters:
      handler - (undocumented)
      subprotocol - (undocumented)
      Returns:
      (undocumented)
    • handleWebSocketMessagesForProtocol

      public <T> Route handleWebSocketMessagesForProtocol(org.apache.pekko.stream.javadsl.Flow<Message,Message,T> handler, String subprotocol, Predicate<Message> shouldCompress)
      Handles WebSocket requests with the given handler if the given subprotocol is offered and selectively compresses outbound messages for which shouldCompress returns true when permessage-deflate was negotiated.

      Parameters:
      handler - (undocumented)
      subprotocol - (undocumented)
      shouldCompress - (undocumented)
      Returns:
      (undocumented)
      Since:
      2.0.0