public class HttpClientWrapper extends Object implements Closeable
Modifier | Constructor and Description |
---|---|
protected |
HttpClientWrapper() |
Modifier and Type | Method and Description |
---|---|
HttpClientWrapper |
addBasicCredentials(String username,
String password)
Add basic auth credentials to requests created by the HttpClientWrapper.
|
HttpClientWrapper |
addRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
Add an
HttpRequestInterceptor for all requests. |
HttpClientWrapper |
addResponseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
Add an
HttpResponseInterceptor for all responses. |
protected void |
assertNotInitialized() |
void |
close()
Safely clean up the HttpClient.
|
void |
close(org.apache.http.client.methods.CloseableHttpResponse response)
Safely clean up after a response.
|
protected void |
configureSSLContext(org.apache.http.impl.client.HttpClientBuilder builder) |
static HttpClientWrapper |
create()
Create a new HTTP client wrapper.
|
HttpClientWrapper |
dontReuseConnections()
Configure HttpClient to not reuse connections for multiple requests.
|
HttpClientWrapper |
duplicate()
Create a duplicate HttpClientWrapper from this wrapper.
|
protected void |
enablePreemptiveAuth(org.apache.http.impl.client.HttpClientBuilder builder) |
org.apache.http.client.methods.CloseableHttpResponse |
execute(org.apache.http.client.methods.HttpUriRequest method)
Execute the given HTTP method, returning an HTTP response.
|
org.apache.http.impl.client.CloseableHttpClient |
getClient() |
HttpClientWrapper |
setConnectionTimeout(Integer connectionTimeout)
Set the connection timeout on connections.
|
protected void |
setCredentials(org.apache.http.impl.client.HttpClientBuilder httpClientBuilder,
String username,
String password) |
HttpClientWrapper |
setRetries(Integer retries)
Set the number of retries when making requests.
|
HttpClientWrapper |
setSocketTimeout(Integer socketTimeout)
Set the socket timeout on connections.
|
HttpClientWrapper |
setUserAgent(String userAgent)
Set the User-Agent header used when making requests.
|
HttpClientWrapper |
setVersion(org.apache.http.HttpVersion httpVersion)
Set the HTTP version used when making requests.
|
HttpClientWrapper |
setVirtualHost(String host)
Set the Host header used when making requests.
|
String |
toString() |
HttpClientWrapper |
trustSelfSigned(String scheme)
Trust self-signed certificates.
|
HttpClientWrapper |
useBrowserCompatibleCookies()
Use browser-compatible cookies rather than the default.
|
HttpClientWrapper |
useLaxRedirect()
Use LAX redirect strategy.
|
HttpClientWrapper |
usePreemptiveAuth()
Preemptively pass basic authentication headers, rather than waiting for the server
to response asking for it.
|
HttpClientWrapper |
useRelaxedSSL(String scheme)
Use relaxed SSL connection handling (EmptyKeyRelaxedTrustSSLContext.ALGORITHM, allows any certificate)
|
HttpClientWrapper |
useSystemProxySettings()
Configure HttpClient to honor the system java proxy settings (-Dhttp.proxyHost= -Dhttp.proxyPort=)
|
public static HttpClientWrapper create()
public HttpClientWrapper addBasicCredentials(String username, String password)
username
- The username to connect aspassword
- The password to usepublic HttpClientWrapper addRequestInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
HttpRequestInterceptor
for all requests.public HttpClientWrapper addResponseInterceptor(org.apache.http.HttpResponseInterceptor interceptor)
HttpResponseInterceptor
for all responses.public HttpClientWrapper dontReuseConnections()
public HttpClientWrapper useSystemProxySettings()
public HttpClientWrapper useBrowserCompatibleCookies()
public HttpClientWrapper useRelaxedSSL(String scheme) throws GeneralSecurityException
public HttpClientWrapper trustSelfSigned(String scheme) throws GeneralSecurityException
GeneralSecurityException
public HttpClientWrapper usePreemptiveAuth()
public HttpClientWrapper useLaxRedirect()
public HttpClientWrapper setSocketTimeout(Integer socketTimeout)
public HttpClientWrapper setConnectionTimeout(Integer connectionTimeout)
public HttpClientWrapper setRetries(Integer retries)
public HttpClientWrapper setUserAgent(String userAgent)
public HttpClientWrapper setVirtualHost(String host)
public HttpClientWrapper setVersion(org.apache.http.HttpVersion httpVersion)
public void close(org.apache.http.client.methods.CloseableHttpResponse response)
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public org.apache.http.client.methods.CloseableHttpResponse execute(org.apache.http.client.methods.HttpUriRequest method) throws org.apache.http.client.ClientProtocolException, IOException
#closeResponse()
so that it gets cleaned up properly.org.apache.http.client.ClientProtocolException
IOException
public HttpClientWrapper duplicate()
public org.apache.http.impl.client.CloseableHttpClient getClient()
protected void assertNotInitialized()
protected void setCredentials(org.apache.http.impl.client.HttpClientBuilder httpClientBuilder, String username, String password)
protected void enablePreemptiveAuth(org.apache.http.impl.client.HttpClientBuilder builder)
protected void configureSSLContext(org.apache.http.impl.client.HttpClientBuilder builder)
Copyright © 2021. All rights reserved.