WsServerContainer (Apache Tomcat 11.0.24 API Documentation)
Description: declaration: package: org.apache.tomcat.websocket.server, class: WsServerContainer

# Class WsServerContainer

java.lang.Object
org.apache.tomcat.websocket.WsWebSocketContainer
org.apache.tomcat.websocket.server.WsServerContainer

All Implemented Interfaces:
  `ServerContainer, WebSocketContainer, BackgroundProcess`

public class WsServerContainer extends WsWebSocketContainer implements ServerContainer
Provides a per class loader (i.e. per web application) instance of a ServerContainer. Web application wide defaults may be configured by setting the following servlet context initialisation parameters to the desired values.

- `Constants.BINARY_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM`
- `Constants.TEXT_BUFFER_SIZE_SERVLET_CONTEXT_INIT_PARAM`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addEndpoint(ServerEndpointConfig sec)`
  Published the provided endpoint implementation at the specified path with the specified configuration.
  `void`
  `addEndpoint(Class<?> pojo)`
  Provides the equivalent of `addEndpoint(ServerEndpointConfig)` for publishing plain old java objects (POJOs) that have been annotated as WebSocket endpoints.
  `void`
  `closeAuthenticatedSession(String httpSessionId)`
  Closes all WebSocket sessions associated with the given authenticated HTTP session.
  `WsMappingResult`
  `findMapping(String path)`
  Finds the endpoint configuration that matches the given path.
  `protected InstanceManager`
  `getInstanceManager(ClassLoader classLoader)`
  Returns the instance manager for the given class loader.
  `protected WsWriteTimeout`
  `getTimeout()`
  Returns the write timeout handler.
  `protected void`
  `registerSession(Object key, WsSession wsSession)`
  Registers a WebSocket session.
  `protected void`
  `unregisterSession(Object key, WsSession wsSession)`
  Unregisters a WebSocket session.
  `void`
  `upgradeHttpToWebSocket(Object httpServletRequest, Object httpServletResponse, ServerEndpointConfig sec, Map<String,String> pathParameters)`
  Upgrade the HTTP connection represented by the `HttpServletRequest` and `HttpServletResponse` to the WebSocket protocol and establish a WebSocket connection as per the provided `ServerEndpointConfig`.

  ### Methods inherited from class WsWebSocketContainer

  `backgroundProcess, connectToServer, connectToServer, connectToServer, connectToServer, destroy, getDefaultAsyncSendTimeout, getDefaultMaxBinaryMessageBufferSize, getDefaultMaxSessionIdleTimeout, getDefaultMaxTextMessageBufferSize, getInstalledExtensions, getProcessPeriod, setAsyncSendTimeout, setDefaultMaxBinaryMessageBufferSize, setDefaultMaxSessionIdleTimeout, setDefaultMaxTextMessageBufferSize, setInstanceManager, setProcessPeriod`

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface WebSocketContainer

  `connectToServer, connectToServer, connectToServer, connectToServer, getDefaultAsyncSendTimeout, getDefaultMaxBinaryMessageBufferSize, getDefaultMaxSessionIdleTimeout, getDefaultMaxTextMessageBufferSize, getInstalledExtensions, setAsyncSendTimeout, setDefaultMaxBinaryMessageBufferSize, setDefaultMaxSessionIdleTimeout, setDefaultMaxTextMessageBufferSize`

- ## Method Details

  - ### addEndpoint

    public void addEndpoint(ServerEndpointConfig sec) throws DeploymentException
    Published the provided endpoint implementation at the specified path with the specified configuration. `WsServerContainer(ServletContext)` must be called before calling this method.
    Specified by:
      `addEndpoint` in interface `ServerContainer`
    Parameters:
      `sec` - The configuration to use when creating endpoint instances
    Throws:
      `DeploymentException` - if the endpoint cannot be published as requested

  - ### addEndpoint

    public void addEndpoint(Class<?> pojo) throws DeploymentException
    Provides the equivalent of `addEndpoint(ServerEndpointConfig)` for publishing plain old java objects (POJOs) that have been annotated as WebSocket endpoints.
    Specified by:
      `addEndpoint` in interface `ServerContainer`
    Parameters:
      `pojo` - The annotated POJO
    Throws:
      `DeploymentException` - If the endpoint cannot be deployed

  - ### upgradeHttpToWebSocket

    public void upgradeHttpToWebSocket(Object httpServletRequest, Object httpServletResponse, ServerEndpointConfig sec, Map<String,String> pathParameters) throws IOException, DeploymentException
    Description copied from interface: `jakarta.websocket.server.ServerContainer`
    Upgrade the HTTP connection represented by the `HttpServletRequest` and `HttpServletResponse` to the WebSocket protocol and establish a WebSocket connection as per the provided `ServerEndpointConfig`.

    This method is primarily intended to be used by frameworks that implement the front-controller pattern. It does not deploy the provided endpoint.

    If the WebSocket implementation is not deployed as part of a Jakarta Servlet container, this method will throw an `UnsupportedOperationException`.

    Specified by:
      `upgradeHttpToWebSocket` in interface `ServerContainer`
    Parameters:
      `httpServletRequest` - The `HttpServletRequest` to be processed as a WebSocket handshake as per section 4.0 of RFC 6455.
      `httpServletResponse` - The `HttpServletResponse` to be used when processing the `httpServletRequest` as a WebSocket handshake as per section 4.0 of RFC 6455.
      `sec` - The server endpoint configuration to use to configure the WebSocket endpoint
      `pathParameters` - Provides a mapping of path parameter names and values, if any, to be used for the WebSocket connection established by the call to this method. If no such mapping is defined, an empty Map must be passed.
    Throws:
      `IOException` - if an I/O error occurs during the establishment of a WebSocket connection
      `DeploymentException` - if a configuration error prevents the establishment of a WebSocket connection

  - ### findMapping

    public WsMappingResult findMapping(String path)
    Finds the endpoint configuration that matches the given path.
    Parameters:
      `path` - the URI path to match
    Returns:
      the mapping result, or null if no match is found

  - ### getTimeout

    protected WsWriteTimeout getTimeout()
    Returns the write timeout handler.
    Returns:
      the write timeout handler

  - ### getInstanceManager

    protected InstanceManager getInstanceManager(ClassLoader classLoader)
    Returns the instance manager for the given class loader. Overridden to make it visible to other classes in this package.
    Overrides:
      `getInstanceManager` in class `WsWebSocketContainer`
    Parameters:
      `classLoader` - the class loader
    Returns:
      the instance manager

  - ### registerSession

    protected void registerSession(Object key, WsSession wsSession)
    Registers a WebSocket session. Overridden to make it visible to other classes in this package.
    Overrides:
      `registerSession` in class `WsWebSocketContainer`
    Parameters:
      `key` - the session key
      `wsSession` - the session to register

  - ### unregisterSession

    protected void unregisterSession(Object key, WsSession wsSession)
    Unregisters a WebSocket session. Overridden to make it visible to other classes in this package.
    Overrides:
      `unregisterSession` in class `WsWebSocketContainer`
    Parameters:
      `key` - the session key
      `wsSession` - the session to unregister

  - ### closeAuthenticatedSession

    public void closeAuthenticatedSession(String httpSessionId)
    Closes all WebSocket sessions associated with the given authenticated HTTP session.
    Parameters:
      `httpSessionId` - the HTTP session ID