Class ClientManager
- java.lang.Object
-
- org.glassfish.tyrus.core.ExecutorServiceProvider
-
- org.glassfish.tyrus.core.BaseContainer
-
- org.glassfish.tyrus.client.ClientManager
-
- All Implemented Interfaces:
WebSocketContainer
public class ClientManager extends BaseContainer implements WebSocketContainer
ClientManager implementation.- Author:
- Stepan Kopriva (stepan.kopriva at oracle.com), Pavel Bucek (pavel.bucek at oracle.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClientManager.ReconnectHandler
Reconnect handler.-
Nested classes/interfaces inherited from class org.glassfish.tyrus.core.BaseContainer
BaseContainer.ShutDownCondition
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
HANDSHAKE_TIMEOUT
Deprecated.please useClientProperties.HANDSHAKE_TIMEOUT
.static java.lang.String
PROXY_HEADERS
Deprecated.please useClientProperties.PROXY_HEADERS
.static java.lang.String
PROXY_URI
Deprecated.please useClientProperties.PROXY_URI
.static java.lang.String
RECONNECT_HANDLER
Deprecated.please useClientProperties.RECONNECT_HANDLER
.static java.lang.String
SSL_ENGINE_CONFIGURATOR
Deprecated.please useClientProperties.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 Summary
Constructors Constructor Description ClientManager()
Create newClientManager
instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.concurrent.Future<Session>
asyncConnectToServer(java.lang.Class<?> annotatedEndpointClass, java.net.URI path)
Non-blocking version ofWebSocketContainer.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 ofWebSocketContainer.connectToServer(Class, javax.websocket.ClientEndpointConfig, java.net.URI)
.java.util.concurrent.Future<Session>
asyncConnectToServer(java.lang.Object obj, java.net.URI path)
Non-blocking version ofWebSocketContainer.connectToServer(Object, java.net.URI)
.java.util.concurrent.Future<Session>
asyncConnectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path)
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(java.lang.Object obj, java.net.URI path)
Connect the supplied annotated endpoint instance 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.static ClientManager
createClient()
Create newClientManager
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 providedWebSocketContainer
instance.static ClientManager
createClient(WebSocketContainer webSocketContainer)
Create new ClientManager instance on top of providedWebSocketContainer
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.-
Methods inherited from class org.glassfish.tyrus.core.BaseContainer
getExecutorService, getScheduledExecutorService, shutdown, shutdown
-
-
-
-
Field Detail
-
HANDSHAKE_TIMEOUT
public static final java.lang.String HANDSHAKE_TIMEOUT
Deprecated.please useClientProperties.HANDSHAKE_TIMEOUT
.Property usable ingetProperties()
.Value must be
int
and represents handshake timeout in milliseconds. Default value is 30000 (30 seconds).- See Also:
- Constant Field Values
-
RECONNECT_HANDLER
public static final java.lang.String RECONNECT_HANDLER
Deprecated.please useClientProperties.RECONNECT_HANDLER
.Property usable ingetProperties()
.Value must be
ClientManager.ReconnectHandler
instance.- See Also:
- Constant Field Values
-
PROXY_URI
public static final java.lang.String PROXY_URI
Deprecated.please useClientProperties.PROXY_URI
.Client-side user property to set proxy URI.Value is expected to be
String
and represent proxy URI. Protocol part is currently ignored but must be present (URI(String)
is used for parsing).client.getProperties().put(ClientManager.PROXY_URI, "http://my.proxy.com:80"); client.connectToServer(...);
-
PROXY_HEADERS
public static final java.lang.String PROXY_HEADERS
Deprecated.please useClientProperties.PROXY_HEADERS
.Client-side user property to set additional 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, seeClientEndpointConfig.Configurator.beforeRequest(java.util.Map)
.
-
SSL_ENGINE_CONFIGURATOR
public static final java.lang.String SSL_ENGINE_CONFIGURATOR
Deprecated.please useClientProperties.SSL_ENGINE_CONFIGURATOR
.Property usable ingetProperties()
as a key for SSL configuration.Value is expected to be either
org.glassfish.grizzly.ssl.SSLEngineConfigurator
when configuring Grizzly client orSslEngineConfigurator
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);
- See Also:
- Constant Field Values
-
WLS_PROXY_HOST
public static final java.lang.String WLS_PROXY_HOST
- See Also:
- Constant Field Values
-
WLS_PROXY_PORT
public static final java.lang.String WLS_PROXY_PORT
- See Also:
- Constant Field Values
-
WLS_PROXY_USERNAME
public static final java.lang.String WLS_PROXY_USERNAME
- See Also:
- Constant Field Values
-
WLS_PROXY_PASSWORD
public static final java.lang.String WLS_PROXY_PASSWORD
- See Also:
- Constant Field Values
-
WLS_SSL_PROTOCOLS_PROPERTY
public static final java.lang.String WLS_SSL_PROTOCOLS_PROPERTY
- See Also:
- Constant Field Values
-
WLS_SSL_TRUSTSTORE_PROPERTY
public static final java.lang.String WLS_SSL_TRUSTSTORE_PROPERTY
- See Also:
- Constant Field Values
-
WLS_SSL_TRUSTSTORE_PWD_PROPERTY
public static final java.lang.String WLS_SSL_TRUSTSTORE_PWD_PROPERTY
- See Also:
- Constant Field Values
-
WLS_MAX_THREADS
public static final java.lang.String WLS_MAX_THREADS
- See Also:
- Constant Field Values
-
WLS_IGNORE_HOSTNAME_VERIFICATION
public static final java.lang.String WLS_IGNORE_HOSTNAME_VERIFICATION
- See Also:
- Constant Field Values
-
WLS_HOSTNAME_VERIFIER_CLASS
public static final java.lang.String WLS_HOSTNAME_VERIFIER_CLASS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ClientManager
public ClientManager()
Create newClientManager
instance.Uses
CONTAINER_PROVIDER_CLASSNAME
as container implementation, thus relevant module needs to be on classpath. Setting different container is possible viacreateClient(String)
}.- See Also:
createClient(String)
-
-
Method Detail
-
createClient
public static ClientManager createClient()
Create newClientManager
instance.Uses
CONTAINER_PROVIDER_CLASSNAME
as container implementation, thus relevant module needs to be on classpath. Setting different container is possible viacreateClient(String)
.- Returns:
- created client manager.
- See Also:
createClient(String)
-
createClient
public static ClientManager createClient(WebSocketContainer webSocketContainer)
Create new ClientManager instance on top of providedWebSocketContainer
instance.Uses
CONTAINER_PROVIDER_CLASSNAME
as container implementation, thus relevant module needs to be on classpath. Setting different container is possible viacreateClient(String)
.- Parameters:
webSocketContainer
- websocket container.- Returns:
- created client manager.
- See Also:
createClient(String)
-
createClient
public static ClientManager createClient(java.lang.String containerProviderClassName)
Create new ClientManager instance.- Parameters:
containerProviderClassName
- classname of container provider. It will be loaded using context class loader.- Returns:
- new ClientManager instance.
-
createClient
public static ClientManager createClient(java.lang.String containerProviderClassName, WebSocketContainer webSocketContainer)
Create new ClientManager instance on top of providedWebSocketContainer
instance.- Parameters:
containerProviderClassName
- classname of container provider. It will be loaded using context class loader.webSocketContainer
- websocket container.- Returns:
- new ClientManager instance.
-
connectToServer
public Session connectToServer(java.lang.Class annotatedEndpointClass, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect the supplied annotated endpoint to its server. The supplied object must be a class decorated with the class leveljavax.websocket.server.ServerEndpoint
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.- Specified by:
connectToServer
in interfaceWebSocketContainer
- Parameters:
annotatedEndpointClass
- the annotated websocket client endpoint.path
- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
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.
-
connectToServer
public Session connectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect the supplied programmatic endpoint to its server with the given configuration. This method blocks until the connection is established, or throws an error if the connection could not be made.- Specified by:
connectToServer
in interfaceWebSocketContainer
- Parameters:
endpointClass
- the programmatic client endpoint classEndpoint
.cec
- the configuration used to configure the programmatic endpoint.path
- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
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 server
-
connectToServer
public Session connectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect the supplied programmatic client endpoint instance to its server with the given configuration. This method blocks until the connection is established, or throws an error if the connection could not be made. 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, useWebSocketContainer.connectToServer(java.lang.Class, javax.websocket.ClientEndpointConfig, java.net.URI)
instead.- Specified by:
connectToServer
in interfaceWebSocketContainer
- Parameters:
endpointInstance
- the programmatic client endpoint instanceEndpoint
.cec
- the configuration used to configure the programmatic endpoint.path
- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
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 server
-
connectToServer
public Session connectToServer(java.lang.Object obj, java.net.URI path) throws DeploymentException, java.io.IOException
Description copied from interface:WebSocketContainer
Connect the supplied annotated endpoint instance to its server. The supplied object must be a class decorated with the class leveljavax.websocket.server.ServerEndpoint
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, useWebSocketContainer.connectToServer(java.lang.Class, java.net.URI)
instead.- Specified by:
connectToServer
in interfaceWebSocketContainer
- Parameters:
obj
- the annotated websocket client endpoint instance.path
- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
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.
-
asyncConnectToServer
public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Class<?> annotatedEndpointClass, java.net.URI path) throws DeploymentException
Non-blocking version ofWebSocketContainer.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.
- Parameters:
annotatedEndpointClass
- the annotated websocket client endpoint.path
- the complete path to the server endpoint.- Returns:
- Future for the Session created if the connection is successful.
- Throws:
DeploymentException
- if the class is not a valid annotated endpoint class.
-
asyncConnectToServer
public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Class<? extends Endpoint> endpointClass, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException
Non-blocking version ofWebSocketContainer.connectToServer(Class, javax.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.
- Parameters:
endpointClass
- the programmatic client endpoint classEndpoint
.path
- the complete path to the server endpoint.cec
- the configuration used to configure the programmatic endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException
- if the configuration is not valid- See Also:
WebSocketContainer.connectToServer(Class, javax.websocket.ClientEndpointConfig, java.net.URI)
-
asyncConnectToServer
public java.util.concurrent.Future<Session> asyncConnectToServer(Endpoint endpointInstance, ClientEndpointConfig cec, java.net.URI path) throws DeploymentException
Non-blocking version ofWebSocketContainer.connectToServer(javax.websocket.Endpoint, javax.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.
- Parameters:
endpointInstance
- the programmatic client endpoint instanceEndpoint
.path
- the complete path to the server endpoint.cec
- the configuration used to configure the programmatic endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException
- if the configuration is not valid- See Also:
WebSocketContainer.connectToServer(javax.websocket.Endpoint, javax.websocket.ClientEndpointConfig, java.net.URI)
-
asyncConnectToServer
public java.util.concurrent.Future<Session> asyncConnectToServer(java.lang.Object obj, java.net.URI path) throws DeploymentException
Non-blocking version ofWebSocketContainer.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.
- Parameters:
obj
- the annotated websocket client endpoint instance.path
- the complete path to the server endpoint.- Returns:
- the Session created if the connection is successful.
- Throws:
DeploymentException
- if the annotated endpoint instance is not valid.- See Also:
WebSocketContainer.connectToServer(Object, java.net.URI)
-
getDefaultMaxBinaryMessageBufferSize
public int getDefaultMaxBinaryMessageBufferSize()
Description copied from interface:WebSocketContainer
Returns the default maximum size of incoming binary message that this container will buffer. This default may be overridden on a per session basis usingSession.setMaxBinaryMessageBufferSize(int)
- Specified by:
getDefaultMaxBinaryMessageBufferSize
in interfaceWebSocketContainer
- Returns:
- the maximum size of incoming binary message in number of bytes.
-
setDefaultMaxBinaryMessageBufferSize
public void setDefaultMaxBinaryMessageBufferSize(int i)
Description copied from interface:WebSocketContainer
Sets the default maximum size of incoming binary message that this container will buffer.- Specified by:
setDefaultMaxBinaryMessageBufferSize
in interfaceWebSocketContainer
- Parameters:
i
- the maximum size of binary message in number of bytes.
-
getDefaultMaxTextMessageBufferSize
public int getDefaultMaxTextMessageBufferSize()
Description copied from interface:WebSocketContainer
Returns the default maximum size of incoming text message that this container will buffer. This default may be overridden on a per session basis usingSession.setMaxTextMessageBufferSize(int)
- Specified by:
getDefaultMaxTextMessageBufferSize
in interfaceWebSocketContainer
- Returns:
- the maximum size of incoming text message in number of bytes.
-
setDefaultMaxTextMessageBufferSize
public void setDefaultMaxTextMessageBufferSize(int i)
Description copied from interface:WebSocketContainer
Sets the maximum size of incoming text message that this container will buffer.- Specified by:
setDefaultMaxTextMessageBufferSize
in interfaceWebSocketContainer
- Parameters:
i
- the maximum size of text message in number of bytes.
-
getInstalledExtensions
public java.util.Set<Extension> getInstalledExtensions()
Description copied from interface:WebSocketContainer
Return the set of Extensions installed in the container.- Specified by:
getInstalledExtensions
in interfaceWebSocketContainer
- Returns:
- the set of extensions.
-
getDefaultAsyncSendTimeout
public long getDefaultAsyncSendTimeout()
Description copied from interface:WebSocketContainer
Return the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A non-positive number indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.- Specified by:
getDefaultAsyncSendTimeout
in interfaceWebSocketContainer
- Returns:
- the timeout time in milliseconds.
-
setAsyncSendTimeout
public void setAsyncSendTimeout(long timeoutmillis)
Description copied from interface:WebSocketContainer
Sets the number of milliseconds the implementation will timeout attempting to send a websocket message for all RemoteEndpoints associated with this container. A non-positive number indicates the implementation will not timeout attempting to send a websocket message asynchronously. Note this default may be overridden in each RemoteEndpoint.- Specified by:
setAsyncSendTimeout
in interfaceWebSocketContainer
- Parameters:
timeoutmillis
- the timeout in milliseconds or a non-positive number for no timeout
-
getDefaultMaxSessionIdleTimeout
public long getDefaultMaxSessionIdleTimeout()
Description copied from interface:WebSocketContainer
Return the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive. A value that is 0 or negative indicates the sessions will never timeout due to inactivity. The value may be overridden on a per session basis usingSession.setMaxIdleTimeout(long)
- Specified by:
getDefaultMaxSessionIdleTimeout
in interfaceWebSocketContainer
- Returns:
- the default number of milliseconds after which an idle session in this container will be closed
-
setDefaultMaxSessionIdleTimeout
public void setDefaultMaxSessionIdleTimeout(long defaultMaxSessionIdleTimeout)
Description copied from interface:WebSocketContainer
Sets the default time in milliseconds after which any web socket sessions in this container will be closed if it has been inactive. A value that is 0 or negative indicates the sessions will never timeout due to inactivity. The value may be overridden on a per session basis usingSession.setMaxIdleTimeout(long)
- Specified by:
setDefaultMaxSessionIdleTimeout
in interfaceWebSocketContainer
- Parameters:
defaultMaxSessionIdleTimeout
- the maximum time in milliseconds.
-
getProperties
public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Container properties.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.
- Returns:
- map containing container properties.
- See Also:
ClientProperties
-
-