ServerContainer (WebSocket 2.2 API Documentation - Apache Tomcat 11.0.24)
Description: declaration: package: jakarta.websocket.server, interface: ServerContainer

# Interface ServerContainer

All Superinterfaces:
  `WebSocketContainer`

public interface ServerContainer extends WebSocketContainer
Provides the ability to deploy endpoints programmatically.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addEndpoint(ServerEndpointConfig sec)`
  Deploys the endpoint configured by the given `ServerEndpointConfig`.
  `void`
  `addEndpoint(Class<?> clazz)`
  Deploys the given endpoint class.
  `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 interface WebSocketContainer

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

- ## Method Details

  - ### addEndpoint

    void addEndpoint(Class<?> clazz) throws DeploymentException
    Deploys the given endpoint class. The class must be annotated with `ServerEndpoint` or extend `Endpoint`.
    Parameters:
      `clazz` - The endpoint class to deploy
    Throws:
      `DeploymentException` - If the endpoint cannot be deployed

  - ### addEndpoint

    void addEndpoint(ServerEndpointConfig sec) throws DeploymentException
    Deploys the endpoint configured by the given `ServerEndpointConfig`.
    Parameters:
      `sec` - The server endpoint configuration
    Throws:
      `DeploymentException` - If the endpoint cannot be deployed

  - ### upgradeHttpToWebSocket

    void upgradeHttpToWebSocket(Object httpServletRequest, Object httpServletResponse, ServerEndpointConfig sec, Map<String,String> pathParameters) throws IOException, DeploymentException
    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`.

    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:
      `IllegalStateException` - if the provided request does not meet the requirements of the WebSocket handshake
      `UnsupportedOperationException` - if the WebSocket implementation is not deployed as part of a Jakarta Servlet container
      `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
    Since:
      WebSocket 2.0