public class ApacheHttpClientProvider extends Object implements HttpProvider
HttpProvider that uses Apache HttpClient as the underlying implementation.
See Apache HTTP Components
for more information, specifically the HttpClient project.
If you just want the default 5000 ms for both connection timeout and request timeout, just use the following example code:
HttpProvider httpProvider = ApacheHttpClientProvider.builder().build();
// use httpProvider such as with HereAccessTokenProviders...
To set the HTTP connection pool size, use the following example code.
NOTE: the connection pool size is set to 200 in this example. Modify the value to fit your needs.
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
// Increase max total connection to 200
cm.setMaxTotal(200);
CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(cm).build();
HttpProvider httpProvider = ApacheHttpClientProvider.builder().setHttpClient(httpClient).build();
// use httpProvider such as with HereAccessTokenProviders...
| Modifier and Type | Class and Description |
|---|---|
static class |
ApacheHttpClientProvider.Builder |
HttpProvider.HttpRequest, HttpProvider.HttpRequestAuthorizer, HttpProvider.HttpResponse| Modifier and Type | Method and Description |
|---|---|
static ApacheHttpClientProvider.Builder |
builder() |
void |
close() |
HttpProvider.HttpResponse |
execute(HttpProvider.HttpRequest httpRequest)
Execute the httpRequest.
|
HttpProvider.HttpRequest |
getRequest(HttpProvider.HttpRequestAuthorizer httpRequestAuthorizer,
String method,
String url,
Map<String,List<String>> formParams)
Gets the RequestBuilder, with the specified method, url, and formParams.
|
HttpProvider.HttpRequest |
getRequest(HttpProvider.HttpRequestAuthorizer httpRequestAuthorizer,
String method,
String url,
String requestBodyJson)
Gets the RequestBuilder, with the specified method, url, and requestBodyJson.
|
public static ApacheHttpClientProvider.Builder builder()
public HttpProvider.HttpRequest getRequest(HttpProvider.HttpRequestAuthorizer httpRequestAuthorizer, String method, String url, String requestBodyJson)
getRequest in interface HttpProviderhttpRequestAuthorizer - for adding the Authorization header valuemethod - HTTP method valueurl - HTTP request URLrequestBodyJson - the
Content-Type: application/json
JSON request body.HttpProvider.execute(HttpRequest).public HttpProvider.HttpRequest getRequest(HttpProvider.HttpRequestAuthorizer httpRequestAuthorizer, String method, String url, Map<String,List<String>> formParams)
getRequest in interface HttpProviderhttpRequestAuthorizer - for adding the Authorization header valuemethod - HTTP method valueurl - HTTP request URLformParams - the
Content-Type: application/x-www-form-urlencoded
form parameters.HttpProvider.execute(HttpRequest).public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic HttpProvider.HttpResponse execute(HttpProvider.HttpRequest httpRequest) throws HttpException, IOException
HttpProviderexecute in interface HttpProviderhttpRequest - the HttpRequestHttpException - if there is trouble executing the httpRequestIOException - if there is I/O trouble executing the httpRequestCopyright © 2022 HERE Europe B.V. All Rights Reserved.