com.google.api.client.http.json
Class JsonHttpRequest

java.lang.Object
  extended by java.util.AbstractMap<String,Object>
      extended by com.google.api.client.util.GenericData
          extended by com.google.api.client.http.json.JsonHttpRequest
All Implemented Interfaces:
Cloneable, Map<String,Object>

public class JsonHttpRequest
extends GenericData

JSON HTTP request to JsonHttpClient.

Implementation is not thread-safe.

Since:
1.6
Author:
Ravi Mistry

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
JsonHttpRequest(JsonHttpClient client, HttpMethod method, String uriTemplate, Object content)
          Builds an instance of JsonHttpRequest.
 
Method Summary
 HttpRequest buildHttpRequest()
          Create an HttpRequest suitable for use against this service.
 GenericUrl buildHttpRequestUrl()
          Creates a new instance of GenericUrl suitable for use against this service.
 void download(OutputStream outputStream)
          Sends the request to the server and writes the content input stream of HttpResponse into the given destination output stream.
 InputStream executeAsInputStream()
          Sends the request to the server and returns the content input stream of HttpResponse.
 HttpResponse executeUnparsed()
          Sends the request to the server and returns the raw HttpResponse.
 JsonHttpClient getClient()
          Returns the JSON HTTP client which handles this request.
 Object getJsonContent()
          Returns a POJO that can be serialized into JSON or null for none.
 HttpHeaders getLastResponseHeaders()
          Gets the HTTP headers of the last response or null for none.
 HttpMethod getMethod()
          Returns the HTTP Method type.
 HttpHeaders getRequestHeaders()
          Gets the HTTP headers used for the JSON HTTP request.
 String getUriTemplate()
          Returns the URI template.
 JsonHttpRequest setRequestHeaders(HttpHeaders headers)
          Sets the HTTP headers used for the JSON HTTP request.
 
Methods inherited from class com.google.api.client.util.GenericData
clone, entrySet, get, getUnknownKeys, put, putAll, remove, set, setUnknownKeys
 
Methods inherited from class java.util.AbstractMap
clear, containsKey, containsValue, equals, hashCode, isEmpty, keySet, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JsonHttpRequest

public JsonHttpRequest(JsonHttpClient client,
                       HttpMethod method,
                       String uriTemplate,
                       Object content)
Builds an instance of JsonHttpRequest.

Parameters:
client - The JSON HTTP client which handles this request
method - HTTP Method type
uriTemplate - URI template for the path relative to the base URL specified in JSON HTTP client. If it starts with a "/" the base path from the base URL will be stripped out. The URI template can also be a full URL. URI template expansion is done using UriTemplate.expand(String, String, Object, boolean)
content - A POJO that can be serialized into JSON or null for none
Method Detail

getMethod

public final HttpMethod getMethod()
Returns the HTTP Method type.


getUriTemplate

public final String getUriTemplate()
Returns the URI template.


getJsonContent

public final Object getJsonContent()
Returns a POJO that can be serialized into JSON or null for none.


getClient

public final JsonHttpClient getClient()
Returns the JSON HTTP client which handles this request.


setRequestHeaders

public JsonHttpRequest setRequestHeaders(HttpHeaders headers)
Sets the HTTP headers used for the JSON HTTP request. Subclasses may override by calling super.

These headers are set on the request after buildHttpRequest() is called, this means that HttpRequestInitializer.initialize(com.google.api.client.http.HttpRequest) is called first.

Since:
1.9

getRequestHeaders

public final HttpHeaders getRequestHeaders()
Gets the HTTP headers used for the JSON HTTP request.

Since:
1.9

getLastResponseHeaders

public final HttpHeaders getLastResponseHeaders()
Gets the HTTP headers of the last response or null for none.

Since:
1.9

buildHttpRequestUrl

public final GenericUrl buildHttpRequestUrl()
Creates a new instance of GenericUrl suitable for use against this service.

Returns:
newly created GenericUrl

buildHttpRequest

public HttpRequest buildHttpRequest()
                             throws IOException
Create an HttpRequest suitable for use against this service. Subclasses may override if specific behavior is required.

Returns:
newly created HttpRequest
Throws:
IOException

executeUnparsed

public HttpResponse executeUnparsed()
                             throws IOException
Sends the request to the server and returns the raw HttpResponse. Subclasses may override if specific behavior is required.

Callers are responsible for closing the response's content input stream by calling HttpResponse.ignore().

Returns:
the HttpResponse
Throws:
IOException - if the request fails

executeAsInputStream

public InputStream executeAsInputStream()
                                 throws IOException
Sends the request to the server and returns the content input stream of HttpResponse. Subclasses may override if specific behavior is required.

Callers are responsible for closing the input stream.

Returns:
input stream of the response content
Throws:
IOException - if the request fails
Since:
1.8

download

public void download(OutputStream outputStream)
              throws IOException
Sends the request to the server and writes the content input stream of HttpResponse into the given destination output stream.

This method closes the content of the HTTP response from HttpResponse.getContent().

Parameters:
outputStream - destination output stream
Throws:
IOException - I/O exception
Since:
1.9


Copyright © 2011-2012 Google. All Rights Reserved.