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 ApacheHttpTransportbuild()Returns a new instance ofApacheHttpTransportbased on the options.ApacheHttpTransport.BuilderdoNotValidateCertificate()Beta
Disables validating server SSL certificates by setting the SSL socket factory usingSslUtils.trustAllSSLContext()for the SSL context andSSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIERfor the host name verifier.org.apache.http.params.HttpParamsgetHttpParams()Returns the HTTP parameters.org.apache.http.conn.ssl.SSLSocketFactorygetSSLSocketFactory()Returns the SSL socket factory (SSLSocketFactory.getSocketFactory()by default).ApacheHttpTransport.BuildersetProxy(org.apache.http.HttpHost proxy)Sets the HTTP proxy to useDefaultHttpRoutePlannerornullto usesetProxySelector(ProxySelector)withProxySelector.getDefault().ApacheHttpTransport.BuildersetProxySelector(ProxySelector proxySelector)Sets the HTTP proxy selector to useProxySelectorRoutePlannerornullforDefaultHttpRoutePlanner.ApacheHttpTransport.BuildersetSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory socketFactory)Sets the SSL socket factory (SSLSocketFactory.getSocketFactory()by default).ApacheHttpTransport.BuildertrustCertificates(KeyStore trustStore)Sets the SSL socket factory based on a root certificate trust store.ApacheHttpTransport.BuildertrustCertificatesFromJavaKeyStore(InputStream keyStoreStream, String storePass)Sets the SSL socket factory based on root certificates in a Java KeyStore.ApacheHttpTransport.BuildertrustCertificatesFromStream(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 useDefaultHttpRoutePlannerornullto 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 useProxySelectorRoutePlannerornullforDefaultHttpRoutePlanner.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:
GeneralSecurityExceptionIOException- 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:
GeneralSecurityExceptionIOException- 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_VERIFIERfor 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 ofApacheHttpTransportbased on the options.
-
-