Class ApacheHttpTransport.Builder
- java.lang.Object
-
- com.google.api.client.http.apache.ApacheHttpTransport.Builder
-
- Enclosing class:
- ApacheHttpTransport
public static final class ApacheHttpTransport.Builder extends Object
Builder forApacheHttpTransport
.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 ApacheHttpTransport
build()
Returns a new instance ofApacheHttpTransport
based on the options.ApacheHttpTransport.Builder
doNotValidateCertificate()
Beta
Disables validating server SSL certificates by setting the SSL socket factory usingSslUtils.trustAllSSLContext()
for the SSL context andSSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
for the host name verifier.org.apache.http.params.HttpParams
getHttpParams()
Returns the HTTP parameters.org.apache.http.conn.ssl.SSLSocketFactory
getSSLSocketFactory()
Returns the SSL socket factory (SSLSocketFactory.getSocketFactory()
by default).ApacheHttpTransport.Builder
setProxy(org.apache.http.HttpHost proxy)
Sets the HTTP proxy to useDefaultHttpRoutePlanner
ornull
to usesetProxySelector(ProxySelector)
withProxySelector.getDefault()
.ApacheHttpTransport.Builder
setProxySelector(ProxySelector proxySelector)
Sets the HTTP proxy selector to useProxySelectorRoutePlanner
ornull
forDefaultHttpRoutePlanner
.ApacheHttpTransport.Builder
setSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory socketFactory)
Sets the SSL socket factory (SSLSocketFactory.getSocketFactory()
by default).ApacheHttpTransport.Builder
trustCertificates(KeyStore trustStore)
Sets the SSL socket factory based on a root certificate trust store.ApacheHttpTransport.Builder
trustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)
Sets the SSL socket factory based on root certificates in a Java KeyStore.ApacheHttpTransport.Builder
trustCertificatesFromStream(InputStream certificateStream)
Sets the SSL socket factory based root certificates generated from the specified stream usingCertificateFactory.generateCertificates(InputStream)
.
-
-
-
Method Detail
-
setProxy
public ApacheHttpTransport.Builder setProxy(org.apache.http.HttpHost proxy)
Sets the HTTP proxy to useDefaultHttpRoutePlanner
ornull
to usesetProxySelector(ProxySelector)
withProxySelector.getDefault()
.By default it is
null
, which uses the proxy settings from system properties.For example:
setProxy(new HttpHost("127.0.0.1", 8080))
-
setProxySelector
public ApacheHttpTransport.Builder setProxySelector(ProxySelector proxySelector)
Sets the HTTP proxy selector to useProxySelectorRoutePlanner
ornull
forDefaultHttpRoutePlanner
.By default it is
ProxySelector.getDefault()
which uses the proxy settings from system properties.
-
trustCertificatesFromJavaKeyStore
public ApacheHttpTransport.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 ApacheHttpTransport.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 ApacheHttpTransport.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 ApacheHttpTransport.Builder doNotValidateCertificate() throws GeneralSecurityException
Beta
Disables validating server SSL certificates by setting the SSL socket factory usingSslUtils.trustAllSSLContext()
for the SSL context andSSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER
for the host name verifier.Be careful! Disabling certificate validation is dangerous and should only be done in testing environments.
- Throws:
GeneralSecurityException
-
setSocketFactory
public ApacheHttpTransport.Builder setSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory socketFactory)
Sets the SSL socket factory (SSLSocketFactory.getSocketFactory()
by default).
-
getSSLSocketFactory
public org.apache.http.conn.ssl.SSLSocketFactory getSSLSocketFactory()
Returns the SSL socket factory (SSLSocketFactory.getSocketFactory()
by default).
-
getHttpParams
public org.apache.http.params.HttpParams getHttpParams()
Returns the HTTP parameters.
-
build
public ApacheHttpTransport build()
Returns a new instance ofApacheHttpTransport
based on the options.
-
-