-
public final class MobonOkHttpClient.Builder
-
-
Constructor Summary
Constructors Constructor Description MobonOkHttpClient.Builder()
-
Method Summary
Modifier and Type Method Description MobonOkHttpClient.BuilderconnectTimeout(long timeout, TimeUnit unit)Sets the default connect timeout for new connections. MobonOkHttpClient.BuilderreadTimeout(long timeout, TimeUnit unit)Sets the default read timeout for new connections. MobonOkHttpClient.BuilderwriteTimeout(long timeout, TimeUnit unit)Sets the default write timeout for new connections. MobonOkHttpClient.BuilderpingInterval(long interval, TimeUnit unit)Sets the interval between HTTP/2 and web socket pings initiated by this client. MobonOkHttpClient.Builderproxy(@Nullable() Proxy proxy)Sets the HTTP proxy that will be used by connections created by this client. MobonOkHttpClient.BuilderproxySelector(ProxySelector proxySelector)Sets the proxy selection policy to be used if no proxy is specifiedexplicitly. MobonOkHttpClient.BuildercookieJar(CookieJar cookieJar)Sets the handler that can accept cookies from incoming HTTP responses and provides cookies tooutgoing HTTP requests. MobonOkHttpClient.Buildercache(@Nullable() Cache cache)Sets the response cache to be used to read and write cached responses. MobonOkHttpClient.Builderdns(Dns dns)Sets the DNS service used to lookup IP addresses for hostnames. MobonOkHttpClient.BuildersocketFactory(SocketFactory socketFactory)Sets the socket factory used to create connections. MobonOkHttpClient.BuildersslSocketFactory(SSLSocketFactory sslSocketFactory)Sets the socket factory used to secure HTTPS connections. MobonOkHttpClient.BuildersslSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager)Sets the socket factory and trust manager used to secure HTTPS connections. MobonOkHttpClient.BuilderhostnameVerifier(HostnameVerifier hostnameVerifier)Sets the verifier used to confirm that response certificates apply to requested hostnames forHTTPS connections. MobonOkHttpClient.BuildercertificatePinner(CertificatePinner certificatePinner)Sets the certificate pinner that constrains which certificates are trusted. MobonOkHttpClient.Builderauthenticator(Authenticator authenticator)Sets the authenticator used to respond to challenges from origin servers. MobonOkHttpClient.BuilderproxyAuthenticator(Authenticator proxyAuthenticator)Sets the authenticator used to respond to challenges from proxy servers. MobonOkHttpClient.BuilderconnectionPool(ConnectionPool connectionPool)Sets the connection pool used to recycle HTTP and HTTPS connections. MobonOkHttpClient.BuilderfollowSslRedirects(boolean followProtocolRedirects)Configure this client to follow redirects from HTTPS to HTTP and from HTTP to HTTPS. MobonOkHttpClient.BuilderfollowRedirects(boolean followRedirects)Configure this client to follow redirects. MobonOkHttpClient.BuilderretryOnConnectionFailure(boolean retryOnConnectionFailure)Configure this client to retry or not when a connectivity problem is encountered. MobonOkHttpClient.Builderdispatcher(Dispatcher dispatcher)Sets the dispatcher used to set policy and execute asynchronous requests. MobonOkHttpClient.Builderprotocols(List<Protocol> protocols)Configure the protocols used by this client to communicate with remote servers. MobonOkHttpClient.BuilderconnectionSpecs(List<ConnectionSpec> connectionSpecs)List<Interceptor>interceptors()Returns a modifiable list of interceptors that observe the full span of each call: frombefore the connection is established (if any) until after the response source is selected(either the origin server, cache, or both). MobonOkHttpClient.BuilderaddInterceptor(Interceptor interceptor)List<Interceptor>networkInterceptors()Returns a modifiable list of interceptors that observe a single network mobonRequest and response. MobonOkHttpClient.BuilderaddNetworkInterceptor(Interceptor interceptor)MobonOkHttpClient.BuildereventListener(EventListener eventListener)Configure a single client scoped listener that will receive all analytic eventsfor this client. MobonOkHttpClient.BuildereventListenerFactory(EventListener.Factory eventListenerFactory)Configure a factory to provide per-call scoped listeners that will receive analytic eventsfor this client. MobonOkHttpClientbuild()-
-
Method Detail
-
connectTimeout
MobonOkHttpClient.Builder connectTimeout(long timeout, TimeUnit unit)
Sets the default connect timeout for new connections. A value of 0 means no timeout,otherwise values must be between 1 and MAX_VALUE when converted tomilliseconds.
The connectTimeout is applied when connecting a TCP socket to the target host.The default value is 10 seconds.
-
readTimeout
MobonOkHttpClient.Builder readTimeout(long timeout, TimeUnit unit)
Sets the default read timeout for new connections. A value of 0 means no timeout, otherwisevalues must be between 1 and MAX_VALUE when converted to milliseconds.
The read timeout is applied to both the TCP socket and for individual read IO operationsincluding on Source of the MobonResponse. The default value is 10 seconds.
-
writeTimeout
MobonOkHttpClient.Builder writeTimeout(long timeout, TimeUnit unit)
Sets the default write timeout for new connections. A value of 0 means no timeout, otherwisevalues must be between 1 and MAX_VALUE when converted to milliseconds.
The write timeout is applied for individual write IO operations.The default value is 10 seconds.
-
pingInterval
MobonOkHttpClient.Builder pingInterval(long interval, TimeUnit unit)
Sets the interval between HTTP/2 and web socket pings initiated by this client. Use this toautomatically send ping frames until either the connection fails or it is closed. This keepsthe connection alive and may detect connectivity failures.
If the server does not respond to each ping with a pong within
{@code interval}, thisclient will assume that connectivity has been lost. When this happens on a web socket theconnection is canceled and its listener is notified of the failure. When it happens on an HTTP/2 connection the connection is closed and anycalls it is carrying will fail with an IOException.The default value of 0 disables client-initiated pings.
-
proxy
MobonOkHttpClient.Builder proxy(@Nullable() Proxy proxy)
Sets the HTTP proxy that will be used by connections created by this client. This takesprecedence over proxySelector, which is only honored when this proxy is null (whichit is by default). To disable proxy use completely, call
{@code proxy(Proxy.NO_PROXY)}.
-
proxySelector
MobonOkHttpClient.Builder proxySelector(ProxySelector proxySelector)
Sets the proxy selection policy to be used if no proxy is specifiedexplicitly. The proxy selector may return multiple proxies; in that case they will be triedin sequence until a successful connection is established.
If unset, the system-wide default proxy selector willbe used.
-
cookieJar
MobonOkHttpClient.Builder cookieJar(CookieJar cookieJar)
Sets the handler that can accept cookies from incoming HTTP responses and provides cookies tooutgoing HTTP requests.
If unset, no cookies will be accepted nor provided.
-
cache
MobonOkHttpClient.Builder cache(@Nullable() Cache cache)
Sets the response cache to be used to read and write cached responses.
-
dns
MobonOkHttpClient.Builder dns(Dns dns)
Sets the DNS service used to lookup IP addresses for hostnames.
If unset, the system-wide default DNS will be used.
-
socketFactory
MobonOkHttpClient.Builder socketFactory(SocketFactory socketFactory)
Sets the socket factory used to create connections. OkHttp only uses the parameterless createSocket() method to create unconnected sockets. Overridingthis method, e. g., allows the socket to be bound to a specific local address.
If unset, the system-wide default socket factory willbe used.
-
sslSocketFactory
MobonOkHttpClient.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory)
Sets the socket factory used to secure HTTPS connections. If unset, the system default willbe used.
-
sslSocketFactory
MobonOkHttpClient.Builder sslSocketFactory(SSLSocketFactory sslSocketFactory, X509TrustManager trustManager)
Sets the socket factory and trust manager used to secure HTTPS connections. If unset, thesystem defaults will be used.
Most applications should not call this method, and instead use the system defaults. Thoseclasses include special optimizations that can be lost if the implementations are decorated.
If necessary, you can create and configure the defaults yourself with the following code:
{@code * * TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance( * TrustManagerFactory.getDefaultAlgorithm()); * trustManagerFactory.init((KeyStore) null); * TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); * if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) { * throw new IllegalStateException("Unexpected default trust managers:" * + Arrays.toString(trustManagers)); * } * X509TrustManager trustManager = (X509TrustManager) trustManagers[0]; * * SSLContext sslContext = SSLContext.getInstance("TLS"); * sslContext.init(null, new TrustManager[] { trustManager }, null); * SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory(); * * MobonOkHttpClient client = new MobonOkHttpClient.Builder() * .sslSocketFactory(sslSocketFactory, trustManager) * .build(); * }
-
hostnameVerifier
MobonOkHttpClient.Builder hostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the verifier used to confirm that response certificates apply to requested hostnames forHTTPS connections.
If unset, a default hostname verifier will be used.
-
certificatePinner
MobonOkHttpClient.Builder certificatePinner(CertificatePinner certificatePinner)
Sets the certificate pinner that constrains which certificates are trusted. By default HTTPSconnections rely on only the SSL socket factory to establish trust.Pinning certificates avoids the need to trust certificate authorities.
-
authenticator
MobonOkHttpClient.Builder authenticator(Authenticator authenticator)
Sets the authenticator used to respond to challenges from origin servers. Use to set the authenticator for proxy servers.
If unset, the no authentication will be attempted.
-
proxyAuthenticator
MobonOkHttpClient.Builder proxyAuthenticator(Authenticator proxyAuthenticator)
Sets the authenticator used to respond to challenges from proxy servers. Use to set the authenticator for origin servers.
If unset, the no authentication will be attempted.
-
connectionPool
MobonOkHttpClient.Builder connectionPool(ConnectionPool connectionPool)
Sets the connection pool used to recycle HTTP and HTTPS connections.
If unset, a new connection pool will be used.
-
followSslRedirects
MobonOkHttpClient.Builder followSslRedirects(boolean followProtocolRedirects)
Configure this client to follow redirects from HTTPS to HTTP and from HTTP to HTTPS.
If unset, protocol redirects will be followed. This is different than the built-in
{@code * HttpURLConnection}'s default.
-
followRedirects
MobonOkHttpClient.Builder followRedirects(boolean followRedirects)
Configure this client to follow redirects. If unset, redirects will be followed.
-
retryOnConnectionFailure
MobonOkHttpClient.Builder retryOnConnectionFailure(boolean retryOnConnectionFailure)
Configure this client to retry or not when a connectivity problem is encountered. By default,this client silently recovers from the following problems:
- Unreachable IP addresses. If the URL's host has multiple IP addresses,failure to reach any individual IP address doesn't fail the overall mobonRequest. This canincrease availability of multi-homed services.
- Stale pooled connections. The ConnectionPool reuses socketsto decrease mobonRequest latency, but these connections will occasionally time out.
- Unreachable proxy servers. A ProxySelector can be used toattempt multiple proxy servers in sequence, eventually falling back to a directconnection.
-
dispatcher
MobonOkHttpClient.Builder dispatcher(Dispatcher dispatcher)
Sets the dispatcher used to set policy and execute asynchronous requests. Must not be null.
-
protocols
MobonOkHttpClient.Builder protocols(List<Protocol> protocols)
Configure the protocols used by this client to communicate with remote servers. By defaultthis client will prefer the most efficient transport available, falling back to moreubiquitous protocols. Applications should only call this method to avoid specificcompatibility problems, such as web servers that behave incorrectly when HTTP/2 is enabled.
The following protocols are currently supported:
This is an evolving set. Future releases include support for transitionalprotocols. The http/1.1 transport will never be dropped.
If multiple protocols are specified, ALPN will be used tonegotiate a transport. Protocol negotiation is only attempted for HTTPS URLs.
HTTP_1_0 is not supported in this set. Requests are initiated with
{@code * HTTP/1.1}. If the server responds with{@code HTTP/1.0}, that will be exposed by .- Parameters:
protocols- the protocols to use, in order of preference.
-
connectionSpecs
MobonOkHttpClient.Builder connectionSpecs(List<ConnectionSpec> connectionSpecs)
-
interceptors
List<Interceptor> interceptors()
Returns a modifiable list of interceptors that observe the full span of each call: frombefore the connection is established (if any) until after the response source is selected(either the origin server, cache, or both).
-
addInterceptor
MobonOkHttpClient.Builder addInterceptor(Interceptor interceptor)
-
networkInterceptors
List<Interceptor> networkInterceptors()
Returns a modifiable list of interceptors that observe a single network mobonRequest and response.These interceptors must call proceed exactly once: it is an errorfor a network interceptor to short-circuit or repeat a network mobonRequest.
-
addNetworkInterceptor
MobonOkHttpClient.Builder addNetworkInterceptor(Interceptor interceptor)
-
eventListener
MobonOkHttpClient.Builder eventListener(EventListener eventListener)
Configure a single client scoped listener that will receive all analytic eventsfor this client.
-
eventListenerFactory
MobonOkHttpClient.Builder eventListenerFactory(EventListener.Factory eventListenerFactory)
Configure a factory to provide per-call scoped listeners that will receive analytic eventsfor this client.
-
build
MobonOkHttpClient build()
-
-
-
-