Class JettyWSUtil

java.lang.Object
org.eclipse.net4j.ws.jetty.server.JettyWSUtil

public final class JettyWSUtil extends Object
Creates a Jetty WebSocket upgrade handler scoped to explicitly configured active Net4j WS acceptors.

The embedding application owns and configures the Jetty server, its network listeners, and handler tree. This utility contributes an upgrade handler; it does not create, start, stop, or own those server resources. The acceptor list scopes routing for this handler, preventing it from selecting another context's acceptor merely because that acceptor is registered in the JVM-wide Net4j registry. Other provider integrations may use different routing arrangements.

Author:
Eike Stepper
  • Method Summary

    Modifier and Type
    Method
    Description
    static org.eclipse.jetty.websocket.server.WebSocketUpgradeHandler
    createUpgradeHandler(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.handler.ContextHandler context, String pathSpec, IWSAcceptor... acceptors)
    Creates a Jetty handler that registers one WebSocket path and routes upgrades only to the configured Net4j acceptors.

    Methods inherited from class Object

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

    • createUpgradeHandler

      public static org.eclipse.jetty.websocket.server.WebSocketUpgradeHandler createUpgradeHandler(org.eclipse.jetty.server.Server server, org.eclipse.jetty.server.handler.ContextHandler context, String pathSpec, IWSAcceptor... acceptors)
      Creates a Jetty handler that registers one WebSocket path and routes upgrades only to the configured Net4j acceptors. Both the decoded request path suffix (the @name route) and Net4jAcceptor handshake header must identify the same acceptor. At routing time, the selected acceptor must still be the instance registered under its name. Registry removal or replacement is therefore observed by subsequent routing checks. A request that passed the check before a concurrent change can still carry the previously selected instance into the handshake; if that acceptor is deactivated before acceptance, the accept call can fail.

      The returned handler wraps the context's current handler, preserving the existing application handler as its fallback. Install it as the context's handler before starting the server. Use a path spec such as /net4j/*, because Net4j clients append the selected acceptor name to the path. The request's secure state must match the acceptor type (ws for non-secure, wss for secure requests); TLS is configured by the application's server connectors. The explicit acceptor set is snapshotted for this handler, but registration and deactivation remain lifecycle responsibilities of the caller and the Net4j container.

      Parameters:
      server - the operator-owned Jetty server used to create the upgrade handler
      context - the context that will contain the WebSocket mapping
      pathSpec - the Jetty path specification for the Net4j WebSocket endpoint
      acceptors - the active acceptors explicitly exposed by this endpoint; each must be the currently registered instance
      Returns:
      the configured upgrade handler to link into the Jetty handler tree
      Throws:
      IllegalArgumentException - if an argument is null, the path is empty, or the acceptors are empty, inactive, or duplicated