public interface ServerContainer extends WebSocketContainer
For websocket enabled web containers, developers may obtain a reference to the ServerContainer instance by retrieving
it as an attribute named jakarta.websocket.server.ServerContainer
on the ServletContext. This way, the
registration methods held on this interface may be called to register server endpoints from a ServletContextListener
during the deployment of the WAR file containing the endpoint. Server endpoints may also be registered after the web
application has started.
WebSocket implementations that run outside the web container may have other means by which to provide a ServerContainer instance to the developer at application deployment time.
Once the application deployment phase is complete, and the websocket application has begun accepting incoming connections, the registration methods may no longer be called.
Modifier and Type | Method and Description |
---|---|
void |
addEndpoint(java.lang.Class<?> endpointClass)
Deploys the given annotated endpoint into this ServerContainer.
|
void |
addEndpoint(ServerEndpointConfig serverConfig)
Deploys the given endpoint described by the provided configuration into this ServerContainer.
|
void |
upgradeHttpToWebSocket(java.lang.Object httpServletRequest,
java.lang.Object httpServletResponse,
ServerEndpointConfig sec,
java.util.Map<java.lang.String,java.lang.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 . |
connectToServer, connectToServer, connectToServer, connectToServer, getDefaultAsyncSendTimeout, getDefaultMaxBinaryMessageBufferSize, getDefaultMaxSessionIdleTimeout, getDefaultMaxTextMessageBufferSize, getInstalledExtensions, setAsyncSendTimeout, setDefaultMaxBinaryMessageBufferSize, setDefaultMaxSessionIdleTimeout, setDefaultMaxTextMessageBufferSize
void addEndpoint(java.lang.Class<?> endpointClass) throws DeploymentException
endpointClass
- the class of the annotated endpointDeploymentException
- if the annotated endpoint was badly formed.java.lang.IllegalStateException
- if the containing websocket application has already been deployed.void addEndpoint(ServerEndpointConfig serverConfig) throws DeploymentException
serverConfig
- the configuration instance representing the logical endpoint that will be registered.DeploymentException
- if the endpoint was badly formed.java.lang.IllegalStateException
- if the containing websocket application has already been deployed.void upgradeHttpToWebSocket(java.lang.Object httpServletRequest, java.lang.Object httpServletResponse, ServerEndpointConfig sec, java.util.Map<java.lang.String,java.lang.String> pathParameters) throws java.io.IOException, DeploymentException
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
.
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 endpointpathParameters
- 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.java.lang.IllegalStateException
- if the provided request does not meet the requirements of the WebSocket handshakejava.lang.UnsupportedOperationException
- if the WebSocket implementation is not deployed as part of a Jakarta
Servlet containerjava.io.IOException
- if an I/O error occurs during the establishment of a WebSocket connectionDeploymentException
- if a configuration error prevents the establishment of a WebSocket connection