Class ApacheHttpTransport (1.43.0)

public final class ApacheHttpTransport extends HttpTransport

Deprecated. Please use com.google.api.client.http.apache.v2.ApacheHttpTransport provided by the com.google.http-client:google-http-client-apache-v2 artifact.

Thread-safe HTTP transport based on the Apache HTTP Client library.

Implementation is thread-safe, as long as any parameter modification to the Apache HTTP Client is only done at initialization time. For maximum efficiency, applications should use a single globally-shared instance of the HTTP transport.

Default settings are specified in #newDefaultHttpClient(). Use the #ApacheHttpTransport(HttpClient) constructor to override the Apache HTTP Client used. Alternatively, use #ApacheHttpTransport() and change the #getHttpClient(). Please read the Apache HTTP Client connection management tutorial for more complex configuration options.

Inheritance

java.lang.Object > HttpTransport > ApacheHttpTransport

Static Methods

newDefaultHttpClient() (deprecated)

public static 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.
  • <The retry mechanism is turned off by setting new DefaultHttpRequestRetryHandler(0, false).
  • The route planner uses ProxySelectorRoutePlanner with ProxySelector#getDefault(), which uses the proxy settings from system properties.
Returns
TypeDescription
org.apache.http.impl.client.DefaultHttpClient

new instance of the Apache HTTP client

Constructors

ApacheHttpTransport() (deprecated)

public ApacheHttpTransport()

Constructor that uses #newDefaultHttpClient() for the Apache HTTP client.

Use Builder to modify HTTP client options.

ApacheHttpTransport(HttpClient httpClient) (deprecated)

public ApacheHttpTransport(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 with HttpVersion#HTTP_1_1.
  • Redirects are disabled using ClientPNames#HANDLE_REDIRECTS.
  • ConnManagerParams#setTimeout and HttpConnectionParams#setConnectionTimeout are set on each request based on HttpRequest#getConnectTimeout().
  • HttpConnectionParams#setSoTimeout is set on each request based on HttpRequest#getReadTimeout().

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

Parameter
NameDescription
httpClientorg.apache.http.client.HttpClient

Apache HTTP client to use

Methods

buildRequest(String method, String url) (deprecated)

protected ApacheHttpRequest buildRequest(String method, String url)

Builds a low level HTTP request for the given HTTP method.

Parameters
NameDescription
methodString
urlString
Returns
TypeDescription
com.google.api.client.http.apache.ApacheHttpRequest
Overrides

getHttpClient() (deprecated)

public HttpClient getHttpClient()

Returns the Apache HTTP client.

Returns
TypeDescription
org.apache.http.client.HttpClient

shutdown() (deprecated)

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

supportsMethod(String method) (deprecated)

public boolean supportsMethod(String method)

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.

Parameter
NameDescription
methodString
Returns
TypeDescription
boolean
Overrides