Class NetHttpTransport.Builder
- java.lang.Object
-
- com.google.api.client.http.javanet.NetHttpTransport.Builder
-
- Enclosing class:
- NetHttpTransport
public static final class NetHttpTransport.Builder extends Object
Builder forNetHttpTransport.Implementation is not thread-safe.
- Since:
- 1.13
-
-
Constructor Summary
Constructors Constructor Description Builder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NetHttpTransportbuild()Returns a new instance ofNetHttpTransportbased on the options.NetHttpTransport.BuilderdoNotValidateCertificate()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.HostnameVerifiergetHostnameVerifier()Returns the host name verifier ornullfor the default.SSLSocketFactorygetSslSocketFactory()Returns the SSL socket factory.NetHttpTransport.BuildersetConnectionFactory(ConnectionFactory connectionFactory)NetHttpTransport.BuildersetHostnameVerifier(HostnameVerifier hostnameVerifier)Sets the host name verifier ornullfor the default.NetHttpTransport.BuildersetProxy(Proxy proxy)Sets the HTTP proxy ornullto use the proxy settings from system properties.NetHttpTransport.BuildersetSslSocketFactory(SSLSocketFactory sslSocketFactory)Sets the SSL socket factory ornullfor the default.NetHttpTransport.BuildertrustCertificates(KeyStore trustStore)Sets the SSL socket factory based on a root certificate trust store.NetHttpTransport.BuildertrustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)Sets the SSL socket factory based on root certificates in a Java KeyStore.NetHttpTransport.BuildertrustCertificatesFromStream(InputStream certificateStream)Sets the SSL socket factory based root certificates generated from the specified stream usingCertificateFactory.generateCertificates(InputStream).
-
-
-
Method Detail
-
setProxy
public NetHttpTransport.Builder setProxy(Proxy proxy)
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
public NetHttpTransport.Builder setConnectionFactory(ConnectionFactory connectionFactory)
Sets theConnectionFactoryornullto 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 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(java.security.KeyStore, java.io.InputStream, java.lang.String)orSecurityUtils.loadKeyStoreFromCertificates(java.security.KeyStore, java.security.cert.CertificateFactory, java.io.InputStream))- Throws:
GeneralSecurityException- Since:
- 1.14
-
doNotValidateCertificate
@Beta public NetHttpTransport.Builder doNotValidateCertificate() throws 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:
GeneralSecurityException
-
getSslSocketFactory
public SSLSocketFactory getSslSocketFactory()
Returns the SSL socket factory.
-
setSslSocketFactory
public NetHttpTransport.Builder setSslSocketFactory(SSLSocketFactory sslSocketFactory)
Sets the SSL socket factory ornullfor the default.
-
getHostnameVerifier
public HostnameVerifier getHostnameVerifier()
Returns the host name verifier ornullfor the default.
-
setHostnameVerifier
public NetHttpTransport.Builder setHostnameVerifier(HostnameVerifier hostnameVerifier)
Sets the host name verifier ornullfor the default.
-
build
public NetHttpTransport build()
Returns a new instance ofNetHttpTransportbased on the options.
-
-