public static final class NetHttpTransport.Builder
Constructors
Builder()
public Builder()
Methods
build()
public NetHttpTransport build()
Returns a new instance of NetHttpTransport based on the options.
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.
Type | Description |
NetHttpTransport.Builder |
Type | Description |
GeneralSecurityException |
getHostnameVerifier()
public HostnameVerifier getHostnameVerifier()
Returns the host name verifier or null
for the default.
Type | Description |
HostnameVerifier |
getSslSocketFactory()
public SSLSocketFactory getSslSocketFactory()
Returns the SSL socket factory.
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.
Name | Description |
connectionFactory | ConnectionFactory |
Type | Description |
NetHttpTransport.Builder |
setHostnameVerifier(HostnameVerifier hostnameVerifier)
public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the host name verifier or null
for the default.
Name | Description |
hostnameVerifier | HostnameVerifier |
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)))
Name | Description |
proxy | Proxy |
Type | Description |
NetHttpTransport.Builder |
setSslSocketFactory(SSLSocketFactory sslSocketFactory)
public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Sets the SSL socket factory or null
for the default.
Name | Description |
sslSocketFactory | SSLSocketFactory |
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.
Name | Description |
trustStore | KeyStore certificate trust store (use for example SecurityUtils#loadKeyStore or SecurityUtils#loadKeyStoreFromCertificates) |
Type | Description |
NetHttpTransport.Builder |
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.
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 |
Type | Description |
NetHttpTransport.Builder |
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");
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 |
Type | Description |
NetHttpTransport.Builder |
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"));
Name | Description |
certificateStream | InputStream certificate stream |
Type | Description |
NetHttpTransport.Builder |
Type | Description |
GeneralSecurityException | |
IOException |