Package org.opensearch.client
Class RestClientBuilder
java.lang.Object
org.opensearch.client.RestClientBuilder
Helps creating a new
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.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback used to customize theCloseableHttpClientinstance used by aRestClientinstance.static interfaceCallback used the defaultRequestConfigbeing set to theCloseableHttpClient -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default connection timout in milliseconds.static final intThe default maximum of connections per route.static final intThe default maximum total connections.static final intThe default socket timeout in milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates a newRestClientbased on the provided configuration.static StringcleanPathPrefix(String pathPrefix) Cleans up the given path prefix to ensure that looks like "/base/path".setChunkedEnabled(boolean chunkedEnabled) Whether the REST client should use Transfer-Encoding: chunked for requests or not"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.setDefaultHeaders(org.apache.http.Header[] defaultHeaders) Sets the default request headers, which will be sent along with each request.setFailureListener(RestClient.FailureListener failureListener) Sets theRestClient.FailureListenerto be notified for each request failuresetHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theRestClientBuilder.HttpClientConfigCallbackto be used to customize http client configurationsetNodeSelector(NodeSelector nodeSelector) Sets theNodeSelectorto be used for all requests.setPathPrefix(String pathPrefix) Sets the path's prefix for every request used by the http client.setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback) Sets theRestClientBuilder.RequestConfigCallbackto be used to customize http client configurationsetStrictDeprecationMode(boolean strictDeprecationMode) Whether the REST client should return any response containing at least one warning header as a failure.
-
Field Details
-
DEFAULT_CONNECT_TIMEOUT_MILLIS
public static final int DEFAULT_CONNECT_TIMEOUT_MILLISThe default connection timout in milliseconds.- See Also:
-
DEFAULT_SOCKET_TIMEOUT_MILLIS
public static final int DEFAULT_SOCKET_TIMEOUT_MILLISThe default socket timeout in milliseconds.- See Also:
-
DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_PER_ROUTEThe default maximum of connections per route.- See Also:
-
DEFAULT_MAX_CONN_TOTAL
public static final int DEFAULT_MAX_CONN_TOTALThe default maximum total connections.- See Also:
-
-
Method Details
-
setDefaultHeaders
Sets the default request headers, which will be sent along with each request.Request-time headers will always overwrite any default headers.
- Parameters:
defaultHeaders- array of default header- Throws:
NullPointerException- ifdefaultHeadersor any header isnull.
-
setFailureListener
Sets theRestClient.FailureListenerto be notified for each request failure- Parameters:
failureListener- theRestClient.FailureListenerfor each failure- Throws:
NullPointerException- iffailureListenerisnull.
-
setHttpClientConfigCallback
public RestClientBuilder setHttpClientConfigCallback(RestClientBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theRestClientBuilder.HttpClientConfigCallbackto be used to customize http client configuration- Parameters:
httpClientConfigCallback- theRestClientBuilder.HttpClientConfigCallbackto be used- Throws:
NullPointerException- ifhttpClientConfigCallbackisnull.
-
setRequestConfigCallback
public RestClientBuilder setRequestConfigCallback(RestClientBuilder.RequestConfigCallback requestConfigCallback) Sets theRestClientBuilder.RequestConfigCallbackto be used to customize http client configuration- Parameters:
requestConfigCallback- theRestClientBuilder.RequestConfigCallbackto be used- Throws:
NullPointerException- ifrequestConfigCallbackisnull.
-
setPathPrefix
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
endpointis 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.- Parameters:
pathPrefix- the path prefix for every request.- Throws:
NullPointerException- ifpathPrefixisnull.IllegalArgumentException- ifpathPrefixis empty, or ends with more than one '/'.
-
cleanPathPrefix
Cleans up the given path prefix to ensure that looks like "/base/path".- Parameters:
pathPrefix- the path prefix to be cleaned up.- Returns:
- the cleaned up path prefix.
- Throws:
NullPointerException- ifpathPrefixisnull.IllegalArgumentException- ifpathPrefixis empty, or ends with more than one '/'.
-
setNodeSelector
Sets theNodeSelectorto be used for all requests.- Parameters:
nodeSelector- theNodeSelectorto be used- Throws:
NullPointerException- if the provided nodeSelector is null
-
setStrictDeprecationMode
Whether the REST client should return any response containing at least one warning header as a failure.- Parameters:
strictDeprecationMode- flag for enabling strict deprecation mode
-
setCompressionEnabled
Whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip" header to receive compressed responses.- Parameters:
compressionEnabled- flag for enabling compression
-
setChunkedEnabled
Whether the REST client should use Transfer-Encoding: chunked for requests or not"- Parameters:
chunkedEnabled- force enable/disable chunked transfer-encoding.
-
build
Creates a newRestClientbased on the provided configuration.
-