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 ConnectionFactory
ConnectionFactory
ornull
to use a DefaultConnectionFactory.private HostnameVerifier
Host name verifier ornull
for the default.private Proxy
HTTP proxy ornull
to use the proxy settings from system properties.private SSLSocketFactory
SSL socket factory ornull
for the default. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Returns a new instance ofNetHttpTransport
based 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 ornull
for the default.Returns the SSL socket factory.setConnectionFactory
(ConnectionFactory connectionFactory) setHostnameVerifier
(HostnameVerifier hostnameVerifier) Sets the host name verifier ornull
for the default.Sets the HTTP proxy ornull
to use the proxy settings from system properties.setSslSocketFactory
(SSLSocketFactory sslSocketFactory) Sets the SSL socket factory ornull
for the default.trustCertificates
(KeyStore trustStore) Sets the SSL socket factory based on a root certificate trust 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 ornull
for the default. -
hostnameVerifier
Host name verifier ornull
for the default. -
proxy
HTTP proxy ornull
to use the proxy settings from system properties. -
connectionFactory
ConnectionFactory
ornull
to use a DefaultConnectionFactory. This value is only used if proxy is unset.
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
setProxy
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
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(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:
GeneralSecurityException
IOException
- 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:
GeneralSecurityException
IOException
- 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
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 ornull
for the default. -
getHostnameVerifier
Returns the host name verifier ornull
for the default. -
setHostnameVerifier
Sets the host name verifier ornull
for the default. -
build
Returns a new instance ofNetHttpTransport
based on the options.
-