Class OkHttpClientBuilder
java.lang.Object
com.amilesend.client.connection.http.OkHttpClientBuilder
Utility to configure and build a
OkHttpClient
with the option of default configuration for this client.
This supports configuring a client that:
- Customizes the SSL trust manager and hostname verifier
- Configures a proxy with username and password
- Configures support to follow redirects
- Configures connection and read/write timeouts (default is disabled)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddInterceptor
(okhttp3.Interceptor interceptor) Adds an interceptor for the client.okhttp3.OkHttpClient
build()
Builds a newOkHttpClient
instance.connectTimeout
(Duration connectTimeout) Sets the connection timeout for the HTTP client.hostnameVerifier
(HostnameVerifier hostnameVerifier) Sets the hostname verifier to use with the HTTP client.isForTest
(boolean isForTest) Sets the flag to allow for non-SSL/TLS based requests used for testing.isRedirectsAllowed
(boolean isRedirectsAllowed) Sets the flag to allow for automatic URL redirects when responses return 300-based HTTP responses.Sets the proxy and associated username plus password to use with the HTTP client.Sets the proxy and associated authenticator to use with the HTTP client.readTimeout
(Duration readTimeout) Sets the read timeout for the HTTP client.trustManager
(X509TrustManager trustManager) Sets the SSL/TLS trust manager to use with the HTTP client.writeTimeout
(Duration writeTimeout) Sets the write timeout for the HTTP client.
-
Constructor Details
-
OkHttpClientBuilder
public OkHttpClientBuilder()
-
-
Method Details
-
trustManager
Sets the SSL/TLS trust manager to use with the HTTP client.- Parameters:
trustManager
- the trust manager- Returns:
- the builder instance
- See Also:
-
hostnameVerifier
Sets the hostname verifier to use with the HTTP client.- Parameters:
hostnameVerifier
- the trust manager- Returns:
- the builder instance
- See Also:
-
proxy
Sets the proxy and associated username plus password to use with the HTTP client. Note: ifusername
andpassword
is undefined, then no credential-based authentication will be configured.- Parameters:
proxy
- the proxy settingsusername
- the usernamepassword
- the password- Returns:
- the builder instance
-
proxy
Sets the proxy and associated authenticator to use with the HTTP client.- Parameters:
proxy
- the proxy settingsproxyAuthenticator
- the proxy authenticator- Returns:
- the builder instance
-
connectTimeout
Sets the connection timeout for the HTTP client.- Parameters:
connectTimeout
- the connection timeout- Returns:
- the builder instance
-
readTimeout
Sets the read timeout for the HTTP client.- Parameters:
readTimeout
- the read timeout- Returns:
- the builder instance
-
writeTimeout
Sets the write timeout for the HTTP client.- Parameters:
writeTimeout
- the write timeout.- Returns:
- the builder instance
-
isRedirectsAllowed
Sets the flag to allow for automatic URL redirects when responses return 300-based HTTP responses.- Parameters:
isRedirectsAllowed
- Iftrue
, then the client will automatically invoke the redirected URL; else,false
- Returns:
- the builder instance
-
isForTest
Sets the flag to allow for non-SSL/TLS based requests used for testing. Note: Should not be set for normal use with real calls to the Graph API.- Parameters:
isForTest
- Iftrue
, then the client will allow HTTP-based invocations; else,false
.- Returns:
- the builder instance
-
addInterceptor
Adds an interceptor for the client.- Parameters:
interceptor
- the interceptor- Returns:
- the builder instance
-
build
public okhttp3.OkHttpClient build()Builds a newOkHttpClient
instance.- Returns:
- the configured HTTP client
-