Class NetHttpTransport.Builder
java.lang.Object
com.google.api.client.http.javanet.NetHttpTransport.Builder
- Enclosing class:
NetHttpTransport
Builder for
NetHttpTransport.
Implementation is not thread-safe.
- Since:
- 1.13
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ConnectionFactoryConnectionFactoryornullto use a DefaultConnectionFactory.private HostnameVerifierHost name verifier ornullfor the default.private booleanWhether the transport is mTLS.private ProxyHTTP proxy ornullto use the proxy settings from system properties.private SSLSocketFactorySSL socket factory ornullfor the default. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Returns a new instance ofNetHttpTransportbased on the options.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.Returns the host name verifier ornullfor the default.Returns the SSL socket factory.setConnectionFactory(ConnectionFactory connectionFactory) setHostnameVerifier(HostnameVerifier hostnameVerifier) Sets the host name verifier ornullfor the default.Sets the HTTP proxy ornullto use the proxy settings from system properties.setSslSocketFactory(SSLSocketFactory sslSocketFactory) Sets the SSL socket factory ornullfor the default.trustCertificates(KeyStore trustStore) Sets the SSL socket factory based on a root certificate trust store.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.trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass) Sets the SSL socket factory based on root certificates in a Java KeyStore.trustCertificatesFromStream(InputStream certificateStream) Sets the SSL socket factory based root certificates generated from the specified stream usingCertificateFactory.generateCertificates(InputStream).
-
Field Details
-
sslSocketFactory
SSL socket factory ornullfor the default. -
hostnameVerifier
Host name verifier ornullfor the default. -
proxy
HTTP proxy ornullto use the proxy settings from system properties. -
connectionFactory
ConnectionFactoryornullto use a DefaultConnectionFactory. This value is only used if proxy is unset. -
isMtls
private boolean isMtlsWhether the transport is mTLS. Default value isfalse.
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
setProxy
Sets the HTTP proxy ornullto use the proxy settings from system properties.For example:
setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080))) -
setConnectionFactory
Sets theConnectionFactoryornullto use aDefaultConnectionFactory. This value is ignored if thesetProxy(Proxy)has been called with a non-null value.If you wish to use a
Proxy, it should be included in yourConnectionFactoryimplementation.- Since:
- 1.20
-
trustCertificatesFromJavaKeyStore
public NetHttpTransport.Builder trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass) throws GeneralSecurityException, 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:
GeneralSecurityExceptionIOException- Since:
- 1.14
-
trustCertificatesFromStream
public NetHttpTransport.Builder trustCertificatesFromStream(InputStream certificateStream) throws GeneralSecurityException, 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:
GeneralSecurityExceptionIOException- Since:
- 1.14
-
trustCertificates
public NetHttpTransport.Builder trustCertificates(KeyStore trustStore) throws GeneralSecurityException Sets the SSL socket factory based on a root certificate trust store.- Parameters:
trustStore- certificate trust store (use for exampleSecurityUtils.loadKeyStore(KeyStore, InputStream, String)orSecurityUtils.loadKeyStoreFromCertificates(KeyStore, CertificateFactory, InputStream))- Throws:
GeneralSecurityException- Since:
- 1.14
-
trustCertificates
@Beta public NetHttpTransport.Builder trustCertificates(KeyStore trustStore, KeyStore mtlsKeyStore, String mtlsKeyStorePassword) throws 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(KeyStore, InputStream, String)orSecurityUtils.loadKeyStoreFromCertificates(KeyStore, CertificateFactory, InputStream))mtlsKeyStore- key store for client certificate and key to establish mutual TLS. (use for exampleSecurityUtils.createMtlsKeyStore(InputStream))mtlsKeyStorePassword- password for mtlsKeyStore parameter- Throws:
GeneralSecurityException- Since:
- 1.38
-
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.Be careful! Disabling certificate validation is dangerous and should only be done in testing environments.
- Throws:
GeneralSecurityException
-
getSslSocketFactory
Returns the SSL socket factory. -
setSslSocketFactory
Sets the SSL socket factory ornullfor the default. -
getHostnameVerifier
Returns the host name verifier ornullfor the default. -
setHostnameVerifier
Sets the host name verifier ornullfor the default. -
build
Returns a new instance ofNetHttpTransportbased on the options.
-