public static final class NetHttpTransport.Builder extends Object
NetHttpTransport
.
Implementation is not thread-safe.
Constructor and Description |
---|
Builder() |
Modifier and Type | Method and Description |
---|---|
NetHttpTransport |
build()
Returns a new instance of
NetHttpTransport based on the options. |
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. |
HostnameVerifier |
getHostnameVerifier()
Returns the host name verifier or
null for the default. |
SSLSocketFactory |
getSslSocketFactory()
Returns the SSL socket factory.
|
NetHttpTransport.Builder |
setConnectionFactory(ConnectionFactory connectionFactory)
|
NetHttpTransport.Builder |
setHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the host name verifier or
null for the default. |
NetHttpTransport.Builder |
setProxy(Proxy proxy)
Sets the HTTP proxy or
null to use the proxy settings from system
properties. |
NetHttpTransport.Builder |
setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Sets the SSL socket factory or
null for the default. |
NetHttpTransport.Builder |
trustCertificates(KeyStore trustStore)
Sets the SSL socket factory based on a root certificate trust store.
|
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. |
NetHttpTransport.Builder |
trustCertificatesFromJavaKeyStore(InputStream keyStoreStream,
String storePass)
Sets the SSL socket factory based on root certificates in a Java KeyStore.
|
NetHttpTransport.Builder |
trustCertificatesFromStream(InputStream certificateStream)
Sets the SSL socket factory based root certificates generated from the specified stream using
CertificateFactory.generateCertificates(InputStream) . |
public NetHttpTransport.Builder setProxy(Proxy proxy)
null
to use the proxy settings from system
properties.
For example:
setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)))
public NetHttpTransport.Builder setConnectionFactory(ConnectionFactory connectionFactory)
ConnectionFactory
or null
to use a DefaultConnectionFactory
.
This value is ignored if the setProxy(java.net.Proxy)
has been called with a non-null value.
If you wish to use a Proxy
, it should be included in your ConnectionFactory
implementation.
public NetHttpTransport.Builder trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass) throws GeneralSecurityException, IOException
Example usage:
trustCertificatesFromJavaKeyStore(new FileInputStream("certs.jks"), "password");
keyStoreStream
- input stream to the key store (closed at the end of this method in a
finally block)storePass
- password protecting the key store fileGeneralSecurityException
IOException
public NetHttpTransport.Builder trustCertificatesFromStream(InputStream certificateStream) throws GeneralSecurityException, IOException
CertificateFactory.generateCertificates(InputStream)
.
Example usage:
trustCertificatesFromStream(new FileInputStream("certs.pem"));
certificateStream
- certificate streamGeneralSecurityException
IOException
public NetHttpTransport.Builder trustCertificates(KeyStore trustStore) throws GeneralSecurityException
trustStore
- certificate trust store (use for example SecurityUtils.loadKeyStore(java.security.KeyStore, java.io.InputStream, java.lang.String)
or SecurityUtils.loadKeyStoreFromCertificates(java.security.KeyStore, java.security.cert.CertificateFactory, java.io.InputStream)
)GeneralSecurityException
@Beta public NetHttpTransport.Builder trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword) throws GeneralSecurityException
Beta
trustStore
- certificate trust store (use for example SecurityUtils.loadKeyStore(java.security.KeyStore, java.io.InputStream, java.lang.String)
or SecurityUtils.loadKeyStoreFromCertificates(java.security.KeyStore, java.security.cert.CertificateFactory, java.io.InputStream)
)mtlsKeyStore
- key store for client certificate and key to establish mutual TLS. (use
for example SecurityUtils.createMtlsKeyStore(InputStream)
)mtlsKeyStorePassword
- password for mtlsKeyStore parameterGeneralSecurityException
@Beta public NetHttpTransport.Builder doNotValidateCertificate() throws GeneralSecurityException
Beta
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.
GeneralSecurityException
public SSLSocketFactory getSslSocketFactory()
public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)
null
for the default.public HostnameVerifier getHostnameVerifier()
null
for the default.public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)
null
for the default.public NetHttpTransport build()
NetHttpTransport
based on the options.Copyright © 2011–2023 Google. All rights reserved.