Class NetHttpTransport.Builder (1.43.0)

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
TypeDescription
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
TypeDescription
NetHttpTransport.Builder
Exceptions
TypeDescription
GeneralSecurityException

getHostnameVerifier()

public HostnameVerifier getHostnameVerifier()

Returns the host name verifier or null for the default.

Returns
TypeDescription
HostnameVerifier

getSslSocketFactory()

public SSLSocketFactory getSslSocketFactory()

Returns the SSL socket factory.

Returns
TypeDescription
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
NameDescription
connectionFactoryConnectionFactory
Returns
TypeDescription
NetHttpTransport.Builder

setHostnameVerifier(HostnameVerifier hostnameVerifier)

public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)

Sets the host name verifier or null for the default.

Parameter
NameDescription
hostnameVerifierHostnameVerifier
Returns
TypeDescription
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
NameDescription
proxyProxy
Returns
TypeDescription
NetHttpTransport.Builder

setSslSocketFactory(SSLSocketFactory sslSocketFactory)

public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)

Sets the SSL socket factory or null for the default.

Parameter
NameDescription
sslSocketFactorySSLSocketFactory
Returns
TypeDescription
NetHttpTransport.Builder

trustCertificates(KeyStore trustStore)

public NetHttpTransport.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
NetHttpTransport.Builder
Exceptions
TypeDescription
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
NameDescription
trustStoreKeyStore

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

mtlsKeyStoreKeyStore

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

mtlsKeyStorePasswordString

password for mtlsKeyStore parameter

Returns
TypeDescription
NetHttpTransport.Builder
Exceptions
TypeDescription
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
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
NetHttpTransport.Builder
Exceptions
TypeDescription
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
NameDescription
certificateStreamInputStream

certificate stream

Returns
TypeDescription
NetHttpTransport.Builder
Exceptions
TypeDescription
GeneralSecurityException
IOException