Module org.elasticsearch.xcore
Class CommandLineHttpClient
java.lang.Object
org.elasticsearch.xpack.core.security.CommandLineHttpClient
A simple http client for usage in command line tools. This client only uses internal jdk classes and does
not rely on an external http libraries.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringapiKeyHeaderValue(SecureString apiKey) voidcheckClusterHealthWithRetriesWaitingForCluster(String username, SecureString password, int retries) If cluster is not up yet (connection refused or master is unavailable), we will retry @retries number of times If status is 'Red', we will wait for 'Yellow' for 30s (default timeout)static URLexecute(String method, URL url, String user, SecureString password, CheckedSupplier<String, Exception> requestBodySupplier, org.elasticsearch.core.CheckedFunction<InputStream, HttpResponse.HttpResponseBuilder, Exception> responseHandler) General purpose HTTP(S) call with JSON Content-Type and Authorization Header.execute(String method, URL url, SecureString apiKey, CheckedSupplier<String, Exception> requestBodySupplier, org.elasticsearch.core.CheckedFunction<InputStream, HttpResponse.HttpResponseBuilder, Exception> responseHandler) General purpose HTTP(S) call with JSON Content-Type and Authorization Header.static StringgetErrorCause(HttpResponse httpResponse)
-
Constructor Details
-
CommandLineHttpClient
-
CommandLineHttpClient
-
-
Method Details
-
execute
public HttpResponse execute(String method, URL url, String user, SecureString password, CheckedSupplier<String, Exception> requestBodySupplier, org.elasticsearch.core.CheckedFunction<InputStream, throws ExceptionHttpResponse.HttpResponseBuilder, Exception> responseHandler) General purpose HTTP(S) call with JSON Content-Type and Authorization Header. SSL settings are read from the settings file, if any.- Parameters:
user- user in the authorization header.password- password in the authorization header.requestBodySupplier- supplier for the JSON string body of the request.responseHandler- handler of the response Input Stream.- Returns:
- HTTP protocol response code.
- Throws:
Exception
-
execute
public HttpResponse execute(String method, URL url, SecureString apiKey, CheckedSupplier<String, Exception> requestBodySupplier, org.elasticsearch.core.CheckedFunction<InputStream, throws ExceptionHttpResponse.HttpResponseBuilder, Exception> responseHandler) General purpose HTTP(S) call with JSON Content-Type and Authorization Header. SSL settings are read from the settings file, if any.- Parameters:
apiKey- API key value to be used in the Authorization headerrequestBodySupplier- supplier for the JSON string body of the request.responseHandler- handler of the response Input Stream.- Returns:
- HTTP protocol response code.
- Throws:
Exception
-
getDefaultURL
-
getErrorCause
-
checkClusterHealthWithRetriesWaitingForCluster
public void checkClusterHealthWithRetriesWaitingForCluster(String username, SecureString password, int retries) throws Exception If cluster is not up yet (connection refused or master is unavailable), we will retry @retries number of times If status is 'Red', we will wait for 'Yellow' for 30s (default timeout)- Throws:
Exception
-
responseBuilder
- Throws:
IOException
-
createURL
public static URL createURL(URL url, String path, String query) throws MalformedURLException, URISyntaxException -
apiKeyHeaderValue
-