Class ApacheHttpTransport.Builder
java.lang.Object
com.google.api.client.http.apache.ApacheHttpTransport.Builder
- Enclosing class:
ApacheHttpTransport
Builder for
ApacheHttpTransport
.
Implementation is not thread-safe.
- Since:
- 1.13
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate org.apache.http.params.HttpParams
HTTP parameters.private ProxySelector
HTTP proxy selector to useProxySelectorRoutePlanner
ornull
forDefaultHttpRoutePlanner
.private org.apache.http.conn.ssl.SSLSocketFactory
SSL socket factory. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()
Returns a new instance ofApacheHttpTransport
based on the options.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
Returns the HTTP parameters.org.apache.http.conn.ssl.SSLSocketFactory
Returns the SSL socket factory (SSLSocketFactory.getSocketFactory()
by default).setProxy
(org.apache.http.HttpHost proxy) Sets the HTTP proxy to useDefaultHttpRoutePlanner
ornull
to usesetProxySelector(ProxySelector)
withProxySelector.getDefault()
.setProxySelector
(ProxySelector proxySelector) Sets the HTTP proxy selector to useProxySelectorRoutePlanner
ornull
forDefaultHttpRoutePlanner
.setSocketFactory
(org.apache.http.conn.ssl.SSLSocketFactory socketFactory) Sets the SSL socket factory (SSLSocketFactory.getSocketFactory()
by 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
-
socketFactory
private org.apache.http.conn.ssl.SSLSocketFactory socketFactorySSL socket factory. -
params
private org.apache.http.params.HttpParams paramsHTTP parameters. -
proxySelector
HTTP proxy selector to useProxySelectorRoutePlanner
ornull
forDefaultHttpRoutePlanner
.
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
setProxy
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
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
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
Returns a new instance ofApacheHttpTransport
based on the options.
-