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 |
doNotValidateCertificate()
Beta
Disables validating server SSL certificates by setting the SSL socket factory using SslUtils for the SSL context and
SslUtils 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 |
setConnectionFactory(ConnectionFactory
|
NetHttpTransport |
setHostnameVerifier(HostnameVerifier
Sets the host name verifier or
null for the default.
|
NetHttpTransport |
setProxy(Proxy
Sets the HTTP proxy or
null to use the proxy settings from
system properties.
|
NetHttpTransport |
setSslSocketFactory(SSLSocketFactory
Sets the SSL socket factory or
null for the default.
|
NetHttpTransport |
trustCertificates(KeyStore
Sets the SSL socket factory based on a root certificate trust store.
|
NetHttpTransport |
trustCertificatesFromJavaKeyStore(InputStream
Sets the SSL socket factory based on root certificates in a Java KeyStore.
|
NetHttpTransport |
trustCertificatesFromStream(InputStream
Sets the SSL socket factory based root certificates generated from the specified stream using
CertificateFactory.
|
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 file
GeneralSecurityException
IOException
public NetHttpTransport.Builder trustCertificatesFromStream(InputStream certificateStream) throws GeneralSecurityException , IOException
CertificateFactory.generateCertificates(InputStream) .
Example usage:
trustCertificatesFromStream(new FileInputStream("certs.pem"));
certificateStream - certificate stream
GeneralSecurityException
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 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 SSLSocketFactorygetSslSocketFactory()
public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)
null for the default.
public HostnameVerifiergetHostnameVerifier()
null for the default.
public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)
null for the default.
public NetHttpTransportbuild()
NetHttpTransport based on the options.