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 |
setMaxResponseSize(int maxResponseSize)
Set the maximum allowed size of the content of the response that the
client can consume in bytes.
|
HttpConfiguration.Builder |
setProtocol(HttpConfiguration.Protocol protocol)
Sets the vAPI Protocol that is used by client to
invoke APIs on the server.
|
HttpConfiguration.Builder |
setProxyConfiguration(HttpConfiguration.ProxyConfiguration proxyConfiguration)
Sets the proxy configuration object used to configure proxy settings on the client.
|
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.
Note that the special instance HttpConfiguration.SslConfiguration.SKIP_SSL_INITIALIZATION
may be used to completely disable the TLS/SSL initialization.
If the system property org.bouncycastle.fips.approved_only is set to true (case insensitive) the TLS/SSL stack will not be initialized, even if different configuration is provide here.
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 setMaxResponseSize(int maxResponseSize)
TransportProtocolException
at runtime.
The method guarantees that at least this size will be allowed. However, the effective maximum size will be the lowest number which is a power of two and is bigger than or equal to the number that is set. That is, effective limit L = min(2^N), where L >= maxResponseSize.
As an example, setting 2000
bytes will produce an effective
limit of 2^11
which is 2048
bytes. Setting
4096
which is 2^12, will not lead to changes and the
effective limit will stay 4096
bytes
HttpConfiguration#getMaxResponseSize()}
for the
effective limit set
When the response content type is
HttpConstants.CONTENT_TYPE_STREAM_JSON
or
HttpConstants.CONTENT_TYPE_FRAMED
maxResponseSize
designates the maximum size of a single frame
Default value is bytes
maxResponseSize
- The maximum allowed size of the response
content in bytes.public 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.Builder setProxyConfiguration(HttpConfiguration.ProxyConfiguration proxyConfiguration)
proxyConfiguration
- is the ProxyConfiguration instance.public HttpConfiguration getConfig()
HttpConfiguration
java.lang.IllegalStateException
- if the combination of settings is not supported