Class ApacheHttpClient5TransportBuilder
java.lang.Object
org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback used the defaultConnectionConfigbeing set to theCloseableHttpClient.static 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 timeout in milliseconds.static final intThe default maximum of connections per route.static final intThe default maximum total connections.static final intThe default response timeout in milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Creates a newRestClientbased on the provided configuration.builder(org.apache.hc.core5.http.HttpHost... hosts) Returns a newApacheHttpClient5TransportBuilderto help withApacheHttpClient5Transportcreation.Returns a newApacheHttpClient5TransportBuilderto help withApacheHttpClient5Transportcreation.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.setConnectionConfigCallback(ApacheHttpClient5TransportBuilder.ConnectionConfigCallback connectionConfigCallback) Sets theApacheHttpClient5TransportBuilder.ConnectionConfigCallbackto be used to customize http client configurationsetDefaultHeaders(org.apache.hc.core5.http.Header[] defaultHeaders) Sets the default request headers, which will be sent along with each request.setFailureListener(ApacheHttpClient5Transport.FailureListener failureListener) Sets theRestClient.FailureListenerto be notified for each request failuresetHttpClientConfigCallback(ApacheHttpClient5TransportBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theApacheHttpClient5TransportBuilder.HttpClientConfigCallbackto be used to customize http client configurationsetMapper(JsonpMapper mapper) Sets theJsonpMapperinstance to be used for parsing JSON payloads.setNodeSelector(NodeSelector nodeSelector) Sets theNodeSelectorto be used for all requests.setOptions(TransportOptions options) Sets the defaultTransportOptionsto be used by the clientsetPathPrefix(String pathPrefix) Sets the path's prefix for every request used by the http client.setRequestConfigCallback(ApacheHttpClient5TransportBuilder.RequestConfigCallback requestConfigCallback) Sets theApacheHttpClient5TransportBuilder.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 timeout in milliseconds.- See Also:
-
DEFAULT_RESPONSE_TIMEOUT_MILLIS
public static final int DEFAULT_RESPONSE_TIMEOUT_MILLISThe default response 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
public ApacheHttpClient5TransportBuilder 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.
- Parameters:
defaultHeaders- array of default header- Throws:
NullPointerException- ifdefaultHeadersor any header isnull.
-
setFailureListener
public ApacheHttpClient5TransportBuilder setFailureListener(ApacheHttpClient5Transport.FailureListener failureListener) Sets theRestClient.FailureListenerto be notified for each request failure- Parameters:
failureListener- theRestClient.FailureListenerfor each failure- Throws:
NullPointerException- iffailureListenerisnull.
-
setHttpClientConfigCallback
public ApacheHttpClient5TransportBuilder setHttpClientConfigCallback(ApacheHttpClient5TransportBuilder.HttpClientConfigCallback httpClientConfigCallback) Sets theApacheHttpClient5TransportBuilder.HttpClientConfigCallbackto be used to customize http client configuration- Parameters:
httpClientConfigCallback- theApacheHttpClient5TransportBuilder.HttpClientConfigCallbackto be used- Throws:
NullPointerException- ifhttpClientConfigCallbackisnull.
-
setRequestConfigCallback
public ApacheHttpClient5TransportBuilder setRequestConfigCallback(ApacheHttpClient5TransportBuilder.RequestConfigCallback requestConfigCallback) Sets theApacheHttpClient5TransportBuilder.RequestConfigCallbackto be used to customize http client configuration- Parameters:
requestConfigCallback- theApacheHttpClient5TransportBuilder.RequestConfigCallbackto be used- Throws:
NullPointerException- ifrequestConfigCallbackisnull.
-
setConnectionConfigCallback
public ApacheHttpClient5TransportBuilder setConnectionConfigCallback(ApacheHttpClient5TransportBuilder.ConnectionConfigCallback connectionConfigCallback) Sets theApacheHttpClient5TransportBuilder.ConnectionConfigCallbackto be used to customize http client configuration- Parameters:
connectionConfigCallback- theApacheHttpClient5TransportBuilder.ConnectionConfigCallbackto be used- Throws:
NullPointerException- ifconnectionConfigCallbackisnull.
-
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 '/'.
-
setMapper
Sets theJsonpMapperinstance to be used for parsing JSON payloads. If not provided theJacksonJsonpMapperis going to be used.- Parameters:
mapper- theJsonpMapperinstance
-
setOptions
Sets the defaultTransportOptionsto be used by the client- Parameters:
options- defaultTransportOptions
-
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. -
builder
Returns a newApacheHttpClient5TransportBuilderto help withApacheHttpClient5Transportcreation. Creates a new builder instance and sets the hosts that the client will send requests to.Prefer this to
builder(HttpHost...)if you have metadata up front about the nodes. If you don't either one is fine.- Parameters:
nodes- The nodes that the client will send requests to.
-
builder
Returns a newApacheHttpClient5TransportBuilderto help withApacheHttpClient5Transportcreation. Creates a new builder instance and sets the nodes that the client will send requests to.You can use this if you do not have metadata up front about the nodes. If you do, prefer
builder(Node...).- Parameters:
hosts- The hosts that the client will send requests to.- See Also:
-