public static final class HttpConfiguration.Builder
extends java.lang.Object
HttpConfiguration
.Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
HttpConfiguration |
getConfig()
Creates a configuration with all the settings set to this
builder instance.
|
HttpConfiguration.Builder |
setConnectTimeout(int connectTimeout)
Sets the amount of time the client is going to wait for establishing
a connection with the target API endpoint.
|
HttpConfiguration.Builder |
setHeadersProvider(HttpConfiguration.HeadersProvider headersProvider)
Sets a callback instance that gets invoked upon each request.
|
HttpConfiguration.Builder |
setIoThreadCount(int ioThreadCount)
Defines the number of I/O dispatch threads to be used by the I/O
reactor of the third-party HTTP library.
|
HttpConfiguration.Builder |
setKeepAlivePeriod(long keepAlivePeriod)
Sets the maximum time a connection is allowed to be kept alive.
|
HttpConfiguration.Builder |
setLibraryType(HttpConfiguration.LibType libraryType)
Sets the type of the HTTP library to be used for execution of
API requests.
|
HttpConfiguration.Builder |
setMaxConnections(int maxConnections)
Sets the maximum number of outstanding TCP connections.
|
HttpConfiguration.Builder |
setProtocol(HttpConfiguration.Protocol protocol)
Sets the vAPI Protocol that is used by client to
invoke APIs on the server.
|
HttpConfiguration.Builder |
setSoTimeout(int soTimeout)
Sets the amount of time (in milliseconds) the client is going to wait
for a response before timing out.
|
HttpConfiguration.Builder |
setSslConfiguration(HttpConfiguration.SslConfiguration sslConfig)
Sets the SSL configuration for executing request over HTTPs, including
trust store for validating server certificate, and optionally key store
for presenting client certificate (SSl mutual authentication).
|
public HttpConfiguration.Builder setLibraryType(HttpConfiguration.LibType libraryType)
Default value is HttpConfiguration.LibType.APACHE_HTTP_CLIENT
.
libraryType
- HTTP library flavor; must not be null
public HttpConfiguration.Builder setSslConfiguration(HttpConfiguration.SslConfiguration sslConfig)
This is not required, but if not set, the client will use the default trust-store of the JRE to connect to API endpoints over HTTPs.
sslConfig
- SSL related settingspublic HttpConfiguration.Builder setIoThreadCount(int ioThreadCount)
HttpConfiguration.LibType.APACHE_HTTP_ASYNC_CLIENT
.
Defaults to the number of the processors on the machine.
ioThreadCount
- number of I/O threads; must be positivepublic HttpConfiguration.Builder setConnectTimeout(int connectTimeout)
Value of 0 means never timeout (wait forever). Negative values are not allowed.
The default value is 15 000 ms (15 seconds).
connectTimeout
- time in milliseconds; must not be negativepublic HttpConfiguration.Builder setSoTimeout(int soTimeout)
SO_TIMEOUT
which impact the Socket.read()
method.
Value of 0 means never time out (wait forever). Negative values are not allowed.
The default value is 0 (never time out).
soTimeout
- time in milliseconds; must not be negativepublic HttpConfiguration.Builder setMaxConnections(int maxConnections)
Default value is 20 connections.
Clients which execute large number of simultaneous API requests need to consider increasing this value to avoid starvation for connections. It is inherent for the HTTP protocol to occupy a TCP connection for the whole timespan of a request/response execution (even if non-blocking I/O is used).
maxConnections
- maximum number of connections; must be positivepublic HttpConfiguration.Builder setKeepAlivePeriod(long keepAlivePeriod)
Non-positive value for this setting means that the connection can be kept alive indefinitely.
It is highly recommended that a value lower than max idle timeout on the server is used. Otherwise a race is possible between client reusing a kept-alive connection for subsequent request and server closing the same connection due to inactivity. In such cases the client request might fail with network error (connection already closed).
Default value is 45 000 ms (45 seconds).
keepAlivePeriod
- the time period in milliseconds.public HttpConfiguration.Builder setHeadersProvider(HttpConfiguration.HeadersProvider headersProvider)
The callback is expected to provide a list of
headers
to be added to the request.
Exceptions
thrown from
the callback or from the methods of each HttpConfiguration.Header
will
propagate and cause the invocation to fail.
Headers reserved
for the
runtime, that are being returned by the callback, will be skipped.
headersProvider
- the callback instancepublic HttpConfiguration.Builder setProtocol(HttpConfiguration.Protocol protocol)
Default value is HttpConfiguration.Protocol.VAPI_JSON_RPC_1_0
.
protocol
- vAPI Protocol; must not be null
.public HttpConfiguration getConfig()
HttpConfiguration
java.lang.IllegalStateException
- if the combination of settings is not supported