Class ApacheHttpTransport.Builder

  • Enclosing class:
    ApacheHttpTransport

    public static final class ApacheHttpTransport.Builder
    extends java.lang.Object
    Builder for ApacheHttpTransport.

    Implementation is not thread-safe.

    Since:
    1.13
    • 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 use ProxySelectorRoutePlanner or null for DefaultHttpRoutePlanner.
    • Constructor Detail

      • Builder

        public Builder()
    • Method Detail

      • setProxySelector

        public ApacheHttpTransport.Builder setProxySelector​(java.net.ProxySelector proxySelector)
        Sets the HTTP proxy selector to use ProxySelectorRoutePlanner or null for DefaultHttpRoutePlanner.

        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.GeneralSecurityException
        java.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 using CertificateFactory.generateCertificates(InputStream).

        Example usage:

         trustCertificatesFromStream(new FileInputStream("certs.pem"));
         
        Parameters:
        certificateStream - certificate stream
        Throws:
        java.security.GeneralSecurityException
        java.io.IOException
        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 using SslUtils.trustAllSSLContext() for the SSL context and SSLSocketFactory.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:
        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.