Class ApacheHttpClient5TransportBuilder
- java.lang.Object
-
- org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder
-
public class ApacheHttpClient5TransportBuilder extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceApacheHttpClient5TransportBuilder.HttpClientConfigCallbackCallback used to customize theCloseableHttpClientinstance used by aRestClientinstance.static interfaceApacheHttpClient5TransportBuilder.RequestConfigCallbackCallback used the defaultRequestConfigbeing set to theCloseableHttpClient
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONNECT_TIMEOUT_MILLISThe default connection timeout in milliseconds.static intDEFAULT_MAX_CONN_PER_ROUTEThe default maximum of connections per route.static intDEFAULT_MAX_CONN_TOTALThe default maximum total connections.static intDEFAULT_RESPONSE_TIMEOUT_MILLISThe default response timeout in milliseconds.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ApacheHttpClient5Transportbuild()Creates a newRestClientbased on the provided configuration.static ApacheHttpClient5TransportBuilderbuilder(org.apache.hc.core5.http.HttpHost... hosts)Returns a newApacheHttpClient5TransportBuilderto help withApacheHttpClient5Transportcreation.static ApacheHttpClient5TransportBuilderbuilder(Node... nodes)Returns a newApacheHttpClient5TransportBuilderto help withApacheHttpClient5Transportcreation.static java.lang.StringcleanPathPrefix(java.lang.String pathPrefix)Cleans up the given path prefix to ensure that looks like "/base/path".ApacheHttpClient5TransportBuildersetChunkedEnabled(boolean chunkedEnabled)Whether the REST client should use Transfer-Encoding: chunked for requests or not"ApacheHttpClient5TransportBuildersetCompressionEnabled(boolean compressionEnabled)Whether the REST client should compress requests using gzip content encoding and add the "Accept-Encoding: gzip" header to receive compressed responses.ApacheHttpClient5TransportBuildersetDefaultHeaders(org.apache.hc.core5.http.Header[] defaultHeaders)Sets the default request headers, which will be sent along with each request.ApacheHttpClient5TransportBuildersetFailureListener(ApacheHttpClient5Transport.FailureListener failureListener)Sets theRestClient.FailureListenerto be notified for each request failureApacheHttpClient5TransportBuildersetHttpClientConfigCallback(ApacheHttpClient5TransportBuilder.HttpClientConfigCallback httpClientConfigCallback)Sets theApacheHttpClient5TransportBuilder.HttpClientConfigCallbackto be used to customize http client configurationApacheHttpClient5TransportBuildersetMapper(JsonpMapper mapper)Sets theJsonpMapperinstance to be used for parsing JSON payloads.ApacheHttpClient5TransportBuildersetNodeSelector(NodeSelector nodeSelector)Sets theNodeSelectorto be used for all requests.ApacheHttpClient5TransportBuildersetOptions(TransportOptions options)Sets the defaultTransportOptionsto be used by the clientApacheHttpClient5TransportBuildersetPathPrefix(java.lang.String pathPrefix)Sets the path's prefix for every request used by the http client.ApacheHttpClient5TransportBuildersetRequestConfigCallback(ApacheHttpClient5TransportBuilder.RequestConfigCallback requestConfigCallback)Sets theApacheHttpClient5TransportBuilder.RequestConfigCallbackto be used to customize http client configurationApacheHttpClient5TransportBuildersetStrictDeprecationMode(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
The default connection timeout in milliseconds.- See Also:
- Constant Field Values
-
DEFAULT_RESPONSE_TIMEOUT_MILLIS
public static final int DEFAULT_RESPONSE_TIMEOUT_MILLIS
The default response timeout in milliseconds.- See Also:
- Constant Field Values
-
DEFAULT_MAX_CONN_PER_ROUTE
public static final int DEFAULT_MAX_CONN_PER_ROUTE
The default maximum of connections per route.- See Also:
- Constant Field Values
-
DEFAULT_MAX_CONN_TOTAL
public static final int DEFAULT_MAX_CONN_TOTAL
The default maximum total connections.- See Also:
- Constant Field Values
-
-
Method Detail
-
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:
java.lang.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:
java.lang.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:
java.lang.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:
java.lang.NullPointerException- ifrequestConfigCallbackisnull.
-
setPathPrefix
public ApacheHttpClient5TransportBuilder 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
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:
java.lang.NullPointerException- ifpathPrefixisnull.java.lang.IllegalArgumentException- ifpathPrefixis empty, or ends with more than one '/'.
-
setMapper
public ApacheHttpClient5TransportBuilder setMapper(JsonpMapper mapper)
Sets theJsonpMapperinstance to be used for parsing JSON payloads. If not provided theJacksonJsonpMapperis going to be used.- Parameters:
mapper- theJsonpMapperinstance
-
setOptions
public ApacheHttpClient5TransportBuilder setOptions(TransportOptions options)
Sets the defaultTransportOptionsto be used by the client- Parameters:
options- defaultTransportOptions
-
cleanPathPrefix
public static java.lang.String cleanPathPrefix(java.lang.String pathPrefix)
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:
java.lang.NullPointerException- ifpathPrefixisnull.java.lang.IllegalArgumentException- ifpathPrefixis empty, or ends with more than one '/'.
-
setNodeSelector
public ApacheHttpClient5TransportBuilder setNodeSelector(NodeSelector nodeSelector)
Sets theNodeSelectorto be used for all requests.- Parameters:
nodeSelector- theNodeSelectorto be used- Throws:
java.lang.NullPointerException- if the provided nodeSelector is null
-
setStrictDeprecationMode
public ApacheHttpClient5TransportBuilder setStrictDeprecationMode(boolean strictDeprecationMode)
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
public ApacheHttpClient5TransportBuilder 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.- Parameters:
compressionEnabled- flag for enabling compression
-
setChunkedEnabled
public ApacheHttpClient5TransportBuilder setChunkedEnabled(boolean chunkedEnabled)
Whether the REST client should use Transfer-Encoding: chunked for requests or not"- Parameters:
chunkedEnabled- force enable/disable chunked transfer-encoding.
-
build
public ApacheHttpClient5Transport build()
Creates a newRestClientbased on the provided configuration.
-
builder
public static ApacheHttpClient5TransportBuilder builder(Node... nodes)
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
public static ApacheHttpClient5TransportBuilder builder(org.apache.hc.core5.http.HttpHost... hosts)
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:
Node(HttpHost)
-
-