Class WebsocketDeploymentUtils

java.lang.Object
io.fluxzero.testserver.websocket.WebsocketDeploymentUtils

public class WebsocketDeploymentUtils extends Object
Utility class for deploying WebSocket server endpoints using Undertow or similar frameworks. Provides methods for setting up WebSocket endpoints, maintaining endpoint configurations, and managing namespace extraction from WebSocket sessions.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.undertow.websockets.jsr.WebSocketDeploymentInfo
    Creates and configures a WebSocketDeploymentInfo instance, setting up the buffer pool and worker for handling WebSocket connections.
    static io.undertow.server.handlers.PathHandler
    deploy(Function<String, jakarta.websocket.Endpoint> endpointSupplier, String path, io.undertow.server.handlers.PathHandler pathHandler)
    Deploys a WebSocket server endpoint for the specified path using an endpoint supplier and a path handler.
    static io.undertow.server.handlers.PathHandler
    deployFromSession(MemoizingFunction<jakarta.websocket.Session, jakarta.websocket.Endpoint> endpointSupplier, String path, io.undertow.server.handlers.PathHandler pathHandler)
    Deploys a WebSocket server endpoint using a specified session-to-endpoint mapping function, path, and handler.
    static String
    getNamespace(jakarta.websocket.Session session)
    Extracts the namespace from the given WebSocket session, using the namespace parameter.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • WebsocketDeploymentUtils

      public WebsocketDeploymentUtils()
  • Method Details

    • deploy

      public static io.undertow.server.handlers.PathHandler deploy(Function<String, jakarta.websocket.Endpoint> endpointSupplier, String path, io.undertow.server.handlers.PathHandler pathHandler)
      Deploys a WebSocket server endpoint for the specified path using an endpoint supplier and a path handler. The method relies on a memoized session-to-namespace mapping function and integrates the deployment into the provided path handler.
      Parameters:
      endpointSupplier - a function mapping WebSocket session identifiers to their corresponding endpoints
      path - the URL path under which the WebSocket endpoint will be made accessible
      pathHandler - the handler managing path mappings for deployment
      Returns:
      a PathHandler that includes the new WebSocket endpoint's path configuration
    • deployFromSession

      public static io.undertow.server.handlers.PathHandler deployFromSession(MemoizingFunction<jakarta.websocket.Session, jakarta.websocket.Endpoint> endpointSupplier, String path, io.undertow.server.handlers.PathHandler pathHandler)
      Deploys a WebSocket server endpoint using a specified session-to-endpoint mapping function, path, and handler. The method sets up a deployment configuration for the provided path and registers the WebSocket endpoint to handle requests at the specified path.
      Parameters:
      endpointSupplier - a memoizing function mapping WebSocket sessions to their respective endpoints
      path - the URL path under which the WebSocket endpoint is made available
      pathHandler - the handler that manages path mappings for deployment
      Returns:
      a PathHandler with the WebSocket path mapping added to it
    • createWebsocketDeploymentInfo

      public static io.undertow.websockets.jsr.WebSocketDeploymentInfo createWebsocketDeploymentInfo()
      Creates and configures a WebSocketDeploymentInfo instance, setting up the buffer pool and worker for handling WebSocket connections.
      Returns:
      a configured WebSocketDeploymentInfo instance
    • getNamespace

      public static String getNamespace(jakarta.websocket.Session session)
      Extracts the namespace from the given WebSocket session, using the namespace parameter.

      If the parameter is not present, the legacy projectId parameter is used instead. If no namespace or projectsId parameter is present in the session, the method defaults to "public".

      Parameters:
      session - the WebSocket session
      Returns:
      the resolved namespace (never null)