Class ApacheHttpTransport
- java.lang.Object
-
- com.google.api.client.http.HttpTransport
-
- com.google.api.client.http.apache.ApacheHttpTransport
-
public final class ApacheHttpTransport extends HttpTransport
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 theApacheHttpTransport(HttpClient)
constructor to override the Apache HTTP Client used. Alternatively, useApacheHttpTransport()
and change thegetHttpClient()
. Please read the Apache HTTP Client connection management tutorial for more complex configuration options.- Since:
- 1.0
- Author:
- Yaniv Inbar
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ApacheHttpTransport.Builder
Builder forApacheHttpTransport
.
-
Constructor Summary
Constructors Constructor Description ApacheHttpTransport()
Constructor that usesnewDefaultHttpClient()
for the Apache HTTP client.ApacheHttpTransport(org.apache.http.client.HttpClient httpClient)
Constructor that allows an alternative Apache HTTP client to be used.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected com.google.api.client.http.apache.ApacheHttpRequest
buildRequest(String method, 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 theApacheHttpTransport()
constructor.void
shutdown()
Shuts down the connection manager and releases allocated resources.boolean
supportsMethod(String method)
Returns whether a specified HTTP method is supported by this transport.-
Methods inherited from class com.google.api.client.http.HttpTransport
createRequestFactory, createRequestFactory
-
-
-
-
Constructor Detail
-
ApacheHttpTransport
public ApacheHttpTransport()
Constructor that usesnewDefaultHttpClient()
for the Apache HTTP client.Use
ApacheHttpTransport.Builder
to modify HTTP client options.- Since:
- 1.3
-
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)
withHttpVersion.HTTP_1_1
. - Redirects are disabled using
ClientPNames.HANDLE_REDIRECTS
. ConnManagerParams.setTimeout(org.apache.http.params.HttpParams, long)
andHttpConnectionParams.setConnectionTimeout(org.apache.http.params.HttpParams, int)
are set on each request based onHttpRequest.getConnectTimeout()
.HttpConnectionParams.setSoTimeout(org.apache.http.params.HttpParams, int)
is set on each request based onHttpRequest.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
- HTTP version is set to 1.1 using
-
-
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 theApacheHttpTransport()
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
withProxySelector.getDefault()
, which uses the proxy settings from system properties.
- Returns:
- new instance of the Apache HTTP client
- Since:
- 1.6
- The client connection manager is set to
-
supportsMethod
public boolean supportsMethod(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 classHttpTransport
- Parameters:
method
- HTTP method
-
buildRequest
protected com.google.api.client.http.apache.ApacheHttpRequest buildRequest(String method, String url)
Description copied from class:HttpTransport
Builds a low level HTTP request for the given HTTP method.- Specified by:
buildRequest
in classHttpTransport
- Parameters:
method
- HTTP methodurl
- 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 classHttpTransport
- Since:
- 1.4
-
getHttpClient
public org.apache.http.client.HttpClient getHttpClient()
Returns the Apache HTTP client.- Since:
- 1.5
-
-