public abstract class HttpTransport extends Object
Implementation is thread-safe, and sub-classes must be thread-safe. For maximum efficiency, applications should use a single globally-shared instance of the HTTP transport.
The recommended concrete implementation HTTP transport library to use depends on what environment you are running in:
com.google.api.client.appengine.UrlFetchTransport
.
com.google.api.client.apache.ApacheHttpTransport
doesn't work on App Engine because
the Apache HTTP Client opens its own sockets (though in theory there are ways to hack it to work
on App Engine that might work).com.google.api.client.javanet.NetHttpTransport
is discouraged due to a bug in the App
Engine SDK itself in how it parses HTTP headers in the response.com.google.api.client.javanet.NetHttpTransport
. Their Apache HTTP Client implementation
is not as well maintained.com.google.api.client.apache.ApacheHttpTransport
.
com.google.api.client.javanet.NetHttpTransport
is not recommended due to some bugs in the
Android SDK implementation of HttpURLConnection.com.google.api.client.javanet.NetHttpTransport
is based on the HttpURLConnection
built into the Java SDK, so it is normally the preferred choice.com.google.api.client.apache.ApacheHttpTransport
is a good choice for users of the
Apache HTTP Client, especially if you need some of the configuration options available in that
library.
Some HTTP transports do not support all HTTP methods. Use supportsMethod(String)
to
check if a certain HTTP method is supported. Calling buildRequest()
on a method that is
not supported will result in an IllegalArgumentException
.
Subclasses should override supportsMethod(String)
and
buildRequest(String, String)
to build requests and specify which HTTP methods are
supported.
Constructor and Description |
---|
HttpTransport() |
Modifier and Type | Method and Description |
---|---|
protected LowLevelHttpRequest |
buildDeleteRequest(String url)
Deprecated.
(scheduled to be removed in 1.14) Use
buildRequest(String, String) instead |
protected LowLevelHttpRequest |
buildGetRequest(String url)
Deprecated.
(scheduled to be removed in 1.14) Use
buildRequest(String, String) instead |
protected LowLevelHttpRequest |
buildHeadRequest(String url)
Deprecated.
(scheduled to be removed in 1.14) Use
buildRequest(String, String) instead |
protected LowLevelHttpRequest |
buildPatchRequest(String url)
Deprecated.
(scheduled to be removed in 1.14) Use
buildRequest(String, String) instead |
protected LowLevelHttpRequest |
buildPostRequest(String url)
Deprecated.
(scheduled to be removed in 1.14) Use
buildRequest(String, String) instead |
protected LowLevelHttpRequest |
buildPutRequest(String url)
Deprecated.
(scheduled to be removed in 1.14) Use
buildRequest(String, String) instead |
protected LowLevelHttpRequest |
buildRequest(String method,
String url)
Builds a low level HTTP request for the given HTTP method.
|
HttpRequestFactory |
createRequestFactory()
Returns a new instance of an HTTP request factory based on this HTTP transport.
|
HttpRequestFactory |
createRequestFactory(HttpRequestInitializer initializer)
Returns a new instance of an HTTP request factory based on this HTTP transport with the given
HTTP request initializer.
|
void |
shutdown()
Default implementation does nothing, but subclasses may override to possibly release allocated
system resources or close connections.
|
boolean |
supportsHead()
Deprecated.
(scheduled to be removed in 1.14) Use
supportsMethod(String) instead |
boolean |
supportsMethod(String method)
Returns whether a specified HTTP method is supported by this transport.
|
boolean |
supportsPatch()
Deprecated.
(scheduled to be removed in 1.14) Use
supportsMethod(String) instead |
public final HttpRequestFactory createRequestFactory()
public final HttpRequestFactory createRequestFactory(HttpRequestInitializer initializer)
initializer
- HTTP request initializer or null
for none@Deprecated public boolean supportsHead() throws IOException
supportsMethod(String)
insteadHEAD
request method.
Default implementation calls supportsMethod(java.lang.String)
.
Upgrade warning: this method now throws an IOException
. In prior version 1.11 it did
not throw an exception.
IOException
@Deprecated public boolean supportsPatch() throws IOException
supportsMethod(String)
insteadPATCH
request method.
Default implementation calls supportsMethod(java.lang.String)
.
Upgrade warning: this method now throws an IOException
. In prior version 1.11 it did
not throw an exception.
IOException
public boolean supportsMethod(String method) throws IOException
Default implementation returns true if and only if the request method is "DELETE"
,
"GET"
, "POST"
, or "PUT"
. Subclasses should override.
method
- HTTP methodIOException
- I/O exceptionprotected LowLevelHttpRequest buildRequest(String method, String url) throws IOException
Warning: for backwards compatibility, in version 1.12 a default implementation that throws an
IllegalArgumentException
is provided, but it will be made abstract in the next version
1.13.
method
- HTTP methodurl
- URLIllegalArgumentException
- if HTTP method is not supportedIOException
- I/O exception@Deprecated protected LowLevelHttpRequest buildDeleteRequest(String url) throws IOException
buildRequest(String, String)
insteadDELETE
request.
Default implementation calls buildRequest()
.
url
- URLIOException
@Deprecated protected LowLevelHttpRequest buildGetRequest(String url) throws IOException
buildRequest(String, String)
insteadGET
request.
Default implementation calls buildRequest()
.
url
- URLIOException
@Deprecated protected LowLevelHttpRequest buildHeadRequest(String url) throws IOException
buildRequest(String, String)
insteadHEAD
request.
Won't be called if supportsHead()
returns false
.
Default implementation calls buildRequest()
.
Upgrade warning: in prior version it threw an UnsupportedOperationException
by
default}.
url
- URLIOException
@Deprecated protected LowLevelHttpRequest buildPatchRequest(String url) throws IOException
buildRequest(String, String)
insteadPATCH
request.
Won't be called if supportsPatch()
returns false
.
Default implementation calls buildRequest()
.
Upgrade warning: in prior version it threw an UnsupportedOperationException
by
default}.
url
- URLIOException
@Deprecated protected LowLevelHttpRequest buildPostRequest(String url) throws IOException
buildRequest(String, String)
insteadPOST
request.
Default implementation calls buildRequest()
.
url
- URLIOException
@Deprecated protected LowLevelHttpRequest buildPutRequest(String url) throws IOException
buildRequest(String, String)
insteadPUT
request.
Default implementation calls buildRequest()
.
url
- URLIOException
public void shutdown() throws IOException
IOException
- I/O exceptionCopyright © 2011-2012 Google. All Rights Reserved.