Class HttpClient
- java.lang.Object
-
- org.apache.pinot.common.utils.http.HttpClient
-
- All Implemented Interfaces:
AutoCloseable
public class HttpClient extends Object implements AutoCloseable
TheHTTPClientwraps around aCloseableHttpClientto provide a reusable client for making HTTP requests.
-
-
Field Summary
Fields Modifier and Type Field Description static StringAUTH_HTTP_HEADERstatic intDEFAULT_SOCKET_TIMEOUT_MSstatic intDELETE_REQUEST_SOCKET_TIMEOUT_MSstatic intGET_REQUEST_SOCKET_TIMEOUT_MSstatic StringJSON_CONTENT_TYPE
-
Constructor Summary
Constructors Constructor Description HttpClient()HttpClient(SSLContext sslContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddHeadersAndParameters(org.apache.http.client.methods.RequestBuilder requestBuilder, List<org.apache.http.Header> headers, List<org.apache.http.NameValuePair> parameters)voidclose()intdownloadFile(URI uri, int socketTimeoutMs, File dest, AuthProvider authProvider, List<org.apache.http.Header> httpHeaders)Download a file using default settings, with an optional auth tokenFiledownloadUntarFileStreamed(URI uri, int socketTimeoutMs, File dest, AuthProvider authProvider, List<org.apache.http.Header> httpHeaders, long maxStreamRateInByte)Download and untar in a streamed manner a file using default settings, with an optional auth tokenprotected org.apache.http.client.methods.CloseableHttpResponseexecute(org.apache.http.client.methods.HttpUriRequest request)static HttpClientgetInstance()SimpleHttpResponsesendDeleteRequest(URI uri)Deprecated due to lack of auth header support.SimpleHttpResponsesendDeleteRequest(URI uri, Map<String,String> headers)SimpleHttpResponsesendDeleteRequest(URI uri, Map<String,String> headers, AuthProvider authProvider)SimpleHttpResponsesendGetRequest(URI uri)Deprecated due to lack of auth header support.SimpleHttpResponsesendGetRequest(URI uri, Map<String,String> headers)SimpleHttpResponsesendGetRequest(URI uri, Map<String,String> headers, AuthProvider authProvider)SimpleHttpResponsesendJsonPostRequest(URI uri, String jsonRequestBody)SimpleHttpResponsesendJsonPostRequest(URI uri, String jsonRequestBody, Map<String,String> headers)SimpleHttpResponsesendJsonPostRequest(URI uri, String jsonRequestBody, Map<String,String> headers, AuthProvider authProvider)SimpleHttpResponsesendJsonPutRequest(URI uri, String jsonRequestBody)SimpleHttpResponsesendJsonPutRequest(URI uri, String jsonRequestBody, Map<String,String> headers)SimpleHttpResponsesendJsonPutRequest(URI uri, String jsonRequestBody, Map<String,String> headers, AuthProvider authProvider)SimpleHttpResponsesendMultipartPostRequest(String url, String body)SimpleHttpResponsesendMultipartPostRequest(String url, String body, Map<String,String> headers)SimpleHttpResponsesendMultipartPutRequest(String url, String body)SimpleHttpResponsesendMultipartPutRequest(String url, String body, Map<String,String> headers)SimpleHttpResponsesendPostRequest(URI uri, org.apache.http.HttpEntity payload, Map<String,String> headers)Deprecated due to lack of auth header support.SimpleHttpResponsesendPostRequest(URI uri, org.apache.http.HttpEntity payload, Map<String,String> headers, AuthProvider authProvider)SimpleHttpResponsesendPutRequest(URI uri, org.apache.http.HttpEntity payload, Map<String,String> headers)Deprecated due to lack of auth header support.SimpleHttpResponsesendPutRequest(URI uri, org.apache.http.HttpEntity payload, Map<String,String> headers, AuthProvider authProvider)SimpleHttpResponsesendRequest(org.apache.http.client.methods.HttpUriRequest request)static voidsetTimeout(org.apache.http.client.methods.RequestBuilder requestBuilder, int socketTimeoutMs)static SimpleHttpResponsewrapAndThrowHttpException(SimpleHttpResponse resp)
-
-
-
Field Detail
-
DEFAULT_SOCKET_TIMEOUT_MS
public static final int DEFAULT_SOCKET_TIMEOUT_MS
- See Also:
- Constant Field Values
-
GET_REQUEST_SOCKET_TIMEOUT_MS
public static final int GET_REQUEST_SOCKET_TIMEOUT_MS
- See Also:
- Constant Field Values
-
DELETE_REQUEST_SOCKET_TIMEOUT_MS
public static final int DELETE_REQUEST_SOCKET_TIMEOUT_MS
- See Also:
- Constant Field Values
-
AUTH_HTTP_HEADER
public static final String AUTH_HTTP_HEADER
- See Also:
- Constant Field Values
-
JSON_CONTENT_TYPE
public static final String JSON_CONTENT_TYPE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HttpClient
public HttpClient()
-
HttpClient
public HttpClient(@Nullable SSLContext sslContext)
-
-
Method Detail
-
getInstance
public static HttpClient getInstance()
-
sendGetRequest
public SimpleHttpResponse sendGetRequest(URI uri) throws IOException
Deprecated due to lack of auth header support. May break for deployments with auth enabled- Throws:
IOException- See Also:
sendGetRequest(URI, Map, AuthProvider)
-
sendGetRequest
public SimpleHttpResponse sendGetRequest(URI uri, @Nullable Map<String,String> headers) throws IOException
- Throws:
IOException
-
sendGetRequest
public SimpleHttpResponse sendGetRequest(URI uri, @Nullable Map<String,String> headers, @Nullable AuthProvider authProvider) throws IOException
- Throws:
IOException
-
sendDeleteRequest
public SimpleHttpResponse sendDeleteRequest(URI uri) throws IOException
Deprecated due to lack of auth header support. May break for deployments with auth enabled- Throws:
IOException- See Also:
sendDeleteRequest(URI, Map, AuthProvider)
-
sendDeleteRequest
public SimpleHttpResponse sendDeleteRequest(URI uri, @Nullable Map<String,String> headers) throws IOException
- Throws:
IOException
-
sendDeleteRequest
public SimpleHttpResponse sendDeleteRequest(URI uri, @Nullable Map<String,String> headers, @Nullable AuthProvider authProvider) throws IOException
- Throws:
IOException
-
sendPostRequest
public SimpleHttpResponse sendPostRequest(URI uri, @Nullable org.apache.http.HttpEntity payload, @Nullable Map<String,String> headers) throws IOException
Deprecated due to lack of auth header support. May break for deployments with auth enabled- Throws:
IOException- See Also:
sendPostRequest(URI, HttpEntity, Map, AuthProvider)
-
sendPostRequest
public SimpleHttpResponse sendPostRequest(URI uri, @Nullable org.apache.http.HttpEntity payload, @Nullable Map<String,String> headers, @Nullable AuthProvider authProvider) throws IOException
- Throws:
IOException
-
sendPutRequest
public SimpleHttpResponse sendPutRequest(URI uri, @Nullable org.apache.http.HttpEntity payload, @Nullable Map<String,String> headers) throws IOException
Deprecated due to lack of auth header support. May break for deployments with auth enabled- Throws:
IOException- See Also:
sendPutRequest(URI, HttpEntity, Map, AuthProvider)
-
sendPutRequest
public SimpleHttpResponse sendPutRequest(URI uri, @Nullable org.apache.http.HttpEntity payload, @Nullable Map<String,String> headers, @Nullable AuthProvider authProvider) throws IOException
- Throws:
IOException
-
sendJsonPostRequest
public SimpleHttpResponse sendJsonPostRequest(URI uri, @Nullable String jsonRequestBody) throws IOException
- Throws:
IOException
-
sendJsonPostRequest
public SimpleHttpResponse sendJsonPostRequest(URI uri, @Nullable String jsonRequestBody, @Nullable Map<String,String> headers) throws IOException
- Throws:
IOException
-
sendJsonPostRequest
public SimpleHttpResponse sendJsonPostRequest(URI uri, @Nullable String jsonRequestBody, @Nullable Map<String,String> headers, @Nullable AuthProvider authProvider) throws IOException
- Throws:
IOException
-
sendJsonPutRequest
public SimpleHttpResponse sendJsonPutRequest(URI uri, @Nullable String jsonRequestBody) throws IOException
- Throws:
IOException
-
sendJsonPutRequest
public SimpleHttpResponse sendJsonPutRequest(URI uri, @Nullable String jsonRequestBody, @Nullable Map<String,String> headers) throws IOException
- Throws:
IOException
-
sendJsonPutRequest
public SimpleHttpResponse sendJsonPutRequest(URI uri, @Nullable String jsonRequestBody, @Nullable Map<String,String> headers, @Nullable AuthProvider authProvider) throws IOException
- Throws:
IOException
-
sendRequest
public SimpleHttpResponse sendRequest(org.apache.http.client.methods.HttpUriRequest request) throws IOException
- Throws:
IOException
-
execute
protected org.apache.http.client.methods.CloseableHttpResponse execute(org.apache.http.client.methods.HttpUriRequest request) throws IOException- Throws:
IOException
-
sendMultipartPostRequest
public SimpleHttpResponse sendMultipartPostRequest(String url, String body) throws IOException
- Throws:
IOException
-
sendMultipartPostRequest
public SimpleHttpResponse sendMultipartPostRequest(String url, String body, @Nullable Map<String,String> headers) throws IOException
- Throws:
IOException
-
sendMultipartPutRequest
public SimpleHttpResponse sendMultipartPutRequest(String url, String body) throws IOException
- Throws:
IOException
-
sendMultipartPutRequest
public SimpleHttpResponse sendMultipartPutRequest(String url, String body, @Nullable Map<String,String> headers) throws IOException
- Throws:
IOException
-
downloadFile
public int downloadFile(URI uri, int socketTimeoutMs, File dest, AuthProvider authProvider, List<org.apache.http.Header> httpHeaders) throws IOException, HttpErrorStatusException
Download a file using default settings, with an optional auth token- Parameters:
uri- URIsocketTimeoutMs- Socket timeout in millisecondsdest- File destinationauthProvider- auth providerhttpHeaders- http headers- Returns:
- Response status code
- Throws:
IOExceptionHttpErrorStatusException
-
downloadUntarFileStreamed
public File downloadUntarFileStreamed(URI uri, int socketTimeoutMs, File dest, AuthProvider authProvider, List<org.apache.http.Header> httpHeaders, long maxStreamRateInByte) throws IOException, HttpErrorStatusException
Download and untar in a streamed manner a file using default settings, with an optional auth token- Parameters:
uri- URIsocketTimeoutMs- Socket timeout in millisecondsdest- File destinationauthProvider- auth providerhttpHeaders- http headersmaxStreamRateInByte- limit the rate to write download-untar stream to disk, in bytes -1 for no disk write limit, 0 for limit the writing to min(untar, download) rate- Returns:
- The untarred directory
- Throws:
IOExceptionHttpErrorStatusException
-
wrapAndThrowHttpException
public static SimpleHttpResponse wrapAndThrowHttpException(SimpleHttpResponse resp) throws HttpErrorStatusException
- Throws:
HttpErrorStatusException
-
addHeadersAndParameters
public static void addHeadersAndParameters(org.apache.http.client.methods.RequestBuilder requestBuilder, @Nullable List<org.apache.http.Header> headers, @Nullable List<org.apache.http.NameValuePair> parameters)
-
setTimeout
public static void setTimeout(org.apache.http.client.methods.RequestBuilder requestBuilder, int socketTimeoutMs)
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-
-