|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.api.client.http.json.JsonHttpClient
public class JsonHttpClient
JSON HTTP Client.
Implementation is not thread-safe.
Nested Class Summary | |
---|---|
static class |
JsonHttpClient.Builder
Builder for JsonHttpClient . |
Method Summary | |
---|---|
protected HttpRequest |
buildHttpRequest(HttpMethod method,
GenericUrl url,
Object body)
Create an HttpRequest suitable for use against this service. |
protected JsonHttpParser |
createParser()
Deprecated. (scheduled to be removed in 1.12) Use JsonHttpClient.Builder.setObjectParser(JsonObjectParser) instead. |
protected JsonHttpContent |
createSerializer(Object body)
Create a JSON serializer for a request object. |
protected InputStream |
executeAsInputStream(HttpMethod method,
GenericUrl url,
Object body)
Builds and executes an HttpRequest and then returns the content input stream of
HttpResponse . |
protected HttpResponse |
executeUnparsed(HttpMethod method,
GenericUrl url,
Object body)
Builds and executes a HttpRequest . |
protected HttpResponse |
executeUnparsed(HttpRequest request)
Executes the specified HttpRequest . |
String |
getApplicationName()
Returns the application name to be sent in the User-Agent header of each request or null for none. |
String |
getBaseUrl()
Returns the base URL of the service, for example "https://www.googleapis.com/tasks/v1/"
. |
JsonFactory |
getJsonFactory()
Returns the JSON Factory. |
JsonHttpParser |
getJsonHttpParser()
Deprecated. (scheduled to be removed in 1.12) Use getJsonObjectParser() instead. |
JsonHttpRequestInitializer |
getJsonHttpRequestInitializer()
Returns the JSON HTTP request initializer or null for none. |
JsonObjectParser |
getJsonObjectParser()
Returns the JSON Object Parser. |
HttpRequestFactory |
getRequestFactory()
Returns the HTTP request factory. |
String |
getRootUrl()
Returns the root URL of the service, for example https://www.googleapis.com/ . |
String |
getServicePath()
Returns the service path of the service, for example "tasks/v1/" . |
protected void |
initialize(JsonHttpRequest jsonHttpRequest)
Initializes a JsonHttpRequest using a JsonHttpRequestInitializer . |
protected boolean |
isBaseUrlUsed()
Deprecated. (scheduled to be removed in 1.12) Use getRootUrl() and
getServicePath() instead. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
@Deprecated public JsonHttpClient(HttpTransport transport, JsonFactory jsonFactory, String baseUrl)
JsonHttpClient(HttpTransport,
JsonFactory, String, String, HttpRequestInitializer)
.
Use JsonHttpClient.Builder
if you need to specify any of the optional parameters.
transport
- The transport to use for requestsjsonFactory
- A factory for creating JSON parsers and serializersbaseUrl
- The base URL of the service. Must end with a "/"public JsonHttpClient(HttpTransport transport, JsonFactory jsonFactory, String rootUrl, String servicePath, HttpRequestInitializer httpRequestInitializer)
Use JsonHttpClient.Builder
if you need to specify any of the optional parameters.
transport
- The transport to use for requestsjsonFactory
- A factory for creating JSON parsers and serializersrootUrl
- The root URL of the serviceservicePath
- The service path of the service. It is allowed to be an empty string
""
or a forward slash "/"
, if it is a forward slash then it is treated
as an empty stringhttpRequestInitializer
- The HTTP request initializer or null
for none@Deprecated protected JsonHttpClient(HttpTransport transport, JsonHttpRequestInitializer jsonHttpRequestInitializer, HttpRequestInitializer httpRequestInitializer, JsonFactory jsonFactory, String baseUrl, String applicationName)
JsonHttpClient(HttpTransport,
JsonHttpRequestInitializer, HttpRequestInitializer, JsonFactory, JsonObjectParser,
String, String, String)
.
JsonHttpClient
.
transport
- The transport to use for requestsjsonHttpRequestInitializer
- The initializer to use when creating an
JsonHttpRequest
or null
for nonehttpRequestInitializer
- The initializer to use when creating an HttpRequest
or
null
for nonejsonFactory
- A factory for creating JSON parsers and serializersbaseUrl
- The base URL of the service. Must end with a "/"applicationName
- The application name to be sent in the User-Agent header of requests or
null
for none@Deprecated protected JsonHttpClient(HttpTransport transport, JsonHttpRequestInitializer jsonHttpRequestInitializer, HttpRequestInitializer httpRequestInitializer, JsonFactory jsonFactory, JsonObjectParser jsonObjectParser, String baseUrl, String applicationName)
JsonHttpClient(HttpTransport,
JsonHttpRequestInitializer, HttpRequestInitializer, JsonFactory, JsonObjectParser,
String, String, String)
.
JsonHttpClient
.
transport
- The transport to use for requestsjsonHttpRequestInitializer
- The initializer to use when creating an
JsonHttpRequest
or null
for nonehttpRequestInitializer
- The initializer to use when creating an HttpRequest
or
null
for nonejsonFactory
- A factory for creating JSON parsers and serializersbaseUrl
- The base URL of the service. Must end with a "/"applicationName
- The application name to be sent in the User-Agent header of requests or
null
for noneprotected JsonHttpClient(HttpTransport transport, JsonHttpRequestInitializer jsonHttpRequestInitializer, HttpRequestInitializer httpRequestInitializer, JsonFactory jsonFactory, JsonObjectParser jsonObjectParser, String rootUrl, String servicePath, String applicationName)
JsonHttpClient
.
transport
- The transport to use for requestsjsonHttpRequestInitializer
- The initializer to use when creating an
JsonHttpRequest
or null
for nonehttpRequestInitializer
- The initializer to use when creating an HttpRequest
or
null
for nonejsonFactory
- A factory for creating JSON parsers and serializersjsonObjectParser
- JSON parser to use or null
if unused. null
won't be
accepted from 1.11 on.rootUrl
- The root URL of the serviceservicePath
- The service path of the service. It is allowed to be an empty string
""
or a forward slash "/"
, if it is a forward slash then it is treated
as an empty stringapplicationName
- The application name to be sent in the User-Agent header of requests or
null
for noneMethod Detail |
---|
@Deprecated protected final boolean isBaseUrlUsed()
getRootUrl()
and
getServicePath()
instead.
servicePath
and rootUrl
.
public final String getBaseUrl()
"https://www.googleapis.com/tasks/v1/"
. Must be URL-encoded and must end with a "/". This is determined when the library is generated
and normally should not be changed.
public final String getRootUrl()
https://www.googleapis.com/
. Must be
URL-encoded and must end with a "/".
public final String getServicePath()
"tasks/v1/"
. Must be URL-encoded
and must end with a "/" and not begin with a "/". It is allowed to be an empty string
""
or a forward slash "/"
, if it is a forward slash then it is treated as an
empty string
public final String getApplicationName()
null
for none.
public final JsonFactory getJsonFactory()
public final HttpRequestFactory getRequestFactory()
public final JsonHttpRequestInitializer getJsonHttpRequestInitializer()
null
for none.
@Deprecated public final JsonHttpParser getJsonHttpParser()
getJsonObjectParser()
instead.
@Deprecated protected JsonHttpParser createParser()
JsonHttpClient.Builder.setObjectParser(JsonObjectParser)
instead.
JsonHttpParser
implementations are required.
public final JsonObjectParser getJsonObjectParser()
protected JsonHttpContent createSerializer(Object body)
JsonHttpContent
implementations are required.
body
- A POJO that can be serialized into JSONprotected void initialize(JsonHttpRequest jsonHttpRequest) throws IOException
JsonHttpRequest
using a JsonHttpRequestInitializer
. Subclasses
may override if specific behavior is required.
Must be called before the JSON HTTP request is executed, preferably right after the request is instantiated. Sample usage:
public class Get extends JsonHttpRequest { ... } public Get get(String userId) throws IOException { Get result = new Get(userId); initialize(result); return result; }
jsonHttpRequest
- JSON HTTP Request type
IOException
protected HttpRequest buildHttpRequest(HttpMethod method, GenericUrl url, Object body) throws IOException
HttpRequest
suitable for use against this service.
Subclasses may override if specific behavior is required, for example if a sequence of requests
need to be built instead of a single request then subclasses should throw an
UnsupportedOperationException
. Subclasses which override this method can make use of
HttpRequest.addParser(com.google.api.client.http.HttpParser)
, HttpRequest.setContent(com.google.api.client.http.HttpContent)
and
HttpRequest.setEnableGZipContent(boolean)
.
method
- HTTP Method typeurl
- The complete URL of the service where requests should be sentbody
- A POJO that can be serialized into JSON or null
for none
HttpRequest
IOException
protected HttpResponse executeUnparsed(HttpMethod method, GenericUrl url, Object body) throws IOException
HttpRequest
. Subclasses may override if specific behavior is
required, for example if a sequence of requests need to be built instead of a single request.
Callers are responsible for disconnecting the HTTP response by calling
HttpResponse.disconnect()
. Example usage:
HttpResponse response = client.executeUnparsed(method, url, body); try { // process response.. } finally { response.disconnect(); }
method
- HTTP Method typeurl
- The complete URL of the service where requests should be sentbody
- A POJO that can be serialized into JSON or null
for none
HttpResponse
type
IOException
- if the request failsprotected HttpResponse executeUnparsed(HttpRequest request) throws IOException
HttpRequest
. Subclasses may override if specific behavior is
required, for example if a custom error is required to be thrown.
Callers are responsible for disconnecting the HTTP response by calling
HttpResponse.disconnect()
. Example usage:
HttpResponse response = client.executeUnparsed(request); try { // process response.. } finally { response.disconnect(); }
request
- HTTP Request
HttpResponse
type
IOException
- if the request failsprotected InputStream executeAsInputStream(HttpMethod method, GenericUrl url, Object body) throws IOException
HttpRequest
and then returns the content input stream of
HttpResponse
. Subclasses may override if specific behavior is required.
Callers are responsible for closing the input stream after it is processed. Example usage:
InputStream is = client.executeAsInputStream(); try { // Process input stream.. } finally { is.close(); }
method
- HTTP Method typeurl
- The complete URL of the service where requests should be sentbody
- A POJO that can be serialized into JSON or null
for none
IOException
- if the request fails
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |