public class Config extends Object
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CONNECT_TIMEOUT |
static int |
DEFAULT_CONNECTION_TIMEOUT |
static int |
DEFAULT_MAX_CONNECTIONS |
static int |
DEFAULT_MAX_PER_ROUTE |
static int |
DEFAULT_SOCKET_TIMEOUT |
Constructor and Description |
---|
Config() |
Modifier and Type | Method and Description |
---|---|
Config |
addDefaultHeader(String name,
String value)
Add default header to appear on all requests
|
Config |
addInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
Add a HttpRequestInterceptor to the clients.
|
Config |
addShutdownHook(boolean value)
Register the client with a system shutdown hook.
|
Config |
asyncClient(AsyncClient value)
Set the full async configuration including monitors.
|
Config |
asyncClient(java.util.function.Function<Config,AsyncClient> asyncClientBuilder)
Set the full async configuration including monitors.
|
Config |
asyncClient(org.apache.http.nio.client.HttpAsyncClient value)
Set the asynchronous AbstractHttpAsyncClient implementation to use for every asynchronous request
|
Config |
automaticRetries(boolean value)
Automaticly retry certain recoverable errors like socket timeouts.
|
Config |
clearDefaultHeaders()
Clear default headers
|
Config |
clientCertificateStore(KeyStore store,
String password)
Set a custom keystore
|
Config |
clientCertificateStore(String fileLocation,
String password)
Set a custom keystore via a file path.
|
Config |
concurrency(int total,
int perRoute)
Set the concurrency levels
|
Config |
connectionTTL(long duration,
TimeUnit unit)
Total time to live (TTL) defines maximum life span of persistent connections regardless of their expiration setting.
|
Config |
connectTimeout(int inMillies)
Set the connection timeout
|
Config |
cookieSpec(String policy)
Sets a cookie policy
Acceptable values:
'default' (same as Netscape),
'netscape',
'ignoreCookies',
'standard' (RFC 6265 interoprability profile) ,
'standard-strict' (RFC 6265 strict profile)
|
Config |
enableCookieManagement(boolean enable)
Allow the client to manage cookies.
|
Config |
followRedirects(boolean enable)
Allow the client to follow redirects.
|
AsyncClient |
getAsyncClient()
Return the current HttpAsyncClient.
|
Client |
getClient()
Return the current Client.
|
int |
getConnectionTimeout() |
String |
getCookieSpec() |
Headers |
getDefaultHeaders()
Return default headers that are added to every request
|
String |
getDefaultResponseEncoding() |
boolean |
getEnabledCookieManagement() |
boolean |
getFollowRedirects() |
List<org.apache.http.HttpRequestInterceptor> |
getInterceptors() |
KeyStore |
getKeystore() |
String |
getKeyStorePassword() |
int |
getMaxConnections() |
int |
getMaxPerRoutes() |
UniMetric |
getMetric() |
ObjectMapper |
getObjectMapper() |
Proxy |
getProxy() |
int |
getSocketTimeout() |
long |
getTTL() |
Config |
httpClient(Client httpClient)
Set the HttpClient implementation to use for every synchronous request
|
Config |
httpClient(java.util.function.Function<Config,Client> httpClient)
Provide a builder for a client
|
Config |
httpClient(org.apache.http.client.HttpClient httpClient)
Deprecated.
|
Config |
instrumentWith(UniMetric metric)
Add a metric object for instrumentation
|
boolean |
isAutomaticRetries() |
boolean |
isRequestCompressionOn() |
boolean |
isRunning()
Does the config have currently running clients? Find out here.
|
boolean |
isVerifySsl() |
Config |
proxy(Proxy value)
Set a proxy
|
Config |
proxy(String host,
int port)
Set a proxy
|
Config |
proxy(String host,
int port,
String username,
String password)
Set an authenticated proxy
|
Config |
requestCompression(boolean value)
Turn on or off requesting all content as compressed.
|
Config |
reset()
Shutdown the current config and re-init.
|
Config |
setDefaultBasicAuth(String username,
String password)
Default basic auth credentials
|
Config |
setDefaultHeader(String name,
String value)
Set default header to appear on all requests
|
Config |
setDefaultHeader(String name,
java.util.function.Supplier<String> value)
Set default header to appear on all requests, value is through a Supplier
This is useful for adding tracing elements to requests.
|
Config |
setDefaultResponseEncoding(String value)
Set the default encoding that will be used for serialization into Strings.
|
Config |
setObjectMapper(ObjectMapper om)
Set the ObjectMapper implementation to use for Response to Object binding
|
boolean |
shouldAddShutdownHook() |
void |
shutDown(boolean clearOptions)
Shut down the configuration and its clients.
|
Config |
socketTimeout(int inMillies)
Set the socket timeout
|
boolean |
useSystemProperties() |
Config |
useSystemProperties(boolean value)
Tell the HttpClients to use the system properties for things like proxies
|
Config |
verifySsl(boolean value)
Toggle verifying SSL/TLS certificates.
|
public static final int DEFAULT_CONNECTION_TIMEOUT
public static final int DEFAULT_MAX_CONNECTIONS
public static final int DEFAULT_MAX_PER_ROUTE
public static final int DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_SOCKET_TIMEOUT
@Deprecated public Config httpClient(org.apache.http.client.HttpClient httpClient)
httpClient
- Custom httpClient implementationpublic Config httpClient(Client httpClient)
httpClient
- Custom httpClient implementationpublic Config httpClient(java.util.function.Function<Config,Client> httpClient)
httpClient
- Custom httpClient implementationpublic Config asyncClient(org.apache.http.nio.client.HttpAsyncClient value)
value
- Custom CloseableHttpAsyncClient implementationpublic Config asyncClient(AsyncClient value)
value
- Custom AsyncConfig class. The actual AsyncHttpClient is required.public Config asyncClient(java.util.function.Function<Config,AsyncClient> asyncClientBuilder)
asyncClientBuilder
- A builder function for creating a AsyncClientpublic Config proxy(Proxy value)
value
- Proxy settings object.public Config proxy(String host, int port)
host
- the hostname of the proxy server.port
- the port of the proxy serverpublic Config proxy(String host, int port, String username, String password)
host
- the hostname of the proxy server.port
- the port of the proxy serverusername
- username for authenticated proxypassword
- password for authenticated proxypublic Config setObjectMapper(ObjectMapper om)
om
- Custom implementation of ObjectMapper interfacepublic Config clientCertificateStore(KeyStore store, String password)
store
- the keystore to use for a custom ssl contextpassword
- the password for the storepublic Config clientCertificateStore(String fileLocation, String password)
fileLocation
- the path keystore to use for a custom ssl contextpassword
- the password for the storepublic Config connectTimeout(int inMillies)
inMillies
- The timeout until a connection with the server is established (in milliseconds). Default is 10000. Set to zero to disable the timeout.public Config socketTimeout(int inMillies)
inMillies
- The timeout to receive data (in milliseconds). Default is 60000. Set to zero to disable the timeout.public Config concurrency(int total, int perRoute)
total
- Defines the overall connection limit for a connection pool. Default is 200.perRoute
- Defines a connection limit per one HTTP route (this can be considered a per target host limit). Default is 20.public Config clearDefaultHeaders()
public Config setDefaultBasicAuth(String username, String password)
username
- the usernamepassword
- the passwordpublic Config setDefaultHeader(String name, String value)
name
- The name of the header.value
- The value of the header.public Config setDefaultHeader(String name, java.util.function.Supplier<String> value)
name
- The name of the header.value
- a supplier that will get called as part of the request.public Config addDefaultHeader(String name, String value)
name
- The name of the header.value
- The value of the header.public Config instrumentWith(UniMetric metric)
metric
- a UniMetric objectpublic Config addInterceptor(org.apache.http.HttpRequestInterceptor interceptor)
interceptor
- The addInterceptorpublic Config followRedirects(boolean enable)
enable
- The name of the header.public Config enableCookieManagement(boolean enable)
enable
- The name of the header.public Config verifySsl(boolean value)
value
- a bool is its true or not.public Config useSystemProperties(boolean value)
value
- a bool is its true or not.public Config requestCompression(boolean value)
value
- a bool is its true or not.public Config automaticRetries(boolean value)
value
- a bool is its true or not.public Config cookieSpec(String policy)
policy:
- the policy for cookies to followpublic Config setDefaultResponseEncoding(String value)
value
- a bool is its true or not.public Config connectionTTL(long duration, TimeUnit unit)
duration
- of ttl.unit
- the time unit of the ttlpublic Config addShutdownHook(boolean value)
value
- a bool is its true or not.public Headers getDefaultHeaders()
public boolean isRunning()
public Config reset()
public void shutDown(boolean clearOptions)
clearOptions
- should the current non-client settings be retained.public Client getClient()
public AsyncClient getAsyncClient()
public boolean getEnabledCookieManagement()
public boolean getFollowRedirects()
public int getMaxConnections()
public int getMaxPerRoutes()
public int getConnectionTimeout()
public int getSocketTimeout()
public KeyStore getKeystore()
public String getKeyStorePassword()
public ObjectMapper getObjectMapper()
UnirestException
- if none has been configured.public List<org.apache.http.HttpRequestInterceptor> getInterceptors()
public Proxy getProxy()
public boolean useSystemProperties()
public String getDefaultResponseEncoding()
public boolean isRequestCompressionOn()
public boolean isAutomaticRetries()
public boolean isVerifySsl()
public boolean shouldAddShutdownHook()
public String getCookieSpec()
public UniMetric getMetric()
public long getTTL()
Copyright © 2019. All rights reserved.