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 |
addDefaultCookie(Cookie cookie)
Adds a default cookie to be added to all requests with this config
|
Config |
addDefaultCookie(String name,
String value)
Adds a default cookie to be added to all requests with this config
|
Config |
addDefaultHeader(String name,
String value)
Add default header to appear on all requests
|
Config |
addInterceptor(org.apache.http.HttpRequestInterceptor value)
Deprecated.
use the Unirest Interceptors rather than Apache
|
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(Function<Config,AsyncClient> asyncClientBuilder)
Set the full async configuration including monitors.
|
Config |
asyncClient(org.apache.http.nio.client.HttpAsyncClient value)
Deprecated.
use asyncClient(AsyncClient value)
|
Config |
automaticRetries(boolean value)
Automaticly retry certain recoverable errors like socket timeouts.
|
void |
cacheResponses(boolean value)
Enable Response Caching with default options
|
void |
cacheResponses(Cache.Builder value)
Enable Response Caching with custom options
|
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(Duration duration)
Sugar!
Total time to live (TTL) defines maximum life span of persistent connections regardless of their expiration setting.
|
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 |
defaultBaseUrl(String value)
set a default base url for all routes.
|
Config |
enableCookieManagement(boolean enable)
Allow the client to manage cookies.
|
Config |
errorHandler(Consumer<HttpResponse<?>> consumer)
Deprecated.
this is merging with the interceptor concept. see interceptor(Interceptor value)
|
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() |
String |
getDefaultBaseUrl() |
Headers |
getDefaultHeaders()
Return default headers that are added to every request
|
String |
getDefaultResponseEncoding() |
boolean |
getEnabledCookieManagement() |
Consumer<HttpResponse<?>> |
getErrorHandler()
Deprecated.
use interceptors instead
|
boolean |
getFollowRedirects() |
HostnameVerifier |
getHostnameVerifier() |
List<org.apache.http.HttpRequestInterceptor> |
getInterceptor()
Deprecated.
use Unirest Interceptors instead
|
KeyStore |
getKeystore() |
String |
getKeyStorePassword() |
int |
getMaxConnections() |
int |
getMaxPerRoutes() |
UniMetric |
getMetric() |
ObjectMapper |
getObjectMapper() |
Proxy |
getProxy() |
int |
getSocketTimeout() |
SSLContext |
getSslContext() |
long |
getTTL() |
Interceptor |
getUniInterceptor() |
Config |
hostnameVerifier(HostnameVerifier value)
Set a custom HostnameVerifier
|
Config |
httpClient(Client httpClient)
Set the HttpClient implementation to use for every synchronous request
|
Config |
httpClient(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
|
Config |
interceptor(Interceptor value)
Add a Interceptor which will be called before and after the request;
|
boolean |
isAutomaticRetries() |
boolean |
isRequestCompressionOn() |
boolean |
isRunning()
Does the config have currently running clients? Find out here.
|
boolean |
isVerifySsl()
Will unirest verify the SSL?
You should only do this in non-prod environments.
|
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,
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
|
Config |
sslContext(SSLContext ssl)
Set a custom SSLContext.
|
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(Function<Config,Client> httpClient)
httpClient
- Custom httpClient implementation@Deprecated public 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(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 sslContext(SSLContext ssl)
ssl
- the SSLContext to use for custom ssl contextUnirestConfigException
- if a keystore was already configured.public Config hostnameVerifier(HostnameVerifier value)
value
- the verifierpublic Config clientCertificateStore(KeyStore store, String password)
store
- the keystore to use for a custom ssl contextpassword
- the password for the storeUnirestConfigException
- if a SSLContext was already configured.public Config clientCertificateStore(String fileLocation, String password)
fileLocation
- the path keystore to use for a custom ssl contextpassword
- the password for the storeUnirestConfigException
- if a SSLContext was already configured.public 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, 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 addDefaultCookie(String name, String value)
name
- the name of the cookievalue
- the value of the cookiepublic Config addDefaultCookie(Cookie cookie)
cookie
- the cookiepublic Config instrumentWith(UniMetric metric)
metric
- a UniMetric object@Deprecated public Config errorHandler(Consumer<HttpResponse<?>> consumer)
consumer
- a function to consume a HttpResponsepublic Config interceptor(Interceptor value)
value
- The Interceptor@Deprecated public Config addInterceptor(org.apache.http.HttpRequestInterceptor value)
value
- 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 void cacheResponses(boolean value)
value
- enable or disable response cachingpublic void cacheResponses(Cache.Builder value)
value
- enable or disable response cachingpublic 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 connectionTTL(Duration duration)
duration
- of ttl.public Config addShutdownHook(boolean value)
value
- a bool is its true or not.public Config defaultBaseUrl(String value)
value
- the base URL to usepublic 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.@Deprecated public List<org.apache.http.HttpRequestInterceptor> getInterceptor()
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()
public Interceptor getUniInterceptor()
@Deprecated public Consumer<HttpResponse<?>> getErrorHandler()
public SSLContext getSslContext()
public HostnameVerifier getHostnameVerifier()
public String getDefaultBaseUrl()
Copyright © 2020. All rights reserved.