Class ClientManager

  • All Implemented Interfaces:
    jakarta.websocket.WebSocketContainer

    public class ClientManager
    extends org.glassfish.tyrus.core.BaseContainer
    implements jakarta.websocket.WebSocketContainer
    ClientManager implementation.
    Author:
    Stepan Kopriva, Pavel Bucek
    • Field Detail

      • PROXY_URI

        public static final java.lang.String PROXY_URI
        Deprecated.
        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(...);
         
        See Also:
        EndpointConfig.getUserProperties(), Constant Field Values
      • PROXY_HEADERS

        public static final java.lang.String PROXY_HEADERS
        Deprecated.
        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, see ClientEndpointConfig.Configurator.beforeRequest(java.util.Map).
        See Also:
        EndpointConfig.getUserProperties(), Constant Field Values
      • SSL_ENGINE_CONFIGURATOR

        public static final java.lang.String SSL_ENGINE_CONFIGURATOR
        Property usable in 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);
         
        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_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
    • Method Detail

      • createClient

        public static ClientManager createClient​(jakarta.websocket.WebSocketContainer webSocketContainer)
        Create new ClientManager instance on top of provided 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).

        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,
                                                 jakarta.websocket.WebSocketContainer webSocketContainer)
        Create new ClientManager instance on top of provided WebSocketContainer instance.
        Parameters:
        containerProviderClassName - classname of container provider. It will be loaded using context class loader.
        webSocketContainer - websocket container.
        Returns:
        new ClientManager instance.
      • connectToServer

        public jakarta.websocket.Session connectToServer​(java.lang.Class annotatedEndpointClass,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • connectToServer

        public jakarta.websocket.Session connectToServer​(java.lang.Class<? extends jakarta.websocket.Endpoint> endpointClass,
                                                         jakarta.websocket.ClientEndpointConfig cec,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • connectToServer

        public jakarta.websocket.Session connectToServer​(jakarta.websocket.Endpoint endpointInstance,
                                                         jakarta.websocket.ClientEndpointConfig cec,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • connectToServer

        public jakarta.websocket.Session connectToServer​(java.lang.Object obj,
                                                         java.net.URI path)
                                                  throws jakarta.websocket.DeploymentException,
                                                         java.io.IOException
        Specified by:
        connectToServer in interface jakarta.websocket.WebSocketContainer
        Throws:
        jakarta.websocket.DeploymentException
        java.io.IOException
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Class<?> annotatedEndpointClass,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of 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.

        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:
        jakarta.websocket.DeploymentException - if the class is not a valid annotated endpoint class.
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Class<? extends jakarta.websocket.Endpoint> endpointClass,
                                                                                           jakarta.websocket.ClientEndpointConfig cec,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of 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.

        Parameters:
        endpointClass - the programmatic client endpoint class Endpoint.
        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:
        jakarta.websocket.DeploymentException - if the configuration is not valid
        See Also:
        WebSocketContainer.connectToServer(Class, jakarta.websocket.ClientEndpointConfig, java.net.URI)
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(jakarta.websocket.Endpoint endpointInstance,
                                                                                           jakarta.websocket.ClientEndpointConfig cec,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of 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.

        Parameters:
        endpointInstance - the programmatic client endpoint instance Endpoint.
        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:
        jakarta.websocket.DeploymentException - if the configuration is not valid
        See Also:
        WebSocketContainer.connectToServer(jakarta.websocket.Endpoint, jakarta.websocket.ClientEndpointConfig, java.net.URI)
      • asyncConnectToServer

        public java.util.concurrent.Future<jakarta.websocket.Session> asyncConnectToServer​(java.lang.Object obj,
                                                                                           java.net.URI path)
                                                                                    throws jakarta.websocket.DeploymentException
        Non-blocking version of 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.

        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:
        jakarta.websocket.DeploymentException - if the annotated endpoint instance is not valid.
        See Also:
        WebSocketContainer.connectToServer(Object, java.net.URI)
      • getDefaultMaxBinaryMessageBufferSize

        public int getDefaultMaxBinaryMessageBufferSize()
        Specified by:
        getDefaultMaxBinaryMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • setDefaultMaxBinaryMessageBufferSize

        public void setDefaultMaxBinaryMessageBufferSize​(int i)
        Specified by:
        setDefaultMaxBinaryMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • getDefaultMaxTextMessageBufferSize

        public int getDefaultMaxTextMessageBufferSize()
        Specified by:
        getDefaultMaxTextMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • setDefaultMaxTextMessageBufferSize

        public void setDefaultMaxTextMessageBufferSize​(int i)
        Specified by:
        setDefaultMaxTextMessageBufferSize in interface jakarta.websocket.WebSocketContainer
      • getInstalledExtensions

        public java.util.Set<jakarta.websocket.Extension> getInstalledExtensions()
        Specified by:
        getInstalledExtensions in interface jakarta.websocket.WebSocketContainer
      • getDefaultAsyncSendTimeout

        public long getDefaultAsyncSendTimeout()
        Specified by:
        getDefaultAsyncSendTimeout in interface jakarta.websocket.WebSocketContainer
      • setAsyncSendTimeout

        public void setAsyncSendTimeout​(long timeoutmillis)
        Specified by:
        setAsyncSendTimeout in interface jakarta.websocket.WebSocketContainer
      • getDefaultMaxSessionIdleTimeout

        public long getDefaultMaxSessionIdleTimeout()
        Specified by:
        getDefaultMaxSessionIdleTimeout in interface jakarta.websocket.WebSocketContainer
      • setDefaultMaxSessionIdleTimeout

        public void setDefaultMaxSessionIdleTimeout​(long defaultMaxSessionIdleTimeout)
        Specified by:
        setDefaultMaxSessionIdleTimeout in interface jakarta.websocket.WebSocketContainer
      • 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