Class Rest5ClientBuilder
java.lang.Object
co.elastic.clients.transport.rest5_client.low_level.Rest5ClientBuilder
Helps creating a new
Rest5Client. 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.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intstatic final intstatic final intstatic final String -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates a newRest5Clientbased on the provided configuration.static StringcleanPathPrefix(String pathPrefix) 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.setConnectionConfigCallback(Consumer<org.apache.hc.client5.http.config.ConnectionConfig.Builder> connectionConfigCallback) Allows to customize theConnectionConfigcreated by theRest5Clientand used by theCloseableHttpAsyncClient.setConnectionManagerCallback(Consumer<org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder> connectionManagerCallback) Allows to customize thePoolingAsyncClientConnectionManagercreated by theRest5Clientand used by theCloseableHttpAsyncClient.setDefaultHeaders(org.apache.hc.core5.http.Header[] defaultHeaders) Sets the default request headers, which will be sent along with each request.setFailureListener(Rest5Client.FailureListener failureListener) Sets theRest5Client.FailureListenerto be notified for each request failuresetHttpClient(org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient httpAsyncClient) Advanced setting, sets the rest client that will be used to handle requests.setHttpClientConfigCallback(Consumer<org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder> httpClientConfigCallback) Allows to customize theCloseableHttpAsyncClientbeing created and used by theRest5Client.setMetaHeaderEnabled(boolean metadataEnabled) Whether to send aX-Elastic-Client-Metaheader that describes the runtime environment.setNodeSelector(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.setProxy(org.apache.hc.core5.http.HttpHost proxy) setProxySelector(ProxySelector proxySelector) setRequestConfigCallback(Consumer<org.apache.hc.client5.http.config.RequestConfig.Builder> requestConfigCallback) Allows to customize theRequestConfigcreated by theRest5Clientand used by theCloseableHttpAsyncClient.setRoutePlanner(org.apache.hc.client5.http.routing.HttpRoutePlanner routePlanner) setSSLContext(SSLContext sslContext) Sets the SSL context, which will be applied to all requests.setStrictDeprecationMode(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_MILLIS- See Also:
-
DEFAULT_SOCKET_TIMEOUT_MILLIS
public static final int DEFAULT_SOCKET_TIMEOUT_MILLIS- See Also:
-
DEFAULT_RESPONSE_TIMEOUT_MILLIS
public static final int DEFAULT_RESPONSE_TIMEOUT_MILLIS- See Also:
-
DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_PER_ROUTE- See Also:
-
DEFAULT_MAX_CONN_TOTAL
public static final int DEFAULT_MAX_CONN_TOTAL- See Also:
-
VERSION
-
-
Method Details
-
setHttpClient
public Rest5ClientBuilder setHttpClient(org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient httpAsyncClient) Advanced setting, sets the rest client that will be used to handle requests. The rest client has to be fully configured, as it will be used as provided, also this will overwrite all builder setters.- Throws:
NullPointerException- ifhttpAsyncClientisnull.
-
setSSLContext
Sets the SSL context, which will be applied to all requests.- Throws:
NullPointerException- ifhttpAsyncClientisnull.
-
setProxy
-
setProxySelector
-
setRoutePlanner
public Rest5ClientBuilder setRoutePlanner(org.apache.hc.client5.http.routing.HttpRoutePlanner routePlanner) -
setDefaultHeaders
Sets the default request headers, which will be sent along with each request.Request-time headers will always overwrite any default headers.
- Throws:
NullPointerException- ifdefaultHeadersor any header isnull.
-
setFailureListener
Sets theRest5Client.FailureListenerto be notified for each request failure- Throws:
NullPointerException- iffailureListenerisnull.
-
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 Elasticsearch 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:
NullPointerException- ifpathPrefixisnull.IllegalArgumentException- ifpathPrefixis empty, or ends with more than one '/'.
-
cleanPathPrefix
-
setNodeSelector
Sets theNodeSelectorto be used for all requests.- 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. -
setCompressionEnabled
Whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip" header to receive compressed responses. -
setMetaHeaderEnabled
Whether to send aX-Elastic-Client-Metaheader that describes the runtime environment. It contains information that is similar to what could be found inUser-Agent. Using a separate header allows applications to useUser-Agentfor their own needs, e.g. to identify application version or other environment information. Defaults totrue. -
setHttpClientConfigCallback
public Rest5ClientBuilder setHttpClientConfigCallback(Consumer<org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder> httpClientConfigCallback) Allows to customize theCloseableHttpAsyncClientbeing created and used by theRest5Client. Commonly used to customizeHttpAsyncClientBuilderwithout losing any other useful default value that theRest5ClientBuilderinternally sets.- Throws:
NullPointerException- ifhttpClientConfigCallbackisnull.
-
setRequestConfigCallback
public Rest5ClientBuilder setRequestConfigCallback(Consumer<org.apache.hc.client5.http.config.RequestConfig.Builder> requestConfigCallback) Allows to customize theRequestConfigcreated by theRest5Clientand used by theCloseableHttpAsyncClient. Commonly used to customizeRequestConfigwithout losing any other useful default value that theRest5ClientBuilderinternally sets.- Throws:
NullPointerException- ifrequestConfigCallbackisnull.
-
setConnectionConfigCallback
public Rest5ClientBuilder setConnectionConfigCallback(Consumer<org.apache.hc.client5.http.config.ConnectionConfig.Builder> connectionConfigCallback) Allows to customize theConnectionConfigcreated by theRest5Clientand used by theCloseableHttpAsyncClient. Commonly used to customizeConnectionConfigwithout losing any other useful default value that theRest5ClientBuilderinternally sets.- Throws:
NullPointerException- ifconnectionConfigCallbackisnull.
-
setConnectionManagerCallback
public Rest5ClientBuilder setConnectionManagerCallback(Consumer<org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder> connectionManagerCallback) Allows to customize thePoolingAsyncClientConnectionManagercreated by theRest5Clientand used by theCloseableHttpAsyncClient. Commonly used to customizePoolingAsyncClientConnectionManagerwithout losing any other useful default value that theRest5ClientBuilderinternally sets.- Throws:
NullPointerException- ifconnectionManagerCallbackisnull.
-
build
Creates a newRest5Clientbased on the provided configuration.
-