Class AbstractGoogleClientRequest<T> (2.5.0)

public abstract class AbstractGoogleClientRequest<T> extends GenericData

Abstract Google client request for a AbstractGoogleClient.

Implementation is not thread-safe.

Inheritance

Object > java.util.AbstractMap > com.google.api.client.util.GenericData > AbstractGoogleClientRequest<T>

Type Parameter

Name Description
T

Static Fields

API_VERSION_HEADER

protected static final String API_VERSION_HEADER

The generated request class will pass this constant as part of the header if the RPC supports ApiVersion.

Field Value
Type Description
String

USER_AGENT_SUFFIX

public static final String USER_AGENT_SUFFIX

User agent suffix for all requests.

Field Value
Type Description
String

Constructors

AbstractGoogleClientRequest(AbstractGoogleClient abstractGoogleClient, String requestMethod, String uriTemplate, HttpContent httpContent, Class<T> responseClass)

protected AbstractGoogleClientRequest(AbstractGoogleClient abstractGoogleClient, String requestMethod, String uriTemplate, HttpContent httpContent, Class<T> responseClass)
Parameters
Name Description
abstractGoogleClient AbstractGoogleClient

Google client

requestMethod String

HTTP Method

uriTemplate String

URI template for the path relative to the base URL. 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)

httpContent com.google.api.client.http.HttpContent

HTTP content or null for none

responseClass Class<T>

response class to parse into

Methods

<E>queue(BatchRequest batchRequest, Class<E> errorClass, BatchCallback<T,E> callback)

public final void <E>queue(BatchRequest batchRequest, Class<E> errorClass, BatchCallback<T,E> callback)

Queues the request into the specified batch request container using the specified error class.

Batched requests are then executed when BatchRequest#execute() is called.

Parameters
Name Description
batchRequest BatchRequest

batch request container

errorClass Class<E>

data class the unsuccessful response will be parsed into or Void.class to ignore the content

callback BatchCallback<T,E>

batch callback

Exceptions
Type Description
IOException

buildHttpRequest()

public HttpRequest buildHttpRequest()

Create a request suitable for use against this service.

Subclasses may override by calling the super implementation.

Returns
Type Description
com.google.api.client.http.HttpRequest
Exceptions
Type Description
IOException

buildHttpRequestUrl()

public GenericUrl buildHttpRequestUrl()

Creates a new instance of GenericUrl suitable for use against this service.

Subclasses may override by calling the super implementation.

Returns
Type Description
com.google.api.client.http.GenericUrl

newly created GenericUrl

buildHttpRequestUsingHead()

protected HttpRequest buildHttpRequestUsingHead()

Create a request suitable for use against this service, but using HEAD instead of GET.

Only supported when the original request method is GET.

Subclasses may override by calling the super implementation.

Returns
Type Description
com.google.api.client.http.HttpRequest
Exceptions
Type Description
IOException

checkRequiredParameter(Object value, String name)

protected final void checkRequiredParameter(Object value, String name)

Ensures that the specified required parameter is not null or AbstractGoogleClient#getSuppressRequiredParameterChecks() is true.

Parameters
Name Description
value Object

the value of the required parameter

name String

the name of the required parameter

execute()

public T execute()

Sends the metadata request to the server and returns the parsed metadata response.

Subclasses may override by calling the super implementation.

Returns
Type Description
T

parsed HTTP response

Exceptions
Type Description
IOException

executeAndDownloadTo(OutputStream outputStream)

public void executeAndDownloadTo(OutputStream outputStream)

Sends the metadata request to the server and writes the metadata content input stream of HttpResponse into the given destination output stream.

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

Subclasses may override by calling the super implementation.

Parameter
Name Description
outputStream OutputStream

destination output stream

Exceptions
Type Description
IOException

executeAsInputStream()

public InputStream executeAsInputStream()

Sends the metadata request to the server and returns the metadata content input stream of HttpResponse.

Callers are responsible for closing the input stream after it is processed. Example sample:


 InputStream is = request.executeAsInputStream();
 try {
   // Process input stream..
 } finally {
   is.close();
 }
 

Subclasses may override by calling the super implementation.

Returns
Type Description
InputStream

input stream of the response content

Exceptions
Type Description
IOException

executeMedia()

protected HttpResponse executeMedia()

Sends the media request to the server and returns the raw media HttpResponse.

Callers are responsible for disconnecting the HTTP response by calling HttpResponse#disconnect. Example usage:


 HttpResponse response = request.executeMedia();
 try {
   // process response..
 } finally {
   response.disconnect();
 }
 

Subclasses may override by calling the super implementation.

Returns
Type Description
com.google.api.client.http.HttpResponse

the HttpResponse

Exceptions
Type Description
IOException

executeMediaAndDownloadTo(OutputStream outputStream)

protected void executeMediaAndDownloadTo(OutputStream outputStream)

Sends the media request to the server and writes the media content input stream of HttpResponse into the given destination output stream.

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

Subclasses may override by calling the super implementation.

Parameter
Name Description
outputStream OutputStream

destination output stream

Exceptions
Type Description
IOException

executeMediaAsInputStream()

protected InputStream executeMediaAsInputStream()

Sends the media request to the server and returns the media content input stream of HttpResponse.

Callers are responsible for closing the input stream after it is processed. Example sample:


 InputStream is = request.executeMediaAsInputStream();
 try {
   // Process input stream..
 } finally {
   is.close();
 }
 

Subclasses may override by calling the super implementation.

Returns
Type Description
InputStream

input stream of the response content

Exceptions
Type Description
IOException

executeUnparsed()

public HttpResponse executeUnparsed()

Sends the metadata request to the server and returns the raw metadata HttpResponse.

Callers are responsible for disconnecting the HTTP response by calling HttpResponse#disconnect. Example usage:


 HttpResponse response = request.executeUnparsed();
 try {
   // process response..
 } finally {
   response.disconnect();
 }
 

Subclasses may override by calling the super implementation.

Returns
Type Description
com.google.api.client.http.HttpResponse

the HttpResponse

Exceptions
Type Description
IOException

executeUsingHead()

protected HttpResponse executeUsingHead()

Sends the metadata request using HEAD to the server and returns the raw metadata HttpResponse for the response headers.

Only supported when the original request method is GET. The response content is assumed to be empty and ignored. Calls HttpResponse#ignore() so there is no need to disconnect the response. Example usage:


 HttpResponse response = request.executeUsingHead();
 // look at response.getHeaders()
 

Subclasses may override by calling the super implementation.

Returns
Type Description
com.google.api.client.http.HttpResponse

the HttpResponse

Exceptions
Type Description
IOException

getAbstractGoogleClient()

public AbstractGoogleClient getAbstractGoogleClient()

Returns the Google client.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Returns
Type Description
AbstractGoogleClient

getDisableGZipContent()

public final boolean getDisableGZipContent()

Returns whether to disable GZip compression of HTTP content.

Returns
Type Description
boolean

getHttpContent()

public final HttpContent getHttpContent()

Returns the HTTP content or null for none.

Returns
Type Description
com.google.api.client.http.HttpContent

getLastResponseHeaders()

public final HttpHeaders getLastResponseHeaders()

Returns the HTTP headers of the last response or null before request has been executed.

Returns
Type Description
com.google.api.client.http.HttpHeaders

getLastStatusCode()

public final int getLastStatusCode()

Returns the status code of the last response or -1 before request has been executed.

Returns
Type Description
int

getLastStatusMessage()

public final String getLastStatusMessage()

Returns the status message of the last response or null before request has been executed.

Returns
Type Description
String

getMediaHttpDownloader()

public final MediaHttpDownloader getMediaHttpDownloader()

Returns the media HTTP downloader or null for none.

Returns
Type Description
MediaHttpDownloader

getMediaHttpUploader()

public final MediaHttpUploader getMediaHttpUploader()

Returns the media HTTP Uploader or null for none.

Returns
Type Description
MediaHttpUploader

getRequestHeaders()

public final HttpHeaders getRequestHeaders()

Returns the HTTP headers used for the Google client request.

Returns
Type Description
com.google.api.client.http.HttpHeaders

getRequestMethod()

public final String getRequestMethod()

Returns the HTTP method.

Returns
Type Description
String

getResponseClass()

public final Class<T> getResponseClass()

Returns the response class to parse into.

Returns
Type Description
Class<T>

getReturnRawInputSteam()

public final boolean getReturnRawInputSteam()

Returns whether response should return raw input stream.

Returns
Type Description
boolean

getUriTemplate()

public final String getUriTemplate()

Returns the URI template for the path relative to the base URL.

Returns
Type Description
String

initializeMediaDownload()

protected final void initializeMediaDownload()

Initializes the media HTTP downloader.

initializeMediaUpload(AbstractInputStreamContent mediaContent)

protected final void initializeMediaUpload(AbstractInputStreamContent mediaContent)

Initializes the media HTTP uploader based on the media content.

Parameter
Name Description
mediaContent com.google.api.client.http.AbstractInputStreamContent

media content

newExceptionOnError(HttpResponse response)

protected IOException newExceptionOnError(HttpResponse response)

Returns the exception to throw on an HTTP error response as defined by HttpResponse#isSuccessStatusCode().

It is guaranteed that HttpResponse#isSuccessStatusCode() is false. Default implementation is to call HttpResponseException#HttpResponseException(HttpResponse), but subclasses may override.

Parameter
Name Description
response com.google.api.client.http.HttpResponse

HTTP response

Returns
Type Description
IOException

exception to throw

set(String fieldName, Object value)

public AbstractGoogleClientRequest<T> set(String fieldName, Object value)
Parameters
Name Description
fieldName String
value Object
Returns
Type Description
AbstractGoogleClientRequest<T>
Overrides
com.google.api.client.util.GenericData.set(java.lang.String,java.lang.Object)

setDisableGZipContent(boolean disableGZipContent)

public AbstractGoogleClientRequest<T> setDisableGZipContent(boolean disableGZipContent)

Sets whether to disable GZip compression of HTTP content.

By default it is false.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
Name Description
disableGZipContent boolean
Returns
Type Description
AbstractGoogleClientRequest<T>

setRequestHeaders(HttpHeaders headers)

public AbstractGoogleClientRequest<T> setRequestHeaders(HttpHeaders headers)

Sets the HTTP headers used for the Google client request.

These headers are set on the request after #buildHttpRequest is called, this means that HttpRequestInitializer#initialize is called first.

Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.

Parameter
Name Description
headers com.google.api.client.http.HttpHeaders
Returns
Type Description
AbstractGoogleClientRequest<T>

setReturnRawInputStream(boolean returnRawInputStream)

public AbstractGoogleClientRequest<T> setReturnRawInputStream(boolean returnRawInputStream)

Sets whether the response should return raw input stream or not.

By default it is false.

When the response contains a known content-encoding header, the response stream is wrapped with an InputStream that decodes the content. This fails when we download large files in chunks (see #1009 ). Setting this to true will make the response return the raw input stream.

Parameter
Name Description
returnRawInputStream boolean
Returns
Type Description
AbstractGoogleClientRequest<T>