Class BusWebSockets

java.lang.Object
org.apache.juneau.console.bus.websocket.BusWebSockets

public final class BusWebSockets extends Object
Registers the bus's WebSocket endpoint on the servlet container (Jakarta WebSocket 2.2).

The endpoint is context-relative ("/juneau-bus/ws/{sessionId}") because WebSocket endpoints are not servlet-mapped. Origin is the CSRF control for the handshake, so registration refuses a policy with no Origin rule. The rule is LoopbackBoundary.origin() for a LoopbackBoundary, the handshake's own scheme and Host for a CsrfBoundary, and BusPolicy.allowedOrigins when the policy has no boundary. Any other boundary type is refused: the handshake cannot apply a boundary it does not know.

Example:

// In a ServletContextListener (or the microservice's start hook): public void contextInitialized(ServletContextEvent e) { BusWebSockets.register(e.getServletContext(), JobsRest.BUS); // "/juneau-bus/ws/{sessionId}" } // Jetty 12 (ee11), when you hold the ServletContextHandler: JakartaWebSocketServletContainerInitializer.configure(context, (servletContext, container) -> BusWebSockets.register(container, JobsRest.BUS));

Since:
10.0.0
  • Field Details

  • Method Details

    • register

      public static void register(jakarta.servlet.ServletContext ctx, ServerBus bus)
      Registers the endpoint on the container found in the servlet context.
      Parameters:
      ctx - The servlet context.
      bus - The bus whose sessions the endpoint serves.
      Throws:
      IllegalStateException - no ServerContainer attribute, no Origin rule, or a boundary type the handshake cannot apply.
    • register

      public static void register(jakarta.websocket.server.ServerContainer container, ServerBus bus)
      Registers the endpoint on a container.

      Enables the bus's WebSocket transport only after the container accepted the endpoint, so a session POST never advertises a path that is not served.

      Parameters:
      container - The container.
      bus - The bus whose sessions the endpoint serves.
      Throws:
      IllegalStateException - no Origin rule, a boundary type the handshake cannot apply, or the container refused the endpoint.