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.ObjectBuilder forNetHttpTransport.Implementation is not thread-safe.
- Since:
- 1.13
-
-
Field Summary
Fields Modifier and Type Field Description private ConnectionFactoryconnectionFactoryConnectionFactoryornullto use a DefaultConnectionFactory.private javax.net.ssl.HostnameVerifierhostnameVerifierHost name verifier ornullfor the default.private java.net.ProxyproxyHTTP proxy ornullto use the proxy settings from system properties.private javax.net.ssl.SSLSocketFactorysslSocketFactorySSL socket factory ornullfor the default.
-
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.javax.net.ssl.HostnameVerifiergetHostnameVerifier()Returns the host name verifier ornullfor the default.javax.net.ssl.SSLSocketFactorygetSslSocketFactory()Returns the SSL socket factory.NetHttpTransport.BuildersetConnectionFactory(ConnectionFactory connectionFactory)NetHttpTransport.BuildersetHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)Sets the host name verifier ornullfor the default.NetHttpTransport.BuildersetProxy(java.net.Proxy proxy)Sets the HTTP proxy ornullto use the proxy settings from system properties.NetHttpTransport.BuildersetSslSocketFactory(javax.net.ssl.SSLSocketFactory sslSocketFactory)Sets the SSL socket factory ornullfor the default.NetHttpTransport.BuildertrustCertificates(java.security.KeyStore trustStore)Sets the SSL socket factory based on a root certificate trust store.NetHttpTransport.BuildertrustCertificatesFromJavaKeyStore(java.io.InputStream keyStoreStream, java.lang.String storePass)Sets the SSL socket factory based on root certificates in a Java KeyStore.NetHttpTransport.BuildertrustCertificatesFromStream(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 ornullfor the default.
-
hostnameVerifier
private javax.net.ssl.HostnameVerifier hostnameVerifier
Host name verifier ornullfor the default.
-
proxy
private java.net.Proxy proxy
HTTP proxy ornullto use the proxy settings from system properties.
-
connectionFactory
private ConnectionFactory connectionFactory
ConnectionFactoryornullto use a DefaultConnectionFactory. This value is only used if proxy is unset.
-
-
Method Detail
-
setProxy
public NetHttpTransport.Builder setProxy(java.net.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(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.GeneralSecurityExceptionjava.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.GeneralSecurityExceptionjava.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
-
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 ornullfor the default.
-
getHostnameVerifier
public javax.net.ssl.HostnameVerifier getHostnameVerifier()
Returns the host name verifier ornullfor the default.
-
setHostnameVerifier
public NetHttpTransport.Builder setHostnameVerifier(javax.net.ssl.HostnameVerifier hostnameVerifier)
Sets the host name verifier ornullfor the default.
-
build
public NetHttpTransport build()
Returns a new instance ofNetHttpTransportbased on the options.
-
-