public class ClientManager extends BaseContainer implements WebSocketContainer
Modifier and Type | Class and Description |
---|---|
static class |
ClientManager.ReconnectHandler
Reconnect handler.
|
BaseContainer.ShutDownCondition
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
HANDSHAKE_TIMEOUT
Deprecated.
please use
ClientProperties.HANDSHAKE_TIMEOUT . |
static java.lang.String |
PROXY_HEADERS
Deprecated.
please use
ClientProperties.PROXY_HEADERS . |
static java.lang.String |
PROXY_URI
Deprecated.
please use
ClientProperties.PROXY_URI . |
static java.lang.String |
RECONNECT_HANDLER
Deprecated.
please use
ClientProperties.RECONNECT_HANDLER . |
static java.lang.String |
SSL_ENGINE_CONFIGURATOR
Deprecated.
please use
ClientProperties.SSL_ENGINE_CONFIGURATOR . |
static java.lang.String |
WLS_HOSTNAME_VERIFIER_CLASS |
static java.lang.String |
WLS_IGNORE_HOSTNAME_VERIFICATION |
static java.lang.String |
WLS_MAX_THREADS |
static java.lang.String |
WLS_PROXY_HOST |
static java.lang.String |
WLS_PROXY_PASSWORD |
static java.lang.String |
WLS_PROXY_PORT |
static java.lang.String |
WLS_PROXY_USERNAME |
static java.lang.String |
WLS_SSL_PROTOCOLS_PROPERTY |
static java.lang.String |
WLS_SSL_TRUSTSTORE_PROPERTY |
static java.lang.String |
WLS_SSL_TRUSTSTORE_PWD_PROPERTY |
Constructor and Description |
---|
ClientManager()
Create new
ClientManager instance. |
Modifier and Type | Method and Description |
---|---|
java.util.concurrent.Future<Session> |
asyncConnectToServer(java.lang.Class<?> annotatedEndpointClass,
java.net.URI path)
Non-blocking version of
WebSocketContainer.connectToServer(Class, java.net.URI) . |
java.util.concurrent.Future<Session> |
asyncConnectToServer(java.lang.Class<? extends Endpoint> endpointClass,
ClientEndpointConfig cec,
java.net.URI path)
Non-blocking version of
WebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig,
java.net.URI) . |
java.util.concurrent.Future<Session> |
asyncConnectToServer(Endpoint endpointInstance,
ClientEndpointConfig cec,
java.net.URI path)
|
java.util.concurrent.Future<Session> |
asyncConnectToServer(java.lang.Object obj,
java.net.URI path)
Non-blocking version of
WebSocketContainer.connectToServer(Object, java.net.URI) . |
Session |
connectToServer(java.lang.Class<? extends Endpoint> endpointClass,
ClientEndpointConfig cec,
java.net.URI path)
Connect the supplied programmatic endpoint to its server with the given configuration.
|
Session |
connectToServer(java.lang.Class annotatedEndpointClass,
java.net.URI path)
Connect the supplied annotated endpoint to its server.
|
Session |
connectToServer(Endpoint endpointInstance,
ClientEndpointConfig cec,
java.net.URI path)
Connect the supplied programmatic client endpoint instance to its server with the given configuration.
|
Session |
connectToServer(java.lang.Object obj,
java.net.URI path)
Connect the supplied annotated endpoint instance to its server.
|
static ClientManager |
createClient()
Create new
ClientManager instance. |
static ClientManager |
createClient(java.lang.String containerProviderClassName)
Create new ClientManager instance.
|
static ClientManager |
createClient(java.lang.String containerProviderClassName,
WebSocketContainer webSocketContainer)
Create new ClientManager instance on top of provided
WebSocketContainer instance. |
static ClientManager |
createClient(WebSocketContainer webSocketContainer)
Create new ClientManager instance on top of provided
WebSocketContainer instance. |
long |
getDefaultAsyncSendTimeout()
Return the number of milliseconds the implementation will timeout attempting to send a websocket message for all
RemoteEndpoints associated with this container.
|
int |
getDefaultMaxBinaryMessageBufferSize()
Returns the default maximum size of incoming binary message that this container will buffer.
|
long |
getDefaultMaxSessionIdleTimeout()
Return the default time in milliseconds after which any web socket sessions in this container will be closed if
it has been inactive.
|
int |
getDefaultMaxTextMessageBufferSize()
Returns the default maximum size of incoming text message that this container will buffer.
|
java.util.Set<Extension> |
getInstalledExtensions()
Return the set of Extensions installed in the container.
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
Container properties.
|
void |
setAsyncSendTimeout(long timeoutmillis)
Sets the number of milliseconds the implementation will timeout attempting to send a websocket message for all
RemoteEndpoints associated with this container.
|
void |
setDefaultMaxBinaryMessageBufferSize(int i)
Sets the default maximum size of incoming binary message that this container will buffer.
|
void |
setDefaultMaxSessionIdleTimeout(long defaultMaxSessionIdleTimeout)
Sets the default time in milliseconds after which any web socket sessions in this container will be closed if it
has been inactive.
|
void |
setDefaultMaxTextMessageBufferSize(int i)
Sets the maximum size of incoming text message that this container will buffer.
|
getExecutorService, getScheduledExecutorService, shutdown, shutdown
public static final java.lang.String HANDSHAKE_TIMEOUT
ClientProperties.HANDSHAKE_TIMEOUT
.getProperties()
.
Value must be int
and represents handshake timeout in milliseconds. Default value is 30000 (30 seconds).
public static final java.lang.String RECONNECT_HANDLER
ClientProperties.RECONNECT_HANDLER
.getProperties()
.
Value must be ClientManager.ReconnectHandler
instance.
public static final java.lang.String PROXY_URI
ClientProperties.PROXY_URI
.
Value is expected to be String
and represent proxy URI. Protocol part is currently ignored
but must be present (URI.URI(String)
is used for parsing).
client.getProperties().put(ClientManager.PROXY_URI, "http://my.proxy.com:80"); client.connectToServer(...);
public static final java.lang.String PROXY_HEADERS
ClientProperties.PROXY_HEADERS
.
Value is expected to be Map
<String
, String
> and represent raw http headers
to be added to initial request which is sent to proxy. Key corresponds to header name, value is header
value.
Sample below demonstrates use of this feature to set preemptive basic proxy authentication:
final HashMap<String, String> proxyHeaders = new HashMap<String, String>(); proxyHeaders.put("Proxy-Authorization", "Basic " + Base64.getEncoder().encodeToString("username:password".getBytes(Charset.forName("UTF-8")))); client.getProperties().put(GrizzlyClientSocket.PROXY_HEADERS, proxyHeaders); client.connectToServer(...);Please note that these headers will be used only when establishing proxy connection, for modifying WebSocket handshake headers, see
ClientEndpointConfig.Configurator.beforeRequest(java.util.Map)
.public static final java.lang.String SSL_ENGINE_CONFIGURATOR
ClientProperties.SSL_ENGINE_CONFIGURATOR
.getProperties()
as a key for SSL configuration.
Value is expected to be either org.glassfish.grizzly.ssl.SSLEngineConfigurator
when configuring Grizzly
client or SslEngineConfigurator
when configuring JDK client.
Example configuration for JDK client:
SslContextConfigurator sslContextConfigurator = new SslContextConfigurator(); sslContextConfigurator.setTrustStoreFile("..."); sslContextConfigurator.setTrustStorePassword("..."); sslContextConfigurator.setTrustStoreType("..."); sslContextConfigurator.setKeyStoreFile("..."); sslContextConfigurator.setKeyStorePassword("..."); sslContextConfigurator.setKeyStoreType("..."); SslEngineConfigurator sslEngineConfigurator = new SslEngineConfigurator(sslContextConfigurator, true, false, false); client.getProperties().put(ClientManager.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
public static final java.lang.String WLS_PROXY_HOST
public static final java.lang.String WLS_PROXY_PORT
public static final java.lang.String WLS_PROXY_USERNAME
public static final java.lang.String WLS_PROXY_PASSWORD
public static final java.lang.String WLS_SSL_PROTOCOLS_PROPERTY
public static final java.lang.String WLS_SSL_TRUSTSTORE_PROPERTY
public static final java.lang.String WLS_SSL_TRUSTSTORE_PWD_PROPERTY
public static final java.lang.String WLS_MAX_THREADS
public static final java.lang.String WLS_IGNORE_HOSTNAME_VERIFICATION
public static final java.lang.String WLS_HOSTNAME_VERIFIER_CLASS
public ClientManager()
ClientManager
instance.
Uses CONTAINER_PROVIDER_CLASSNAME
as container implementation, thus relevant module needs
to be on classpath. Setting different container is possible via createClient(String)
}.
createClient(String)
public static ClientManager createClient()
ClientManager
instance.
Uses CONTAINER_PROVIDER_CLASSNAME
as container implementation, thus relevant module needs
to be on classpath. Setting different container is possible via createClient(String)
.
createClient(String)
public static ClientManager createClient(WebSocketContainer webSocketContainer)
WebSocketContainer
instance.
Uses CONTAINER_PROVIDER_CLASSNAME
as container implementation, thus relevant module needs
to be on classpath. Setting different container is possible via createClient(String)
.
webSocketContainer
- websocket container.createClient(String)
public static ClientManager createClient(java.lang.String containerProviderClassName)
containerProviderClassName
- classname of container provider. It will be loaded using context class loader.public static ClientManager createClient(java.lang.String containerProviderClassName, WebSocketContainer webSocketContainer)
WebSocketContainer
instance.containerProviderClassName
- classname of container provider. It will be loaded using context class loader.webSocketContainer
- websocket container.public Session connectToServer(java.lang.Class annotatedEndpointClass, java.net.URI path) throws DeploymentException, java.io.IOException
WebSocketContainer
ClientEndpoint
annotation. This method blocks until the connection is
established, or throws an error if either the connection could not be made or there was a problem with the
supplied endpoint class.connectToServer
in interface WebSocketContainer
annotatedEndpointClass
- the annotated websocket client endpoint.path
- the complete path to the server endpoint.DeploymentException
- if the class is not a valid annotated endpoint class.java.io.IOException
- if there was a network or protocol problem that prevented the client endpoint being
connected to its server.public Session connectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException, java.io.IOException
WebSocketContainer
connectToServer
in interface WebSocketContainer
endpointClass
- the programmatic client endpoint class Endpoint
.cec
- the configuration used to configure the programmatic endpoint.path
- the complete path to the server endpoint.DeploymentException
- if the configuration is not validjava.io.IOException
- if there was a network or protocol problem that prevented the client endpoint being
connected to its serverpublic Session connectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException, java.io.IOException
WebSocketContainer
WebSocketContainer.connectToServer(java.lang.Class, jakarta.websocket.ClientEndpointConfig, java.net.URI)
instead.connectToServer
in interface WebSocketContainer
endpointInstance
- the programmatic client endpoint instance Endpoint
.cec
- the configuration used to configure the programmatic endpoint.path
- the complete path to the server endpoint.DeploymentException
- if the configuration is not validjava.io.IOException
- if there was a network or protocol problem that prevented the client endpoint being
connected to its serverpublic Session connectToServer(java.lang.Object obj, java.net.URI path) throws DeploymentException, java.io.IOException
WebSocketContainer
ClientEndpoint
annotation. This method blocks until the
connection is established, or throws an error if either the connection could not be made or there was a problem
with the supplied endpoint class. If the developer uses this method to deploy the client endpoint, services like
dependency injection that are supported, for example, when the implementation is part of the Java EE platform may
not be available. If the client endpoint uses dependency injection, use
WebSocketContainer.connectToServer(java.lang.Class, java.net.URI)
instead.connectToServer
in interface WebSocketContainer
obj
- the annotated websocket client endpoint instance.path
- the complete path to the server endpoint.DeploymentException
- if the annotated endpoint instance is not valid.java.io.IOException
- if there was a network or protocol problem that prevented the client endpoint being
connected to its server.public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Class<?> annotatedEndpointClass, java.net.URI path) throws DeploymentException
WebSocketContainer.connectToServer(Class, java.net.URI)
.
Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
annotatedEndpointClass
- the annotated websocket client endpoint.path
- the complete path to the server endpoint.DeploymentException
- if the class is not a valid annotated endpoint class.public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException
WebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig,
java.net.URI)
.
Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
endpointClass
- the programmatic client endpoint class Endpoint
.path
- the complete path to the server endpoint.cec
- the configuration used to configure the programmatic endpoint.DeploymentException
- if the configuration is not validWebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI)
public java.util.concurrent.Future<Session> asyncConnectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException
WebSocketContainer.connectToServer(jakarta.websocket.Endpoint,
jakarta.websocket.ClientEndpointConfig, java.net.URI)
.
Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
endpointInstance
- the programmatic client endpoint instance Endpoint
.path
- the complete path to the server endpoint.cec
- the configuration used to configure the programmatic endpoint.DeploymentException
- if the configuration is not validWebSocketContainer.connectToServer(jakarta.websocket.Endpoint, jakarta.websocket.ClientEndpointConfig,
java.net.URI)
public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Object obj, java.net.URI path) throws DeploymentException
WebSocketContainer.connectToServer(Object, java.net.URI)
.
Only simple checks are performed in the main thread; client container is created in different thread, same applies to connecting etc.
obj
- the annotated websocket client endpoint instance.path
- the complete path to the server endpoint.DeploymentException
- if the annotated endpoint instance is not valid.WebSocketContainer.connectToServer(Object, java.net.URI)
public int getDefaultMaxBinaryMessageBufferSize()
WebSocketContainer
Session.setMaxBinaryMessageBufferSize(int)
getDefaultMaxBinaryMessageBufferSize
in interface WebSocketContainer
public void setDefaultMaxBinaryMessageBufferSize(int i)
WebSocketContainer
setDefaultMaxBinaryMessageBufferSize
in interface WebSocketContainer
i
- the maximum size of binary message in number of bytes.public int getDefaultMaxTextMessageBufferSize()
WebSocketContainer
Session.setMaxTextMessageBufferSize(int)
getDefaultMaxTextMessageBufferSize
in interface WebSocketContainer
public void setDefaultMaxTextMessageBufferSize(int i)
WebSocketContainer
setDefaultMaxTextMessageBufferSize
in interface WebSocketContainer
i
- the maximum size of text message in number of bytes.public java.util.Set<Extension> getInstalledExtensions()
WebSocketContainer
getInstalledExtensions
in interface WebSocketContainer
public long getDefaultAsyncSendTimeout()
WebSocketContainer
getDefaultAsyncSendTimeout
in interface WebSocketContainer
public void setAsyncSendTimeout(long timeoutmillis)
WebSocketContainer
setAsyncSendTimeout
in interface WebSocketContainer
timeoutmillis
- the timeout in milliseconds or a non-positive number for no timeoutpublic long getDefaultMaxSessionIdleTimeout()
WebSocketContainer
Session.setMaxIdleTimeout(long)
getDefaultMaxSessionIdleTimeout
in interface WebSocketContainer
public void setDefaultMaxSessionIdleTimeout(long defaultMaxSessionIdleTimeout)
WebSocketContainer
Session.setMaxIdleTimeout(long)
setDefaultMaxSessionIdleTimeout
in interface WebSocketContainer
defaultMaxSessionIdleTimeout
- the maximum time in milliseconds.public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Used to set container specific configuration as SSL truststore and keystore, HTTP Proxy configuration and maximum incoming buffer size. These properties cannot be shared among various containers due to constraints in WebSocket API, so if you need to have multiple configurations, you will need to create multiple ClientManager instances or synchronize connectToServer method invocations.
ClientProperties
Copyright © 2012–2020 Oracle Corporation. All rights reserved.