public final class RestClientBuilder
extends java.lang.Object
RestClient
. Allows to set the most common http client configuration options when internally
creating the underlying HttpAsyncClient
. Also allows to provide an externally created
HttpAsyncClient
in case additional customization is needed.Modifier and Type | Class and Description |
---|---|
static interface |
RestClientBuilder.HttpClientConfigCallback
Callback used to customize the
CloseableHttpClient instance used by a RestClient instance. |
static interface |
RestClientBuilder.RequestConfigCallback
Callback used the default
RequestConfig being set to the CloseableHttpClient |
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CONNECT_TIMEOUT_MILLIS |
static int |
DEFAULT_CONNECTION_REQUEST_TIMEOUT_MILLIS |
static int |
DEFAULT_MAX_CONN_PER_ROUTE |
static int |
DEFAULT_MAX_CONN_TOTAL |
static int |
DEFAULT_MAX_RETRY_TIMEOUT_MILLIS |
static int |
DEFAULT_SOCKET_TIMEOUT_MILLIS |
Modifier and Type | Method and Description |
---|---|
RestClient |
build()
Creates a new
RestClient based on the provided configuration. |
RestClientBuilder |
setDefaultHeaders(org.apache.http.Header[] defaultHeaders)
Sets the default request headers, which will be sent along with each request.
|
RestClientBuilder |
setFailureListener(RestClient.FailureListener failureListener)
Sets the
RestClient.FailureListener to be notified for each request failure |
RestClientBuilder |
setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback)
Sets the
RestClientBuilder.HttpClientConfigCallback to be used to customize http client configuration |
RestClientBuilder |
setMaxRetryTimeoutMillis(int maxRetryTimeoutMillis)
Sets the maximum timeout (in milliseconds) to honour in case of multiple retries of the same request.
|
RestClientBuilder |
setPathPrefix(java.lang.String pathPrefix)
Sets the path's prefix for every request used by the http client.
|
RestClientBuilder |
setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback)
Sets the
RestClientBuilder.RequestConfigCallback to be used to customize http client configuration |
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS
public static final int DEFAULT_MAX_RETRY_TIMEOUT_MILLIS
public static final int DEFAULT_CONNECTION_REQUEST_TIMEOUT_MILLIS
public static final int DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_TOTAL
public RestClientBuilder setDefaultHeaders(org.apache.http.Header[] defaultHeaders)
Request-time headers will always overwrite any default headers.
java.lang.NullPointerException
- if defaultHeaders
or any header is null
.public RestClientBuilder setFailureListener(RestClient.FailureListener failureListener)
RestClient.FailureListener
to be notified for each request failurejava.lang.NullPointerException
- if failureListener
is null
.public RestClientBuilder setMaxRetryTimeoutMillis(int maxRetryTimeoutMillis)
DEFAULT_MAX_RETRY_TIMEOUT_MILLIS
if not specified.java.lang.IllegalArgumentException
- if maxRetryTimeoutMillis
is not greater than 0public RestClientBuilder setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback)
RestClientBuilder.HttpClientConfigCallback
to be used to customize http client configurationjava.lang.NullPointerException
- if httpClientConfigCallback
is null
.public RestClientBuilder setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback)
RestClientBuilder.RequestConfigCallback
to be used to customize http client configurationjava.lang.NullPointerException
- if requestConfigCallback
is null
.public RestClientBuilder setPathPrefix(java.lang.String pathPrefix)
For example, if this is set to "/my/path", then any client request will become "/my/path/" + endpoint
.
In essence, every request's endpoint
is prefixed by this pathPrefix
. The path prefix is useful for when
Elasticsearch is behind a proxy that provides a base path; it is not intended for other purposes and it should not be supplied in
other scenarios.
java.lang.NullPointerException
- if pathPrefix
is null
.java.lang.IllegalArgumentException
- if pathPrefix
is empty, only '/', or ends with more than one '/'.public RestClient build()
RestClient
based on the provided configuration.