Class WebsocketDeploymentUtils
java.lang.Object
io.fluxzero.testserver.websocket.WebsocketDeploymentUtils
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 -
Method Summary
Modifier and TypeMethodDescriptionstatic io.undertow.websockets.jsr.WebSocketDeploymentInfoCreates and configures aWebSocketDeploymentInfoinstance, setting up the buffer pool and worker for handling WebSocket connections.static io.undertow.server.handlers.PathHandlerdeploy(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.PathHandlerdeployFromSession(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 StringgetNamespace(jakarta.websocket.Session session) Extracts the namespace from the given WebSocket session, using thenamespaceparameter.
-
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 endpointspath- the URL path under which the WebSocket endpoint will be made accessiblepathHandler- the handler managing path mappings for deployment- Returns:
- a
PathHandlerthat 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 endpointspath- the URL path under which the WebSocket endpoint is made availablepathHandler- the handler that manages path mappings for deployment- Returns:
- a
PathHandlerwith the WebSocket path mapping added to it
-
createWebsocketDeploymentInfo
public static io.undertow.websockets.jsr.WebSocketDeploymentInfo createWebsocketDeploymentInfo()Creates and configures aWebSocketDeploymentInfoinstance, setting up the buffer pool and worker for handling WebSocket connections.- Returns:
- a configured
WebSocketDeploymentInfoinstance
-
getNamespace
Extracts the namespace from the given WebSocket session, using thenamespaceparameter.If the parameter is not present, the legacy
projectIdparameter is used instead. If nonamespaceorprojectsIdparameter is present in the session, the method defaults to"public".- Parameters:
session- the WebSocket session- Returns:
- the resolved namespace (never
null)
-