com.google.api.client.http.apache
Class ApacheHttpTransport

java.lang.Object
  extended by com.google.api.client.http.HttpTransport
      extended by 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 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 questions, such as how to set up an HTTP proxy.

Since:
1.0
Author:
Yaniv Inbar

Constructor Summary
ApacheHttpTransport()
          Constructor that uses newDefaultHttpClient() 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
 com.google.api.client.http.apache.ApacheHttpRequest buildDeleteRequest(String url)
          Builds a DELETE request.
 com.google.api.client.http.apache.ApacheHttpRequest buildGetRequest(String url)
          Builds a GET request.
 com.google.api.client.http.apache.ApacheHttpRequest buildHeadRequest(String url)
          Builds a HEAD request.
 com.google.api.client.http.apache.ApacheHttpRequest buildPatchRequest(String url)
          Builds a PATCH request.
 com.google.api.client.http.apache.ApacheHttpRequest buildPostRequest(String url)
          Builds a POST request.
 com.google.api.client.http.apache.ApacheHttpRequest buildPutRequest(String url)
          Builds a PUT request.
 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.
 void shutdown()
          Shuts down the connection manager and releases allocated resources.
 boolean supportsHead()
          Returns whether this HTTP transport implementation supports the HEAD request method.
 boolean supportsPatch()
          Returns whether this HTTP transport implementation supports the PATCH request method.
 
Methods inherited from class com.google.api.client.http.HttpTransport
createRequestFactory, createRequestFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ApacheHttpTransport

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

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:

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:

Returns:
new instance of the Apache HTTP client
Since:
1.6

supportsHead

public boolean supportsHead()
Description copied from class: HttpTransport
Returns whether this HTTP transport implementation supports the HEAD request method.

Default implementation returns false.

Overrides:
supportsHead in class HttpTransport

supportsPatch

public boolean supportsPatch()
Description copied from class: HttpTransport
Returns whether this HTTP transport implementation supports the PATCH request method.

Default implementation returns false.

Overrides:
supportsPatch in class HttpTransport

buildDeleteRequest

public com.google.api.client.http.apache.ApacheHttpRequest buildDeleteRequest(String url)
Description copied from class: HttpTransport
Builds a DELETE request.

Specified by:
buildDeleteRequest in class HttpTransport
Parameters:
url - URL

buildGetRequest

public com.google.api.client.http.apache.ApacheHttpRequest buildGetRequest(String url)
Description copied from class: HttpTransport
Builds a GET request.

Specified by:
buildGetRequest in class HttpTransport
Parameters:
url - URL

buildHeadRequest

public com.google.api.client.http.apache.ApacheHttpRequest buildHeadRequest(String url)
Description copied from class: HttpTransport
Builds a HEAD request. Won't be called if HttpTransport.supportsHead() returns false .

Default implementation throws an UnsupportedOperationException.

Overrides:
buildHeadRequest in class HttpTransport
Parameters:
url - URL

buildPatchRequest

public com.google.api.client.http.apache.ApacheHttpRequest buildPatchRequest(String url)
Description copied from class: HttpTransport
Builds a PATCH request. Won't be called if HttpTransport.supportsPatch() returns false.

Default implementation throws an UnsupportedOperationException.

Overrides:
buildPatchRequest in class HttpTransport
Parameters:
url - URL

buildPostRequest

public com.google.api.client.http.apache.ApacheHttpRequest buildPostRequest(String url)
Description copied from class: HttpTransport
Builds a POST request.

Specified by:
buildPostRequest in class HttpTransport
Parameters:
url - URL

buildPutRequest

public com.google.api.client.http.apache.ApacheHttpRequest buildPutRequest(String url)
Description copied from class: HttpTransport
Builds a PUT request.

Specified by:
buildPutRequest in class HttpTransport
Parameters:
url - URL

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


Copyright © 2011 Google. All Rights Reserved.