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.HttpParamsHTTP parameters.private ProxySelectorHTTP proxy selector to useProxySelectorRoutePlannerornullforDefaultHttpRoutePlanner.private org.apache.http.conn.ssl.SSLSocketFactorySSL socket factory. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Returns a new instance ofApacheHttpTransportbased 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_VERIFIERfor the host name verifier.org.apache.http.params.HttpParamsReturns the HTTP parameters.org.apache.http.conn.ssl.SSLSocketFactoryReturns the SSL socket factory (SSLSocketFactory.getSocketFactory()by default).setProxy(org.apache.http.HttpHost proxy) Sets the HTTP proxy to useDefaultHttpRoutePlannerornullto usesetProxySelector(ProxySelector)withProxySelector.getDefault().setProxySelector(ProxySelector proxySelector) Sets the HTTP proxy selector to useProxySelectorRoutePlannerornullforDefaultHttpRoutePlanner.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 useProxySelectorRoutePlannerornullforDefaultHttpRoutePlanner.
-
-
Constructor Details
-
Builder
public Builder()
-
-
Method Details
-
setProxy
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
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(KeyStore, InputStream, String)orSecurityUtils.loadKeyStoreFromCertificates(KeyStore, CertificateFactory, 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_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
Returns a new instance ofApacheHttpTransportbased on the options.
-