Top Inners Fields Constructors Methods
org.apache.tomcat.websocket

public Class WsWebSocketContainer

extends Object
implements WebSocketContainer, BackgroundProcess
Class Inheritance
All Implemented Interfaces
org.apache.tomcat.websocket.BackgroundProcess, jakarta.websocket.WebSocketContainer
Known Direct Subclasses
org.apache.tomcat.websocket.server.WsServerContainer
Imports
java.io.EOFException, .File, .FileInputStream, .IOException, .InputStream, java.net.InetSocketAddress, .Proxy, .ProxySelector, .SocketAddress, .URI, .URISyntaxException, java.nio.ByteBuffer, java.nio.channels.AsynchronousChannelGroup, .AsynchronousSocketChannel, java.nio.charset.StandardCharsets, java.security.KeyStore, java.util.ArrayList, .Arrays, .Collections, .HashMap, .HashSet, .List, .Locale, .Map, .Map.Entry, .Random, .Set, java.util.concurrent.ConcurrentHashMap, .ExecutionException, .Future, .TimeUnit, .TimeoutException, javax.net.ssl.SSLContext, .SSLEngine, .SSLException, .SSLParameters, .TrustManagerFactory, jakarta.websocket.ClientEndpoint, .ClientEndpointConfig, .CloseReason, .CloseReason.CloseCodes, .DeploymentException, .Endpoint, .Extension, .HandshakeResponse, .Session, .WebSocketContainer, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.InstanceManager, .InstanceManagerBindings, org.apache.tomcat.util.buf.StringUtils, org.apache.tomcat.util.codec.binary.Base64, org.apache.tomcat.util.collections.CaseInsensitiveKeyMap, org.apache.tomcat.util.res.StringManager, org.apache.tomcat.util.security.KeyStoreUtil

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private volatile AsynchronousChannelGroup
private final Object
private int
private static final byte[]
private long
private volatile long
private final Map<Object, Set<WsSession>>
private final Object
private static final byte[]
private static final byte[]
private InstanceManager
private final Log
private int
private int
private int
private static final Random
private static final byte[]
private final Map<WsSession, WsSession>
private static final StringManager

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static ByteBuffer
addHeader(ByteBuffer result, String key, List<String> values)

public void
public Session
public Session
public Session
connectToServer(Class<? extends Endpoint>
An instance of this class will be created to handle responses from the server
clazz
,
ClientEndpointConfig
Used to configure the new connection
clientEndpointConfiguration
,
URI
The full URL of the WebSocket endpoint to connect to
path
)

Implements jakarta.websocket.WebSocketContainer.connectToServer.

Creates a new connection to the WebSocket.

public Session
connectToServer(Endpoint
The endpoint instance that will handle responses from the server
endpoint
,
ClientEndpointConfig
Used to configure the new connection
clientEndpointConfiguration
,
URI
The full URL of the WebSocket endpoint to connect to
path
)

Implements jakarta.websocket.WebSocketContainer.connectToServer.

Creates a new connection to the WebSocket.

private Session
connectToServerRecursive(ClientEndpointHolder clientEndpointHolder, ClientEndpointConfig clientEndpointConfiguration, URI path, Set<URI> redirectSet)

private ClientEndpointConfig
createClientEndpointConfig(Class<?> annotatedEndpointClass)

private static ByteBuffer
createProxyRequest(String host, int port, String authorizationHeader)

private static ByteBuffer
createRequest(URI uri, Map<String, List<String>> reqHeaders)

private static Map<String, List<String>>
createRequestHeaders(String host, int port, boolean secure, ClientEndpointConfig clientEndpointConfiguration)

private SSLEngine
createSSLEngine(ClientEndpointConfig clientEndpointConfig, String host, int port)

public void
destroy()

Cleans up the resources still in use by WebSocket sessions created from this container.

private static List<String>
private static String
private AsynchronousChannelGroup
public long
getDefaultAsyncSendTimeout()

Implements jakarta.websocket.WebSocketContainer.getDefaultAsyncSendTimeout.

Get the default timeout for sending a message asynchronously.

public int
public long
public int
getDefaultMaxTextMessageBufferSize()

Implements jakarta.websocket.WebSocketContainer.getDefaultMaxTextMessageBufferSize.

Get the default maximum buffer size for text messages.

public Set<Extension>
protected InstanceManager
pack-priv Set<Session>
public int
getProcessPeriod()

Implements org.apache.tomcat.websocket.BackgroundProcess.getProcessPeriod.

The default value is 10 which means session expirations are processed every 10 seconds.

private static boolean
isRedirectStatus(int httpResponseCode)

private void
private int
private Session
processAuthenticationChallenge(ClientEndpointHolder clientEndpointHolder, ClientEndpointConfig clientEndpointConfiguration, URI path, Set<URI> redirectSet, Map<String, Object> userProperties, ByteBuffer request, WsWebSocketContainer.HttpResponse httpResponse, AuthenticationType authenticationType)

private WsWebSocketContainer.HttpResponse
processResponse(ByteBuffer response, AsyncChannelWrapper channel, long timeout)

Process response, blocking until HTTP response has been fully received.

private static ByteBuffer
putWithExpand(ByteBuffer input, byte[] bytes)

private String
readLine(ByteBuffer response)

protected void
public void
setAsyncSendTimeout(long
The new default timeout in milliseconds. A non-positive value means an infinite timeout.
timeout
)

Implements jakarta.websocket.WebSocketContainer.setAsyncSendTimeout.

Set the default timeout for sending a message asynchronously.

public void
setDefaultMaxBinaryMessageBufferSize(int
The new default maximum buffer size in bytes
max
)

Implements jakarta.websocket.WebSocketContainer.setDefaultMaxBinaryMessageBufferSize.

Set the default maximum buffer size for binary messages.

public void
setDefaultMaxSessionIdleTimeout(long
The new default session idle timeout in milliseconds. Zero or negative values indicate an infinite timeout.
timeout
)

Implements jakarta.websocket.WebSocketContainer.setDefaultMaxSessionIdleTimeout.

Set the default session idle timeout.

public void
setDefaultMaxTextMessageBufferSize(int
The new default maximum buffer size in characters
max
)

Implements jakarta.websocket.WebSocketContainer.setDefaultMaxTextMessageBufferSize.

Set the default maximum buffer size for text messages.

protected void
public void
protected void
private static void
writeRequest(AsyncChannelWrapper channel, ByteBuffer request, long timeout)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

asynchronousChannelGroupback to summary
private volatile AsynchronousChannelGroup asynchronousChannelGroup
asynchronousChannelGroupLockback to summary
private final Object asynchronousChannelGroupLock
backgroundProcessCountback to summary
private int backgroundProcessCount
CRLFback to summary
private static final byte[] CRLF
defaultAsyncTimeoutback to summary
private long defaultAsyncTimeout
defaultMaxSessionIdleTimeoutback to summary
private volatile long defaultMaxSessionIdleTimeout
endpointSessionMapback to summary
private final Map<Object, Set<WsSession>> endpointSessionMap
endPointSessionMapLockback to summary
private final Object endPointSessionMapLock
GET_BYTESback to summary
private static final byte[] GET_BYTES
HTTP_VERSION_BYTESback to summary
private static final byte[] HTTP_VERSION_BYTES
instanceManagerback to summary
private InstanceManager instanceManager
logback to summary
private final Log log
maxBinaryMessageBufferSizeback to summary
private int maxBinaryMessageBufferSize
maxTextMessageBufferSizeback to summary
private int maxTextMessageBufferSize
processPeriodback to summary
private int processPeriod
RANDOMback to summary
private static final Random RANDOM
ROOT_URI_BYTESback to summary
private static final byte[] ROOT_URI_BYTES
sessionsback to summary
private final Map<WsSession, WsSession> sessions
smback to summary
private static final StringManager sm

Constructor Detail

WsWebSocketContainerback to summary
public WsWebSocketContainer()

Method Detail

addHeaderback to summary
private static ByteBuffer addHeader(ByteBuffer result, String key, List<String> values)
backgroundProcessback to summary
public void backgroundProcess()

Implements org.apache.tomcat.websocket.BackgroundProcess.backgroundProcess.

Annotations
@Override
connectToServerback to summary
public Session connectToServer(Object pojo, URI path) throws DeploymentException

Implements jakarta.websocket.WebSocketContainer.connectToServer.

Annotations
@Override
connectToServerback to summary
public Session connectToServer(Class<?> annotatedEndpointClass, URI path) throws DeploymentException

Implements jakarta.websocket.WebSocketContainer.connectToServer.

Annotations
@Override
connectToServerback to summary
public Session connectToServer(Class<? extends Endpoint> clazz, ClientEndpointConfig clientEndpointConfiguration, URI path) throws DeploymentException

Implements jakarta.websocket.WebSocketContainer.connectToServer.

Doc from jakarta.websocket.WebSocketContainer.connectToServer.

Creates a new connection to the WebSocket.

Parameters
clazz:Class<? extends Endpoint>

An instance of this class will be created to handle responses from the server

clientEndpointConfiguration:ClientEndpointConfig

Used to configure the new connection

path:URI

The full URL of the WebSocket endpoint to connect to

Returns:Session

The WebSocket session for the connection

Annotations
@Override
Exceptions
DeploymentException:
If the connection cannot be established
connectToServerback to summary
public Session connectToServer(Endpoint endpoint, ClientEndpointConfig clientEndpointConfiguration, URI path) throws DeploymentException

Implements jakarta.websocket.WebSocketContainer.connectToServer.

Doc from jakarta.websocket.WebSocketContainer.connectToServer.

Creates a new connection to the WebSocket.

Parameters
endpoint:Endpoint

The endpoint instance that will handle responses from the server

clientEndpointConfiguration:ClientEndpointConfig

Used to configure the new connection

path:URI

The full URL of the WebSocket endpoint to connect to

Returns:Session

The WebSocket session for the connection

Annotations
@Override
Exceptions
DeploymentException:
If the connection cannot be established
connectToServerRecursiveback to summary
private Session connectToServerRecursive(ClientEndpointHolder clientEndpointHolder, ClientEndpointConfig clientEndpointConfiguration, URI path, Set<URI> redirectSet) throws DeploymentException
createClientEndpointConfigback to summary
private ClientEndpointConfig createClientEndpointConfig(Class<?> annotatedEndpointClass) throws DeploymentException
createProxyRequestback to summary
private static ByteBuffer createProxyRequest(String host, int port, String authorizationHeader)
createRequestback to summary
private static ByteBuffer createRequest(URI uri, Map<String, List<String>> reqHeaders)
createRequestHeadersback to summary
private static Map<String, List<String>> createRequestHeaders(String host, int port, boolean secure, ClientEndpointConfig clientEndpointConfiguration)
createSSLEngineback to summary
private SSLEngine createSSLEngine(ClientEndpointConfig clientEndpointConfig, String host, int port) throws DeploymentException
Annotations
@SuppressWarnings:removal
destroyback to summary
public void destroy()

Cleans up the resources still in use by WebSocket sessions created from this container. This includes closing sessions and cancelling Futures associated with blocking read/writes.

generateExtensionHeadersback to summary
private static List<String> generateExtensionHeaders(List<Extension> extensions)
generateWsKeyValueback to summary
private static String generateWsKeyValue()
getAsynchronousChannelGroupback to summary
private AsynchronousChannelGroup getAsynchronousChannelGroup()
getDefaultAsyncSendTimeoutback to summary
public long getDefaultAsyncSendTimeout()

Implements jakarta.websocket.WebSocketContainer.getDefaultAsyncSendTimeout.

Doc from jakarta.websocket.WebSocketContainer.getDefaultAsyncSendTimeout.

Get the default timeout for sending a message asynchronously. The default value for this implementation is -1.

Returns:long

The current default timeout in milliseconds. A non-positive value means an infinite timeout.

Annotations
@Override
getDefaultMaxBinaryMessageBufferSizeback to summary
public int getDefaultMaxBinaryMessageBufferSize()

Implements jakarta.websocket.WebSocketContainer.getDefaultMaxBinaryMessageBufferSize.

Doc from jakarta.websocket.WebSocketContainer.getDefaultMaxBinaryMessageBufferSize.

Get the default maximum buffer size for binary messages.

Returns:int

The current default maximum buffer size in bytes

Annotations
@Override
getDefaultMaxSessionIdleTimeoutback to summary
public long getDefaultMaxSessionIdleTimeout()

Implements jakarta.websocket.WebSocketContainer.getDefaultMaxSessionIdleTimeout.

Doc from jakarta.websocket.WebSocketContainer.getDefaultMaxSessionIdleTimeout.

Get the current default session idle timeout.

Returns:long

The current default session idle timeout in milliseconds. Zero or negative values indicate an infinite timeout.

Annotations
@Override
getDefaultMaxTextMessageBufferSizeback to summary
public int getDefaultMaxTextMessageBufferSize()

Implements jakarta.websocket.WebSocketContainer.getDefaultMaxTextMessageBufferSize.

Doc from jakarta.websocket.WebSocketContainer.getDefaultMaxTextMessageBufferSize.

Get the default maximum buffer size for text messages.

Returns:int

The current default maximum buffer size in characters

Annotations
@Override
getInstalledExtensionsback to summary
public Set<Extension> getInstalledExtensions()

Implements jakarta.websocket.WebSocketContainer.getInstalledExtensions.

Doc from jakarta.websocket.WebSocketContainer.getInstalledExtensions.

Get the installed extensions. Currently, this implementation does not support any extensions.

Returns:Set<Extension>

The set of extensions that are supported by this WebSocket implementation.

Annotations
@Override
getInstanceManagerback to summary
protected InstanceManager getInstanceManager(ClassLoader classLoader)
getOpenSessionsback to summary
pack-priv Set<Session> getOpenSessions(Object key)
getProcessPeriodback to summary
public int getProcessPeriod()

Implements org.apache.tomcat.websocket.BackgroundProcess.getProcessPeriod.

The default value is 10 which means session expirations are processed every 10 seconds.

Annotations
@Override
isRedirectStatusback to summary
private static boolean isRedirectStatus(int httpResponseCode)
parseHeadersback to summary
private void parseHeaders(String line, Map<String, List<String>> headers)
parseStatusback to summary
private int parseStatus(String line) throws DeploymentException
processAuthenticationChallengeback to summary
private Session processAuthenticationChallenge(ClientEndpointHolder clientEndpointHolder, ClientEndpointConfig clientEndpointConfiguration, URI path, Set<URI> redirectSet, Map<String, Object> userProperties, ByteBuffer request, WsWebSocketContainer.HttpResponse httpResponse, AuthenticationType authenticationType) throws DeploymentException, AuthenticationException
processResponseback to summary
private WsWebSocketContainer.HttpResponse processResponse(ByteBuffer response, AsyncChannelWrapper channel, long timeout) throws InterruptedException, ExecutionException, DeploymentException, EOFException, TimeoutException

Process response, blocking until HTTP response has been fully received.

Exceptions
InterruptedException:
if the thread is interrupted while reading the response
ExecutionException:
if there is an exception reading the response
DeploymentException:
if the response status line is not correctly formatted
TimeoutException:
if the response was not read within the expected timeout
putWithExpandback to summary
private static ByteBuffer putWithExpand(ByteBuffer input, byte[] bytes)
readLineback to summary
private String readLine(ByteBuffer response)
registerSessionback to summary
protected void registerSession(Object key, WsSession wsSession)
setAsyncSendTimeoutback to summary
public void setAsyncSendTimeout(long timeout)

Implements jakarta.websocket.WebSocketContainer.setAsyncSendTimeout.

Doc from jakarta.websocket.WebSocketContainer.setAsyncSendTimeout.

Set the default timeout for sending a message asynchronously. The default value for this implementation is -1.

Parameters
timeout:long

The new default timeout in milliseconds. A non-positive value means an infinite timeout.

Annotations
@Override
setDefaultMaxBinaryMessageBufferSizeback to summary
public void setDefaultMaxBinaryMessageBufferSize(int max)

Implements jakarta.websocket.WebSocketContainer.setDefaultMaxBinaryMessageBufferSize.

Doc from jakarta.websocket.WebSocketContainer.setDefaultMaxBinaryMessageBufferSize.

Set the default maximum buffer size for binary messages.

Parameters
max:int

The new default maximum buffer size in bytes

Annotations
@Override
setDefaultMaxSessionIdleTimeoutback to summary
public void setDefaultMaxSessionIdleTimeout(long timeout)

Implements jakarta.websocket.WebSocketContainer.setDefaultMaxSessionIdleTimeout.

Doc from jakarta.websocket.WebSocketContainer.setDefaultMaxSessionIdleTimeout.

Set the default session idle timeout.

Parameters
timeout:long

The new default session idle timeout in milliseconds. Zero or negative values indicate an infinite timeout.

Annotations
@Override
setDefaultMaxTextMessageBufferSizeback to summary
public void setDefaultMaxTextMessageBufferSize(int max)

Implements jakarta.websocket.WebSocketContainer.setDefaultMaxTextMessageBufferSize.

Doc from jakarta.websocket.WebSocketContainer.setDefaultMaxTextMessageBufferSize.

Set the default maximum buffer size for text messages.

Parameters
max:int

The new default maximum buffer size in characters

Annotations
@Override
setInstanceManagerback to summary
protected void setInstanceManager(InstanceManager instanceManager)
setProcessPeriodback to summary
public void setProcessPeriod(int period)

Implements org.apache.tomcat.websocket.BackgroundProcess.setProcessPeriod.

Annotations
@Override
unregisterSessionback to summary
protected void unregisterSession(Object key, WsSession wsSession)
writeRequestback to summary
private static void writeRequest(AsyncChannelWrapper channel, ByteBuffer request, long timeout) throws TimeoutException, InterruptedException, ExecutionException
org.apache.tomcat.websocket back to summary

private Class WsWebSocketContainer.HttpResponse

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.tomcat.websocket.WsWebSocketContainer.HttpResponse

Field Summary

Modifier and TypeField and Description
private final HandshakeResponse
private final int

Constructor Summary

AccessConstructor and Description
pack-priv
HttpResponse(int status, HandshakeResponse handshakeResponse)

Method Summary

Modifier and TypeMethod and Description
public HandshakeResponse
public int
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

handshakeResponseback to summary
private final HandshakeResponse handshakeResponse
statusback to summary
private final int status

Constructor Detail

HttpResponseback to summary
pack-priv HttpResponse(int status, HandshakeResponse handshakeResponse)

Method Detail

getHandshakeResponseback to summary
public HandshakeResponse getHandshakeResponse()
getStatusback to summary
public int getStatus()