public class ClientBuilder
extends java.lang.Object
CloudantClient
instances.
CloudantClient client = ClientBuilder.account("yourCloudantAccount")
.username("yourUsername")
.password("yourPassword")
.build();
CloudantClient client = ClientBuilder.url(new URL("https://yourCloudantLocalAddress.example"))
.username("yourUsername")
.password("yourPassword")
.build();
CloudantClient client = ClientBuilder.account("yourCloudantAccount")
.username("yourUsername")
.password("yourPassword")
.proxyURL(new URL("https://yourProxyServerAddress.example"))
.proxyUser(yourProxyUser)
.proxyPassword(yourProxyPass)
.build();
CloudantClient client = ClientBuilder.account("yourCloudantAccount")
.username("yourUsername")
.password("yourPassword")
.customSSLSocketFactory(...)
.build();
CloudantClient client = ClientBuilder.account("yourCloudantAccount")
.username("yourUsername")
.password("yourPassword")
.connectTimeout(1, TimeUnit.MINUTES)
.readTimeout(1, TimeUnit.MINUTES)
.build();
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_CONNECTION_TIMEOUT
Connection timeout defaults to 5 minutes
|
static int |
DEFAULT_MAX_CONNECTIONS
Default max of 6 connections
|
static long |
DEFAULT_READ_TIMEOUT
Read timeout defaults to 5 minutes
|
Modifier and Type | Method and Description |
---|---|
static ClientBuilder |
account(java.lang.String account)
Constructs a new ClientBuilder for building a CloudantClient instance to connect to the
Cloudant server with the specified account.
|
CloudantClient |
build()
Build the
CloudantClient instance based on the endpoint used to construct this
client builder and the options that have been set on it before calling this method. |
ClientBuilder |
connectTimeout(long connectTimeout,
java.util.concurrent.TimeUnit connectTimeoutUnit)
Sets the specified timeout value when opening the client connection.
|
ClientBuilder |
customSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
Specifies the custom SSLSocketFactory to use when connecting to Cloudant over a
https URL, when SSL authentication is enabled. |
ClientBuilder |
disableSSLAuthentication()
Flag to disable hostname verification and certificate chain validation.
|
ClientBuilder |
gsonBuilder(com.google.gson.GsonBuilder gsonBuilder)
Set a custom GsonBuilder to use when serializing and de-serializing JSON in requests and
responses between the CloudantClient and the server.
|
ClientBuilder |
interceptors(HttpConnectionInterceptor... interceptors)
This method adds
HttpConnectionInterceptor s to be used on the CloudantClient
connection. |
ClientBuilder |
maxConnections(int maxConnections)
Set the maximum number of connections to maintain in the connection pool.
|
ClientBuilder |
password(java.lang.String password)
Sets the password for the client connection.
|
ClientBuilder |
proxyPassword(java.lang.String proxyPassword)
Sets an optional proxy password for the proxy user specified by
proxyUser(String) . |
ClientBuilder |
proxyURL(java.net.URL proxyURL)
Sets a proxy url for the client connection.
|
ClientBuilder |
proxyUser(java.lang.String proxyUser)
Sets an optional proxy username for the client connection.
|
ClientBuilder |
readTimeout(long readTimeout,
java.util.concurrent.TimeUnit readTimeoutUnit)
Sets the specified timeout value when reading from a
InputStream with an
established client connection. |
static ClientBuilder |
url(java.net.URL url)
Constructs a new ClientBuilder for building a CloudantClient instance to connect to the
Cloudant server with the specified URL.
|
ClientBuilder |
username(java.lang.String username)
Sets a username or API key for the client connection.
|
public static final int DEFAULT_MAX_CONNECTIONS
public static final long DEFAULT_CONNECTION_TIMEOUT
public static final long DEFAULT_READ_TIMEOUT
public static ClientBuilder account(java.lang.String account)
account
- the Cloudant account name to connect to e.g. "example" is the account name
for the "example.cloudant.com" endpointjava.lang.IllegalArgumentException
- if the specified account name forms an invalid endpoint URLpublic static ClientBuilder url(java.net.URL url)
url
- server URL e.g. "https://yourCloudantLocalAddress.example"public CloudantClient build()
CloudantClient
instance based on the endpoint used to construct this
client builder and the options that have been set on it before calling this method.CloudantClient
instance for the specified end point and optionspublic ClientBuilder username(java.lang.String username)
username
- the user or API key for the sessionpublic ClientBuilder password(java.lang.String password)
username(String)
method.password
- user password or API key passphrasepublic ClientBuilder gsonBuilder(com.google.gson.GsonBuilder gsonBuilder)
Note: the supplied GsonBuilder will be augmented with some internal TypeAdapters.
gsonBuilder
- the custom GsonBuilder to usepublic ClientBuilder maxConnections(int maxConnections)
Note: this setting only applies if using the optional OkHttp dependency. If OkHttp is not
present then the JVM configuration is used for pooling. Consult the JVM documentation for
the http.maxConnections
property for further details.
DEFAULT_MAX_CONNECTIONS
maxConnections
- the maximum number of simultaneous connections to open to the serverpublic ClientBuilder proxyURL(java.net.URL proxyURL)
proxyURL
- the URL of the proxy serverpublic ClientBuilder proxyUser(java.lang.String proxyUser)
proxyUser
- username for the proxy serverpublic ClientBuilder proxyPassword(java.lang.String proxyPassword)
proxyUser(String)
.proxyPassword
- password for the proxy server userpublic ClientBuilder disableSSLAuthentication()
The SSL authentication is enabled by default meaning that hostname verification and certificate chain validation is done using the JVM default settings.
java.lang.IllegalStateException
- if customSSLSocketFactory(SSLSocketFactory)
has been called on this ClientBuildercustomSSLSocketFactory(SSLSocketFactory)
public ClientBuilder customSSLSocketFactory(javax.net.ssl.SSLSocketFactory factory)
https
URL, when SSL authentication is enabled.factory
- An SSLSocketFactory, or null
for the
default SSLSocketFactory of the JRE.java.lang.IllegalStateException
- if disableSSLAuthentication()
has been called on this ClientBuilderdisableSSLAuthentication()
public ClientBuilder interceptors(HttpConnectionInterceptor... interceptors)
HttpConnectionInterceptor
s to be used on the CloudantClient
connection. Interceptors can be used to modify the HTTP requests and responses between the
CloudantClient and the server.
An example interceptor use might be to apply a custom authorization mechanism. For
instance to use BasicAuth instead of CookieAuth it is possible to use a
BasicAuthInterceptor
that adds the BasicAuth
Authorization
header to the request:
CloudantClient client = ClientBuilder.account("yourCloudantAccount")
.interceptors(new BasicAuthInterceptor("yourUsername:yourPassword"))
.build()
interceptors
- one or more HttpConnectionInterceptor objectsHttpConnectionInterceptor
public ClientBuilder connectTimeout(long connectTimeout, java.util.concurrent.TimeUnit connectTimeoutUnit)
SocketTimeoutException
is raised.
Example creating a CloudantClient
with a connection timeout of 2 seconds:
CloudantClient client = ClientBuilder.account("yourCloudantAccount")
.username("yourUsername")
.password("yourPassword")
.connectTimeout(2, TimeUnit.SECONDS)
.build();
Defaults to DEFAULT_CONNECTION_TIMEOUT
with TimeUnit.MINUTES
.connectTimeout
- duration of the read timeoutconnectTimeoutUnit
- unit of measurement of the read timeout parameterURLConnection.setConnectTimeout(int)
public ClientBuilder readTimeout(long readTimeout, java.util.concurrent.TimeUnit readTimeoutUnit)
InputStream
with an
established client connection. If the timeout expires before there is data available for
read, a SocketTimeoutException
is raised.
Example creating a CloudantClient
with a read timeout of 2 seconds:
CloudantClient client = ClientBuilder.account("yourCloudantAccount")
.username("yourUsername")
.password("yourPassword")
.readTimeout(2, TimeUnit.SECONDS)
.build();
Defaults to DEFAULT_READ_TIMEOUT
with TimeUnit.MINUTES
.readTimeout
- duration of the read timeoutreadTimeoutUnit
- unit of measurement of the read timeout parameterURLConnection.setReadTimeout(int)