Class NetHttpTransport.Builder
- java.lang.Object
-
- com.google.api.client.http.javanet.NetHttpTransport.Builder
-
- Enclosing class:
- NetHttpTransport
public static final class NetHttpTransport.Builder extends java.lang.Object
Builder forNetHttpTransport
.Implementation is not thread-safe.
- Since:
- 1.13
-
-
Field Summary
Fields Modifier and Type Field Description private ConnectionFactory
connectionFactory
ConnectionFactory
ornull
to use a DefaultConnectionFactory.private javax.net.ssl.HostnameVerifier
hostnameVerifier
Host name verifier ornull
for the default.private boolean
isMtls
Whether the transport is mTLS.private java.net.Proxy
proxy
HTTP proxy ornull
to use the proxy settings from system properties.private javax.net.ssl.SSLSocketFactory
sslSocketFactory
SSL socket factory ornull
for the default.
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NetHttpTransport
build()
Returns a new instance ofNetHttpTransport
based on the options.NetHttpTransport.Builder
doNotValidateCertificate()
Beta
Disables validating server SSL certificates by setting the SSL socket factory usingSslUtils.trustAllSSLContext()
for the SSL context andSslUtils.trustAllHostnameVerifier()
for the host name verifier.javax.net.ssl.HostnameVerifier
getHostnameVerifier()
Returns the host name verifier ornull
for the default.javax.net.ssl.SSLSocketFactory
getSslSocketFactory()
Returns the SSL socket factory.NetHttpTransport.Builder
setConnectionFactory(ConnectionFactory connectionFactory)
NetHttpTransport.Builder
setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
Sets the host name verifier ornull
for the default.NetHttpTransport.Builder
setProxy(java.net.Proxy proxy)
Sets the HTTP proxy ornull
to use the proxy settings from system properties.NetHttpTransport.Builder
setSslSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
Sets the SSL socket factory ornull
for the default.NetHttpTransport.Builder
trustCertificates(java.security.KeyStore trustStore)
Sets the SSL socket factory based on a root certificate trust store.NetHttpTransport.Builder
trustCertificates(java.security.KeyStore trustStore, java.security.KeyStore mtlsKeyStore, java.lang.String mtlsKeyStorePassword)
Beta
Sets the SSL socket factory based on a root certificate trust store and a client certificate key store.NetHttpTransport.Builder
trustCertificatesFromJavaKeyStore(java.io.InputStream keyStoreStream, java.lang.String storePass)
Sets the SSL socket factory based on root certificates in a Java KeyStore.NetHttpTransport.Builder
trustCertificatesFromStream(java.io.InputStream certificateStream)
Sets the SSL socket factory based root certificates generated from the specified stream usingCertificateFactory.generateCertificates(InputStream)
.
-
-
-
Field Detail
-
sslSocketFactory
private javax.net.ssl.SSLSocketFactory sslSocketFactory
SSL socket factory ornull
for the default.
-
hostnameVerifier
private javax.net.ssl.HostnameVerifier hostnameVerifier
Host name verifier ornull
for the default.
-
proxy
private java.net.Proxy proxy
HTTP proxy ornull
to use the proxy settings from system properties.
-
connectionFactory
private ConnectionFactory connectionFactory
ConnectionFactory
ornull
to use a DefaultConnectionFactory. This value is only used if proxy is unset.
-
isMtls
private boolean isMtls
Whether the transport is mTLS. Default value isfalse
.
-
-
Method Detail
-
setProxy
public NetHttpTransport.Builder setProxy(java.net.Proxy proxy)
Sets the HTTP proxy ornull
to use the proxy settings from system properties.For example:
setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080)))
-
setConnectionFactory
public NetHttpTransport.Builder setConnectionFactory(ConnectionFactory connectionFactory)
Sets theConnectionFactory
ornull
to use aDefaultConnectionFactory
. This value is ignored if thesetProxy(java.net.Proxy)
has been called with a non-null value.If you wish to use a
Proxy
, it should be included in yourConnectionFactory
implementation.- Since:
- 1.20
-
trustCertificatesFromJavaKeyStore
public NetHttpTransport.Builder trustCertificatesFromJavaKeyStore(java.io.InputStream keyStoreStream, java.lang.String storePass) throws java.security.GeneralSecurityException, java.io.IOException
Sets the SSL socket factory based on root certificates in a Java KeyStore.Example usage:
trustCertificatesFromJavaKeyStore(new FileInputStream("certs.jks"), "password");
- Parameters:
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- Throws:
java.security.GeneralSecurityException
java.io.IOException
- Since:
- 1.14
-
trustCertificatesFromStream
public NetHttpTransport.Builder trustCertificatesFromStream(java.io.InputStream certificateStream) throws java.security.GeneralSecurityException, java.io.IOException
Sets the SSL socket factory based root certificates generated from the specified stream usingCertificateFactory.generateCertificates(InputStream)
.Example usage:
trustCertificatesFromStream(new FileInputStream("certs.pem"));
- Parameters:
certificateStream
- certificate stream- Throws:
java.security.GeneralSecurityException
java.io.IOException
- Since:
- 1.14
-
trustCertificates
public NetHttpTransport.Builder trustCertificates(java.security.KeyStore trustStore) throws java.security.GeneralSecurityException
Sets the SSL socket factory based on a root certificate trust store.- Parameters:
trustStore
- certificate trust store (use for exampleSecurityUtils.loadKeyStore(java.security.KeyStore, java.io.InputStream, java.lang.String)
orSecurityUtils.loadKeyStoreFromCertificates(java.security.KeyStore, java.security.cert.CertificateFactory, java.io.InputStream)
)- Throws:
java.security.GeneralSecurityException
- Since:
- 1.14
-
trustCertificates
@Beta public NetHttpTransport.Builder trustCertificates(java.security.KeyStore trustStore, java.security.KeyStore mtlsKeyStore, java.lang.String mtlsKeyStorePassword) throws java.security.GeneralSecurityException
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:
trustStore
- certificate trust store (use for exampleSecurityUtils.loadKeyStore(java.security.KeyStore, java.io.InputStream, java.lang.String)
orSecurityUtils.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 exampleSecurityUtils.createMtlsKeyStore(InputStream)
)mtlsKeyStorePassword
- password for mtlsKeyStore parameter- Throws:
java.security.GeneralSecurityException
- Since:
- 1.38
-
doNotValidateCertificate
@Beta public NetHttpTransport.Builder doNotValidateCertificate() throws java.security.GeneralSecurityException
Beta
Disables validating server SSL certificates by setting the SSL socket factory usingSslUtils.trustAllSSLContext()
for the SSL context andSslUtils.trustAllHostnameVerifier()
for the host name verifier.Be careful! Disabling certificate validation is dangerous and should only be done in testing environments.
- Throws:
java.security.GeneralSecurityException
-
getSslSocketFactory
public javax.net.ssl.SSLSocketFactory getSslSocketFactory()
Returns the SSL socket factory.
-
setSslSocketFactory
public NetHttpTransport.Builder setSslSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)
Sets the SSL socket factory ornull
for the default.
-
getHostnameVerifier
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
Returns the host name verifier ornull
for the default.
-
setHostnameVerifier
public NetHttpTransport.Builder setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
Sets the host name verifier ornull
for the default.
-
build
public NetHttpTransport build()
Returns a new instance ofNetHttpTransport
based on the options.
-
-