Top Description Fields Constructors Methods
org.glassfish.tyrus.client

public final Class ClientProperties

extends Object
Class Inheritance
Imports
java.net.InetAddress, .URI, org.glassfish.tyrus.client.auth.AuthConfig, .AuthenticationException, .Authenticator, .Credentials, org.glassfish.tyrus.spi.UpgradeResponse

Tyrus client configuration properties.
Author
Petr Janouch

Field Summary

Modifier and TypeField and Description
public static final String
AUTH_CONFIG

Authentication configuration.

public static final String
CREDENTIALS

Authentication credentials.

public static final String
public static final String
INCOMING_BUFFER_SIZE

Property name for maximal incoming buffer size.

public static final String
LOG_HTTP_UPGRADE

User property to configure logging of HTTP upgrade messages.

public static final String
MASKING_KEY_GENERATOR

Property name for registering a custom masking key generator.

public static final String
PROXY_HEADERS

User property to set additional proxy headers.

public static final String
PROXY_URI

User property to set proxy URI.

public static final String
public static final String
REDIRECT_ENABLED

HTTP Redirect support.

public static final String
REDIRECT_THRESHOLD

The maximal number of redirects during single handshake.

public static final String
RETRY_AFTER_SERVICE_UNAVAILABLE

HTTP Service Unavailable - Retry-After reconnect support.

public static final String
SHARED_CONTAINER

When set to true (boolean value), client runtime preserves used container and reuses it for outgoing connections.

public static final String
SHARED_CONTAINER_IDLE_TIMEOUT

Container idle timeout in seconds (Integer value).

public static final String
SOCKET_BINDING

Property name for defining local binding address for all socket created by the client.

public static final String
SSL_ENGINE_CONFIGURATOR

Property usable in ClientManager#getProperties() as a key for SSL configuration.

public static final String
WORKER_THREAD_POOL_CONFIG

User property to set worker thread pool configuration.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AUTH_CONFIGback to summary
public static final String AUTH_CONFIG

Authentication configuration. If no AuthConfig is specified then default configuration will be used, containing both Basic and Digest provided authenticators.

Value must be AuthConfig instance.

Sample below demonstrates how to use this property:

    client.getProperties().put(ClientProperties.AUTH_CONFIG, AuthConfig.builder().enableProvidedBasicAuth()
    .build());
See Also
AuthConfig, AuthConfig.Builder, Authenticator
CREDENTIALSback to summary
public static final String CREDENTIALS

Authentication credentials.

Value must be Credentials instance.

Provided authenticators (both Basic and Digest) require this property set, otherwise AuthenticationException will be thrown during a handshake. User defined authenticators may look up credentials in another sources.

Sample below demonstrates how to use this property:

    client.getProperties().put(ClientProperties.CREDENTIALS, new Credentials("websocket_user", "password");
See Also
Credentials, AuthConfig, Authenticator
HANDSHAKE_TIMEOUTback to summary
public static final String HANDSHAKE_TIMEOUT

Property usable in ClientManager#getProperties().

Value must be int and represents handshake timeout in milliseconds. Default value is 30000 (30 seconds).

INCOMING_BUFFER_SIZEback to summary
public static final String INCOMING_BUFFER_SIZE

Property name for maximal incoming buffer size.

Can be set in properties map (see org.glassfish.tyrus.spi.ClientContainer#openClientSocket(jakarta.websocket.ClientEndpointConfig, java.util.Map, org.glassfish.tyrus.spi.ClientEngine).

LOG_HTTP_UPGRADEback to summary
public static final String LOG_HTTP_UPGRADE

User property to configure logging of HTTP upgrade messages.

Value is expected to be boolean. Default value is false.

When set to true upgrade request and response messages will be logged regardless of the logging level configuration. When the logging is configured to java.util.logging.Level#FINE or lower, this setting will have no effect as at this level HTTP upgrade messages will be logged anyway.

MASKING_KEY_GENERATORback to summary
public static final String MASKING_KEY_GENERATOR

Property name for registering a custom masking key generator. The expected value is an instance of org.glassfish.tyrus.core.MaskingKeyGenerator.

As a security measure, all frames originating on websocket client have to be masked with random 4B value, which should be freshly generated for each frame. Moreover to fully comply with the security requirements of RFC 6455, a masking key of a frame must not be predictable from masking keys of previous frames and therefore Tyrus uses java.security.SecureRandom as a default masking key generator. While this is perfectly OK for most Tyrus client use cases, usage of java.security.SecureRandom might prove to be a performance issue, when the client is used for instance for highly parallel stress testing as java.security.SecureRandom uses a synchronized singleton as a random entropy provider in its internals.

This property allows replacing the default java.security.SecureRandom with a more scalable provider of masking keys.

PROXY_HEADERSback to summary
public static final String PROXY_HEADERS

User property to set additional proxy headers.

Value is expected to be java.util.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(ClientProperties.PROXY_HEADERS, proxyHeaders);
    client.connectToServer(...);
Please note that these headers will be used only when establishing proxy connection, for modifying WebSocket handshake headers, see jakarta.websocket.ClientEndpointConfig.Configurator#beforeRequest(java.util.Map).
See Also
jakarta.websocket.ClientEndpointConfig#getUserProperties()
PROXY_URIback to summary
public static final String PROXY_URI

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 (java.net.URI#URI(String) is used for parsing).

    client.getProperties().put(ClientProperties.PROXY_URI, "http://my.proxy.com:80");
    client.connectToServer(...);
See Also
jakarta.websocket.ClientEndpointConfig#getUserProperties()
RECONNECT_HANDLERback to summary
public static final String RECONNECT_HANDLER

Property usable in ClientManager#getProperties().

Value must be org.glassfish.tyrus.client.ClientManager.ReconnectHandler instance.

See Also
ClientProperties#RETRY_AFTER_SERVICE_UNAVAILABLE
REDIRECT_ENABLEDback to summary
public static final String REDIRECT_ENABLED

HTTP Redirect support.

Value is expected to be boolean. Default value is false.

When set to true and one of the following redirection HTTP response status code (3xx) is received during a handshake, client will attempt to connect to the URI contained in Location header from handshake response. Number of redirection is limited by property REDIRECT_THRESHOLD (integer value), while default value is 5.

List of supported HTTP status codes:

  • 300 - Multiple Choices
  • 301 - Moved permanently
  • 302 - Found
  • 303 - See Other (since HTTP/1.1)
  • 307 - Temporary Redirect (since HTTP/1.1)
  • 308 - Permanent Redirect (Experimental RFC; RFC 7238)
See Also
REDIRECT_THRESHOLD
REDIRECT_THRESHOLDback to summary
public static final String REDIRECT_THRESHOLD

The maximal number of redirects during single handshake.

Value is expected to be positive Integer. Default value is 5.

HTTP redirection must be enabled by property REDIRECT_ENABLED, otherwise REDIRECT_THRESHOLD is not applied.

See Also
REDIRECT_ENABLED, RedirectException
RETRY_AFTER_SERVICE_UNAVAILABLEback to summary
public static final String RETRY_AFTER_SERVICE_UNAVAILABLE

HTTP Service Unavailable - Retry-After reconnect support.

Value is expected to be boolean. Default value is false.

When set to true and HTTP response code 503 - Service Unavailable is received, client will attempt to reconnect after delay specified in Retry-After header from handshake response. According to RFC 2616 the value must be decimal integer (representing delay in seconds) or http-date.

Tyrus client will try to reconnect after this delay if:

  • Retry-After header is present and is not empty
  • Retry-After header can be parsed
  • number of reconnection attempts does not exceed 5
  • delay is not longer then 300 seconds
See Also
RetryAfterException, ClientProperties#RECONNECT_HANDLER, ClientManager.ReconnectHandler, ClientManager.ReconnectHandler#onConnectFailure(Exception)
SHARED_CONTAINERback to summary
public static final String SHARED_CONTAINER

When set to true (boolean value), client runtime preserves used container and reuses it for outgoing connections.

A single thread pool is reused by all clients with this property set to true. JDK client supports only shared container option, so setting this property has no effect.

See Also
SHARED_CONTAINER_IDLE_TIMEOUT
SHARED_CONTAINER_IDLE_TIMEOUTback to summary
public static final String SHARED_CONTAINER_IDLE_TIMEOUT

Container idle timeout in seconds (Integer value).

When the timeout elapses, the shared thread pool will be destroyed.

See Also
SHARED_CONTAINER
SOCKET_BINDINGback to summary
public static final String SOCKET_BINDING

Property name for defining local binding address for all socket created by the client. The expected value is an instance of java.net.InetAddress.

Sample below demonstrates how to use this property:

    client.getProperties().put(ClientProperties.SOCKET_BINDING, InetAddress.getByName("127.0.0.1"));
SSL_ENGINE_CONFIGURATORback to summary
public static final String SSL_ENGINE_CONFIGURATOR

Property usable in ClientManager#getProperties() as a key for SSL configuration.

Value is expected to be either org.glassfish.grizzly.ssl.SSLEngineConfigurator or org.glassfish.tyrus.client.SslEngineConfigurator when configuring Grizzly client or only org.glassfish.tyrus.client.SslEngineConfigurator when configuring JDK client.

The advantage of using org.glassfish.tyrus.client.SslEngineConfigurator with Grizzly client is that org.glassfish.tyrus.client.SslEngineConfigurator allows configuration of host name verification (which is turned on by default)

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(ClientProperties.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
WORKER_THREAD_POOL_CONFIGback to summary
public static final String WORKER_THREAD_POOL_CONFIG

User property to set worker thread pool configuration.

An instance of org.glassfish.tyrus.client.ThreadPoolConfig is expected for both JDK and Grizzly client. Instance of org.glassfish.grizzly.threadpool.ThreadPoolConfig, can be used for Grizzly client.

Sample below demonstrates how to use this property:

    client.getProperties().put(ClientProperties.WORKER_THREAD_POOL_CONFIG, ThreadPoolConfig.defaultConfig());

Constructor Detail

ClientPropertiesback to summary
public ClientProperties()