Class Rest5ClientBuilder

java.lang.Object
co.elastic.clients.transport.rest5_client.low_level.Rest5ClientBuilder

public final class Rest5ClientBuilder extends Object
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 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

      public static final String 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 - if httpAsyncClient is null.
    • setSSLContext

      public Rest5ClientBuilder setSSLContext(SSLContext sslContext)
      Sets the SSL context, which will be applied to all requests.
      Throws:
      NullPointerException - if httpAsyncClient is null.
    • setProxy

      public Rest5ClientBuilder setProxy(org.apache.hc.core5.http.HttpHost proxy)
    • setProxySelector

      public Rest5ClientBuilder setProxySelector(ProxySelector proxySelector)
    • setRoutePlanner

      public Rest5ClientBuilder setRoutePlanner(org.apache.hc.client5.http.routing.HttpRoutePlanner routePlanner)
    • setDefaultHeaders

      public Rest5ClientBuilder setDefaultHeaders(org.apache.hc.core5.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:
      NullPointerException - if defaultHeaders or any header is null.
    • setFailureListener

      public Rest5ClientBuilder setFailureListener(Rest5Client.FailureListener failureListener)
      Sets the Rest5Client.FailureListener to be notified for each request failure
      Throws:
      NullPointerException - if failureListener is null.
    • setPathPrefix

      public Rest5ClientBuilder setPathPrefix(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 this pathPrefix. 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 - if pathPrefix is null.
      IllegalArgumentException - if pathPrefix is empty, or ends with more than one '/'.
    • cleanPathPrefix

      public static String cleanPathPrefix(String pathPrefix)
    • setNodeSelector

      public Rest5ClientBuilder setNodeSelector(NodeSelector nodeSelector)
      Sets the NodeSelector to be used for all requests.
      Throws:
      NullPointerException - if the provided nodeSelector is null
    • setStrictDeprecationMode

      public Rest5ClientBuilder setStrictDeprecationMode(boolean strictDeprecationMode)
      Whether the REST client should return any response containing at least one warning header as a failure.
    • setCompressionEnabled

      public Rest5ClientBuilder 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.
    • setMetaHeaderEnabled

      public Rest5ClientBuilder setMetaHeaderEnabled(boolean metadataEnabled)
      Whether to send a X-Elastic-Client-Meta header that describes the runtime environment. It contains information that is similar to what could be found in User-Agent. Using a separate header allows applications to use User-Agent for their own needs, e.g. to identify application version or other environment information. Defaults to true.
    • setHttpClientConfigCallback

      public Rest5ClientBuilder setHttpClientConfigCallback(Consumer<org.apache.hc.client5.http.impl.async.HttpAsyncClientBuilder> httpClientConfigCallback)
      Allows to customize the CloseableHttpAsyncClient being created and used by the Rest5Client. Commonly used to customize HttpAsyncClientBuilder without losing any other useful default value that the Rest5ClientBuilder internally sets.
      Throws:
      NullPointerException - if httpClientConfigCallback is null.
    • setRequestConfigCallback

      public Rest5ClientBuilder setRequestConfigCallback(Consumer<org.apache.hc.client5.http.config.RequestConfig.Builder> requestConfigCallback)
      Allows to customize the RequestConfig created by the Rest5Client and used by the CloseableHttpAsyncClient. Commonly used to customize RequestConfig without losing any other useful default value that the Rest5ClientBuilder internally sets.
      Throws:
      NullPointerException - if requestConfigCallback is null.
    • setConnectionConfigCallback

      public Rest5ClientBuilder setConnectionConfigCallback(Consumer<org.apache.hc.client5.http.config.ConnectionConfig.Builder> connectionConfigCallback)
      Allows to customize the ConnectionConfig created by the Rest5Client and used by the CloseableHttpAsyncClient. Commonly used to customize ConnectionConfig without losing any other useful default value that the Rest5ClientBuilder internally sets.
      Throws:
      NullPointerException - if connectionConfigCallback is null.
    • setConnectionManagerCallback

      public Rest5ClientBuilder setConnectionManagerCallback(Consumer<org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder> connectionManagerCallback)
      Allows to customize the PoolingAsyncClientConnectionManager created by the Rest5Client and used by the CloseableHttpAsyncClient. Commonly used to customize PoolingAsyncClientConnectionManager without losing any other useful default value that the Rest5ClientBuilder internally sets.
      Throws:
      NullPointerException - if connectionManagerCallback is null.
    • build

      public Rest5Client build()
      Creates a new Rest5Client based on the provided configuration.