T
- type of the responsepublic abstract class AbstractGoogleClientRequest<T> extends GenericData
AbstractGoogleClient
.
Implementation is not thread-safe.
GenericData.Flags
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
Modifier and Type | Field and Description |
---|---|
static String |
USER_AGENT_SUFFIX
User agent suffix for all requests.
|
Modifier | Constructor and Description |
---|---|
protected |
AbstractGoogleClientRequest(AbstractGoogleClient abstractGoogleClient,
String requestMethod,
String uriTemplate,
HttpContent httpContent,
Class<T> responseClass) |
Modifier and Type | Method and Description |
---|---|
HttpRequest |
buildHttpRequest()
Create a request suitable for use against this service.
|
GenericUrl |
buildHttpRequestUrl()
Creates a new instance of
GenericUrl suitable for use against this service. |
protected HttpRequest |
buildHttpRequestUsingHead()
Create a request suitable for use against this service, but using HEAD instead of GET.
|
protected void |
checkRequiredParameter(Object value,
String name)
Ensures that the specified required parameter is not null or
AbstractGoogleClient.getSuppressRequiredParameterChecks() is true. |
T |
execute()
Sends the metadata request to the server and returns the parsed metadata response.
|
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. |
InputStream |
executeAsInputStream()
Sends the metadata request to the server and returns the metadata content input stream of
HttpResponse . |
protected HttpResponse |
executeMedia()
Sends the media request to the server and returns the raw media
HttpResponse . |
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. |
protected InputStream |
executeMediaAsInputStream()
Sends the media request to the server and returns the media content input stream of
HttpResponse . |
HttpResponse |
executeUnparsed()
Sends the metadata request to the server and returns the raw metadata
HttpResponse . |
protected HttpResponse |
executeUsingHead()
Sends the metadata request using HEAD to the server and returns the raw metadata
HttpResponse for the response headers. |
AbstractGoogleClient |
getAbstractGoogleClient()
Returns the Google client.
|
boolean |
getDisableGZipContent()
Returns whether to disable GZip compression of HTTP content.
|
HttpContent |
getHttpContent()
Returns the HTTP content or
null for none. |
HttpHeaders |
getLastResponseHeaders()
Returns the HTTP headers of the last response or
null before request has been executed. |
int |
getLastStatusCode()
Returns the status code of the last response or
-1 before request has been executed. |
String |
getLastStatusMessage()
Returns the status message of the last response or
null before request has been
executed. |
MediaHttpDownloader |
getMediaHttpDownloader()
Returns the media HTTP downloader or
null for none. |
MediaHttpUploader |
getMediaHttpUploader()
Returns the media HTTP Uploader or
null for none. |
HttpHeaders |
getRequestHeaders()
Returns the HTTP headers used for the Google client request.
|
String |
getRequestMethod()
Returns the HTTP method.
|
Class<T> |
getResponseClass()
Returns the response class to parse into.
|
boolean |
getReturnRawInputSteam()
Returns whether response should return raw input stream.
|
String |
getUriTemplate()
Returns the URI template for the path relative to the base URL.
|
protected void |
initializeMediaDownload()
Initializes the media HTTP downloader.
|
protected void |
initializeMediaUpload(AbstractInputStreamContent mediaContent)
Initializes the media HTTP uploader based on the media content.
|
protected IOException |
newExceptionOnError(HttpResponse response)
Returns the exception to throw on an HTTP error response as defined by
HttpResponse.isSuccessStatusCode() . |
<E> void |
queue(BatchRequest batchRequest,
Class<E> errorClass,
BatchCallback<T,E> callback)
Queues the request into the specified batch request container using the specified error class.
|
AbstractGoogleClientRequest<T> |
set(String fieldName,
Object value) |
AbstractGoogleClientRequest<T> |
setDisableGZipContent(boolean disableGZipContent)
Sets whether to disable GZip compression of HTTP content.
|
AbstractGoogleClientRequest<T> |
setRequestHeaders(HttpHeaders headers)
Sets the HTTP headers used for the Google client request.
|
AbstractGoogleClientRequest<T> |
setReturnRawInputStream(boolean returnRawInputStream)
Sets whether the response should return raw input stream or not.
|
clone, entrySet, equals, get, getClassInfo, getUnknownKeys, hashCode, put, putAll, remove, setUnknownKeys, toString
clear, containsKey, containsValue, isEmpty, keySet, size, values
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public static final String USER_AGENT_SUFFIX
protected AbstractGoogleClientRequest(AbstractGoogleClient abstractGoogleClient, String requestMethod, String uriTemplate, HttpContent httpContent, Class<T> responseClass)
abstractGoogleClient
- Google clientrequestMethod
- HTTP MethoduriTemplate
- 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
- HTTP content or null
for noneresponseClass
- response class to parse intopublic final boolean getDisableGZipContent()
public final boolean getReturnRawInputSteam()
public AbstractGoogleClientRequest<T> setDisableGZipContent(boolean disableGZipContent)
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.
public AbstractGoogleClientRequest<T> setReturnRawInputStream(boolean returnRawInputStream)
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.
public final String getRequestMethod()
public final String getUriTemplate()
public final HttpContent getHttpContent()
null
for none.public AbstractGoogleClient getAbstractGoogleClient()
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public final HttpHeaders getRequestHeaders()
public AbstractGoogleClientRequest<T> setRequestHeaders(HttpHeaders headers)
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.
Overriding is only supported for the purpose of calling the super implementation and changing the return type, but nothing else.
public final HttpHeaders getLastResponseHeaders()
null
before request has been executed.public final int getLastStatusCode()
-1
before request has been executed.public final String getLastStatusMessage()
null
before request has been
executed.public final MediaHttpUploader getMediaHttpUploader()
null
for none.protected final void initializeMediaUpload(AbstractInputStreamContent mediaContent)
mediaContent
- media contentpublic final MediaHttpDownloader getMediaHttpDownloader()
null
for none.protected final void initializeMediaDownload()
public GenericUrl buildHttpRequestUrl()
GenericUrl
suitable for use against this service.
Subclasses may override by calling the super implementation.
GenericUrl
public HttpRequest buildHttpRequest() throws IOException
Subclasses may override by calling the super implementation.
IOException
protected HttpRequest buildHttpRequestUsingHead() throws IOException
Only supported when the original request method is GET.
Subclasses may override by calling the super implementation.
IOException
public HttpResponse executeUnparsed() throws IOException
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.
HttpResponse
IOException
protected HttpResponse executeMedia() throws IOException
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.
HttpResponse
IOException
protected HttpResponse executeUsingHead() throws IOException
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.
HttpResponse
IOException
protected IOException newExceptionOnError(HttpResponse response)
HttpResponse.isSuccessStatusCode()
.
It is guaranteed that HttpResponse.isSuccessStatusCode()
is false
. Default
implementation is to call HttpResponseException.HttpResponseException(HttpResponse)
,
but subclasses may override.
response
- HTTP responsepublic T execute() throws IOException
Subclasses may override by calling the super implementation.
IOException
public InputStream executeAsInputStream() throws IOException
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.
IOException
protected InputStream executeMediaAsInputStream() throws IOException
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.
IOException
public void executeAndDownloadTo(OutputStream outputStream) throws IOException
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.
outputStream
- destination output streamIOException
protected void executeMediaAndDownloadTo(OutputStream outputStream) throws IOException
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.
outputStream
- destination output streamIOException
public final <E> void queue(BatchRequest batchRequest, Class<E> errorClass, BatchCallback<T,E> callback) throws IOException
Batched requests are then executed when BatchRequest.execute()
is called.
batchRequest
- batch request containererrorClass
- data class the unsuccessful response will be parsed into or
Void.class
to ignore the contentcallback
- batch callbackIOException
public AbstractGoogleClientRequest<T> set(String fieldName, Object value)
set
in class GenericData
protected final void checkRequiredParameter(Object value, String name)
AbstractGoogleClient.getSuppressRequiredParameterChecks()
is true.value
- the value of the required parametername
- the name of the required parameterIllegalArgumentException
- if the specified required parameter is null and
AbstractGoogleClient.getSuppressRequiredParameterChecks()
is falseCopyright © 2010–2020 Google. All rights reserved.