Package org.opensearch.client
Class RestClientBuilder
- java.lang.Object
-
- org.opensearch.client.RestClientBuilder
-
public final class RestClientBuilder extends java.lang.Object
Helps creating a newRestClient
. Allows to set the most common http client configuration options when internally creating the underlyingHttpAsyncClient
. Also allows to provide an externally createdHttpAsyncClient
in case additional customization is needed.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
RestClientBuilder.HttpClientConfigCallback
Callback used to customize theCloseableHttpClient
instance used by aRestClient
instance.static interface
RestClientBuilder.RequestConfigCallback
Callback used the defaultRequestConfig
being set to theCloseableHttpClient
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_CONNECT_TIMEOUT_MILLIS
static int
DEFAULT_MAX_CONN_PER_ROUTE
static int
DEFAULT_MAX_CONN_TOTAL
static int
DEFAULT_SOCKET_TIMEOUT_MILLIS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description RestClient
build()
Creates a newRestClient
based on the provided configuration.static java.lang.String
cleanPathPrefix(java.lang.String pathPrefix)
RestClientBuilder
setCompressionEnabled(boolean compressionEnabled)
Whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip" header to receive compressed responses.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 theRestClient.FailureListener
to be notified for each request failureRestClientBuilder
setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback)
Sets theRestClientBuilder.HttpClientConfigCallback
to be used to customize http client configurationRestClientBuilder
setNodeSelector(NodeSelector nodeSelector)
Sets theNodeSelector
to be used for all requests.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 theRestClientBuilder.RequestConfigCallback
to be used to customize http client configurationRestClientBuilder
setStrictDeprecationMode(boolean strictDeprecationMode)
Whether the REST client should return any response containing at least one warning header as a failure.
-
-
-
Field Detail
-
DEFAULT_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_CONNECT_TIMEOUT_MILLIS
- See Also:
- Constant Field Values
-
DEFAULT_SOCKET_TIMEOUT_MILLIS
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS
- See Also:
- Constant Field Values
-
DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_PER_ROUTE
- See Also:
- Constant Field Values
-
DEFAULT_MAX_CONN_TOTAL
public static final int DEFAULT_MAX_CONN_TOTAL
- See Also:
- Constant Field Values
-
-
Method Detail
-
setDefaultHeaders
public RestClientBuilder setDefaultHeaders(org.apache.http.Header[] defaultHeaders)
Sets the default request headers, which will be sent along with each request.Request-time headers will always overwrite any default headers.
- Throws:
java.lang.NullPointerException
- ifdefaultHeaders
or any header isnull
.
-
setFailureListener
public RestClientBuilder setFailureListener(RestClient.FailureListener failureListener)
Sets theRestClient.FailureListener
to be notified for each request failure- Throws:
java.lang.NullPointerException
- iffailureListener
isnull
.
-
setHttpClientConfigCallback
public RestClientBuilder setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback)
Sets theRestClientBuilder.HttpClientConfigCallback
to be used to customize http client configuration- Throws:
java.lang.NullPointerException
- ifhttpClientConfigCallback
isnull
.
-
setRequestConfigCallback
public RestClientBuilder setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback)
Sets theRestClientBuilder.RequestConfigCallback
to be used to customize http client configuration- Throws:
java.lang.NullPointerException
- ifrequestConfigCallback
isnull
.
-
setPathPrefix
public RestClientBuilder setPathPrefix(java.lang.String pathPrefix)
Sets the path's prefix for every request used by the http client.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 thispathPrefix
. The path prefix is useful for when OpenSearch is behind a proxy that provides a base path or a proxy that requires all paths to start with '/'; it is not intended for other purposes and it should not be supplied in other scenarios.- Throws:
java.lang.NullPointerException
- ifpathPrefix
isnull
.java.lang.IllegalArgumentException
- ifpathPrefix
is empty, or ends with more than one '/'.
-
cleanPathPrefix
public static java.lang.String cleanPathPrefix(java.lang.String pathPrefix)
-
setNodeSelector
public RestClientBuilder setNodeSelector(NodeSelector nodeSelector)
Sets theNodeSelector
to be used for all requests.- Throws:
java.lang.NullPointerException
- if the provided nodeSelector is null
-
setStrictDeprecationMode
public RestClientBuilder setStrictDeprecationMode(boolean strictDeprecationMode)
Whether the REST client should return any response containing at least one warning header as a failure.
-
setCompressionEnabled
public RestClientBuilder setCompressionEnabled(boolean compressionEnabled)
Whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip" header to receive compressed responses.
-
build
public RestClient build()
Creates a newRestClient
based on the provided configuration.
-
-