Class ApacheHttpTransport.Builder
- java.lang.Object
-
- com.google.api.client.http.apache.ApacheHttpTransport.Builder
-
- Enclosing class:
- ApacheHttpTransport
public static final class ApacheHttpTransport.Builder extends java.lang.ObjectBuilder forApacheHttpTransport.Implementation is not thread-safe.
- Since:
- 1.13
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.http.params.HttpParamsparamsHTTP parameters.private java.net.ProxySelectorproxySelectorHTTP proxy selector to useProxySelectorRoutePlannerornullforDefaultHttpRoutePlanner.private org.apache.http.conn.ssl.SSLSocketFactorysocketFactorySSL socket factory.
-
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(java.net.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(java.security.KeyStore trustStore)Sets the SSL socket factory based on a root certificate trust store.ApacheHttpTransport.BuildertrustCertificatesFromJavaKeyStore(java.io.InputStream keyStoreStream, java.lang.String storePass)Sets the SSL socket factory based on root certificates in a Java KeyStore.ApacheHttpTransport.BuildertrustCertificatesFromStream(java.io.InputStream certificateStream)Sets the SSL socket factory based root certificates generated from the specified stream usingCertificateFactory.generateCertificates(InputStream).
-
-
-
Field Detail
-
socketFactory
private org.apache.http.conn.ssl.SSLSocketFactory socketFactory
SSL socket factory.
-
params
private org.apache.http.params.HttpParams params
HTTP parameters.
-
proxySelector
private java.net.ProxySelector proxySelector
HTTP proxy selector to useProxySelectorRoutePlannerornullforDefaultHttpRoutePlanner.
-
-
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(java.net.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(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 ApacheHttpTransport.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 ApacheHttpTransport.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 ApacheHttpTransport.Builder doNotValidateCertificate() throws java.security.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:
java.security.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.
-
-