Class NetHttpTransport.Builder (1.43.2)

public static final class NetHttpTransport.Builder

Builder for NetHttpTransport.

Implementation is not thread-safe.

Inheritance

java.lang.Object > NetHttpTransport.Builder

Constructors

Builder()

public Builder()

Methods

build()

public NetHttpTransport build()

Returns a new instance of NetHttpTransport based on the options.

Returns
Type Description
NetHttpTransport

doNotValidateCertificate()

public NetHttpTransport.Builder doNotValidateCertificate()

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

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

Returns
Type Description
NetHttpTransport.Builder
Exceptions
Type Description
GeneralSecurityException

getHostnameVerifier()

public HostnameVerifier getHostnameVerifier()

Returns the host name verifier or null for the default.

Returns
Type Description
HostnameVerifier

getSslSocketFactory()

public SSLSocketFactory getSslSocketFactory()

Returns the SSL socket factory.

Returns
Type Description
SSLSocketFactory

setConnectionFactory(ConnectionFactory connectionFactory)

public NetHttpTransport.Builder setConnectionFactory(ConnectionFactory connectionFactory)

Sets the ConnectionFactory or null to use a DefaultConnectionFactory. This value is ignored if the #setProxy has been called with a non-null value.

If you wish to use a Proxy, it should be included in your ConnectionFactory implementation.

Parameter
Name Description
connectionFactory ConnectionFactory
Returns
Type Description
NetHttpTransport.Builder

setHostnameVerifier(HostnameVerifier hostnameVerifier)

public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)

Sets the host name verifier or null for the default.

Parameter
Name Description
hostnameVerifier HostnameVerifier
Returns
Type Description
NetHttpTransport.Builder

setProxy(Proxy proxy)

public NetHttpTransport.Builder setProxy(Proxy proxy)

Sets the HTTP proxy or null to use the proxy settings from system properties.

For example:

setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)))

Parameter
Name Description
proxy Proxy
Returns
Type Description
NetHttpTransport.Builder

setSslSocketFactory(SSLSocketFactory sslSocketFactory)

public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)

Sets the SSL socket factory or null for the default.

Parameter
Name Description
sslSocketFactory SSLSocketFactory
Returns
Type Description
NetHttpTransport.Builder

trustCertificates(KeyStore trustStore)

public NetHttpTransport.Builder trustCertificates(KeyStore trustStore)

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

Parameter
Name Description
trustStore KeyStore

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

Returns
Type Description
NetHttpTransport.Builder
Exceptions
Type Description
GeneralSecurityException

trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword)

public NetHttpTransport.Builder trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword)

Beta
Sets the SSL socket factory based on a root certificate trust store and a client certificate key store. The client certificate key store will be used to establish mutual TLS.

Parameters
Name Description
trustStore KeyStore

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

mtlsKeyStore KeyStore

key store for client certificate and key to establish mutual TLS. (use for example SecurityUtils#createMtlsKeyStore(InputStream))

mtlsKeyStorePassword String

password for mtlsKeyStore parameter

Returns
Type Description
NetHttpTransport.Builder
Exceptions
Type Description
GeneralSecurityException

trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)

public NetHttpTransport.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
Name Description
keyStoreStream InputStream

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

storePass String

password protecting the key store file

Returns
Type Description
NetHttpTransport.Builder
Exceptions
Type Description
GeneralSecurityException
IOException

trustCertificatesFromStream(InputStream certificateStream)

public NetHttpTransport.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
Name Description
certificateStream InputStream

certificate stream

Returns
Type Description
NetHttpTransport.Builder
Exceptions
Type Description
GeneralSecurityException
IOException