Class ApacheHttpTransport

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.http.client.HttpClient httpClient
      Apache HTTP client.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected ApacheHttpRequest buildRequest​(java.lang.String method, java.lang.String url)
      Builds a low level HTTP request for the given HTTP method.
      org.apache.http.client.HttpClient getHttpClient()
      Returns the Apache HTTP client.
      static org.apache.http.impl.client.DefaultHttpClient newDefaultHttpClient()
      Creates a new instance of the Apache HTTP client that is used by the ApacheHttpTransport() constructor.
      (package private) static org.apache.http.impl.client.DefaultHttpClient newDefaultHttpClient​(org.apache.http.conn.ssl.SSLSocketFactory socketFactory, org.apache.http.params.HttpParams params, java.net.ProxySelector proxySelector)
      Creates a new instance of the Apache HTTP client that is used by the ApacheHttpTransport() constructor.
      (package private) static org.apache.http.params.HttpParams newDefaultHttpParams()
      Returns a new instance of the default HTTP parameters we use.
      void shutdown()
      Shuts down the connection manager and releases allocated resources.
      boolean supportsMethod​(java.lang.String method)
      Returns whether a specified HTTP method is supported by this transport.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • httpClient

        private final org.apache.http.client.HttpClient httpClient
        Apache HTTP client.
    • Constructor Detail

      • ApacheHttpTransport

        public ApacheHttpTransport​(org.apache.http.client.HttpClient httpClient)
        Constructor that allows an alternative Apache HTTP client to be used.

        Note that a few settings are overridden:

        • HTTP version is set to 1.1 using HttpProtocolParams.setVersion(org.apache.http.params.HttpParams, org.apache.http.ProtocolVersion) with HttpVersion.HTTP_1_1.
        • Redirects are disabled using ClientPNames.HANDLE_REDIRECTS.
        • ConnManagerParams.setTimeout(org.apache.http.params.HttpParams, long) and HttpConnectionParams.setConnectionTimeout(org.apache.http.params.HttpParams, int) are set on each request based on HttpRequest.getConnectTimeout().
        • HttpConnectionParams.setSoTimeout(org.apache.http.params.HttpParams, int) is set on each request based on HttpRequest.getReadTimeout().

        Use ApacheHttpTransport.Builder for a more user-friendly way to modify the HTTP client options.

        Parameters:
        httpClient - Apache HTTP client to use
        Since:
        1.6
    • Method Detail

      • newDefaultHttpClient

        public static org.apache.http.impl.client.DefaultHttpClient newDefaultHttpClient()
        Creates a new instance of the Apache HTTP client that is used by the ApacheHttpTransport() constructor.

        Use this constructor if you want to customize the default Apache HTTP client. Settings:

        • The client connection manager is set to ThreadSafeClientConnManager.
        • The socket buffer size is set to 8192 using HttpConnectionParams.setSocketBufferSize(org.apache.http.params.HttpParams, int).
        • new DefaultHttpRequestRetryHandler(0, false).
        • The route planner uses ProxySelectorRoutePlanner with ProxySelector.getDefault(), which uses the proxy settings from system properties.
        Returns:
        new instance of the Apache HTTP client
        Since:
        1.6
      • newDefaultHttpParams

        static org.apache.http.params.HttpParams newDefaultHttpParams()
        Returns a new instance of the default HTTP parameters we use.
      • newDefaultHttpClient

        static org.apache.http.impl.client.DefaultHttpClient newDefaultHttpClient​(org.apache.http.conn.ssl.SSLSocketFactory socketFactory,
                                                                                  org.apache.http.params.HttpParams params,
                                                                                  java.net.ProxySelector proxySelector)
        Creates a new instance of the Apache HTTP client that is used by the ApacheHttpTransport() constructor.
        Parameters:
        socketFactory - SSL socket factory
        params - HTTP parameters
        proxySelector - HTTP proxy selector to use ProxySelectorRoutePlanner or null for DefaultHttpRoutePlanner
        Returns:
        new instance of the Apache HTTP client
      • supportsMethod

        public boolean supportsMethod​(java.lang.String method)
        Description copied from class: HttpTransport
        Returns whether a specified HTTP method is supported by this transport.

        Default implementation returns true if and only if the request method is "DELETE", "GET", "POST", or "PUT". Subclasses should override.

        Overrides:
        supportsMethod in class HttpTransport
        Parameters:
        method - HTTP method
      • buildRequest

        protected ApacheHttpRequest buildRequest​(java.lang.String method,
                                                 java.lang.String url)
        Description copied from class: HttpTransport
        Builds a low level HTTP request for the given HTTP method.
        Specified by:
        buildRequest in class HttpTransport
        Parameters:
        method - HTTP method
        url - URL
        Returns:
        new low level HTTP request
      • shutdown

        public void shutdown()
        Shuts down the connection manager and releases allocated resources. This includes closing all connections, whether they are currently used or not.
        Overrides:
        shutdown in class HttpTransport
        Since:
        1.4
      • getHttpClient

        public org.apache.http.client.HttpClient getHttpClient()
        Returns the Apache HTTP client.
        Since:
        1.5