Class ApacheHttpTransport.Builder (1.42.3)

public static final class ApacheHttpTransport.Builder

Builder for ApacheHttpTransport.

Implementation is not thread-safe.

Inheritance

java.lang.Object > ApacheHttpTransport.Builder

Constructors

Builder()

public Builder()

Methods

build()

public ApacheHttpTransport build()

Returns a new instance of ApacheHttpTransport based on the options.

Returns
TypeDescription
ApacheHttpTransport

doNotValidateCertificate()

public ApacheHttpTransport.Builder doNotValidateCertificate()

Beta
Disables validating server SSL certificates by setting the SSL socket factory using SslUtils#trustAllSSLContext() for the SSL context and SSLSocketFactory#ALLOW_ALL_HOSTNAME_VERIFIER for the host name verifier.

Be careful! Disabling certificate validation is dangerous and should only be done in testing environments.

Returns
TypeDescription
ApacheHttpTransport.Builder
Exceptions
TypeDescription
GeneralSecurityException

getHttpParams()

public HttpParams getHttpParams()

Returns the HTTP parameters.

Returns
TypeDescription
org.apache.http.params.HttpParams

getSSLSocketFactory()

public SSLSocketFactory getSSLSocketFactory()

Returns the SSL socket factory (SSLSocketFactory#getSocketFactory() by default).

Returns
TypeDescription
org.apache.http.conn.ssl.SSLSocketFactory

setProxy(HttpHost proxy)

public ApacheHttpTransport.Builder setProxy(HttpHost proxy)

Sets the HTTP proxy to use DefaultHttpRoutePlanner or null to use #setProxySelector(ProxySelector) with ProxySelector#getDefault().

By default it is null, which uses the proxy settings from system properties.

For example:

setProxy(new HttpHost("127.0.0.1", 8080))

Parameter
NameDescription
proxyorg.apache.http.HttpHost
Returns
TypeDescription
ApacheHttpTransport.Builder

setProxySelector(ProxySelector proxySelector)

public ApacheHttpTransport.Builder setProxySelector(ProxySelector proxySelector)

Sets the HTTP proxy selector to use ProxySelectorRoutePlanner or null for DefaultHttpRoutePlanner.

By default it is ProxySelector#getDefault() which uses the proxy settings from system properties.

Parameter
NameDescription
proxySelectorProxySelector
Returns
TypeDescription
ApacheHttpTransport.Builder

setSocketFactory(SSLSocketFactory socketFactory)

public ApacheHttpTransport.Builder setSocketFactory(SSLSocketFactory socketFactory)

Sets the SSL socket factory (SSLSocketFactory#getSocketFactory() by default).

Parameter
NameDescription
socketFactoryorg.apache.http.conn.ssl.SSLSocketFactory
Returns
TypeDescription
ApacheHttpTransport.Builder

trustCertificates(KeyStore trustStore)

public ApacheHttpTransport.Builder trustCertificates(KeyStore trustStore)

Sets the SSL socket factory based on a root certificate trust store.

Parameter
NameDescription
trustStoreKeyStore

certificate trust store (use for example SecurityUtils#loadKeyStore or SecurityUtils#loadKeyStoreFromCertificates)

Returns
TypeDescription
ApacheHttpTransport.Builder
Exceptions
TypeDescription
GeneralSecurityException

trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)

public ApacheHttpTransport.Builder trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)

Sets the SSL socket factory based on root certificates in a Java KeyStore.

Example usage:

trustCertificatesFromJavaKeyStore(new FileInputStream("certs.jks"), "password");

Parameters
NameDescription
keyStoreStreamInputStream

input stream to the key store (closed at the end of this method in a finally block)

storePassString

password protecting the key store file

Returns
TypeDescription
ApacheHttpTransport.Builder
Exceptions
TypeDescription
GeneralSecurityException
IOException

trustCertificatesFromStream(InputStream certificateStream)

public ApacheHttpTransport.Builder trustCertificatesFromStream(InputStream certificateStream)

Sets the SSL socket factory based root certificates generated from the specified stream using CertificateFactory#generateCertificates(InputStream).

Example usage:

trustCertificatesFromStream(new FileInputStream("certs.pem"));

Parameter
NameDescription
certificateStreamInputStream

certificate stream

Returns
TypeDescription
ApacheHttpTransport.Builder
Exceptions
TypeDescription
GeneralSecurityException
IOException