public class

HttpGDataRequest

extends Object
implements Service.GDataRequest
java.lang.Object
   ↳ com.google.gdata.client.http.HttpGDataRequest
Known Direct Subclasses

Class Overview

The HttpGDataRequest class provides a basic implementation of the GDataRequest interface over HTTP.

Summary

Nested Classes
class HttpGDataRequest.Factory The HttpGDataRequest.Factory class is a factory class for constructing new HttpGDataRequest instances. 
Constants
String METHOD_OVERRIDE_HEADER This constant is deprecated. Use METHOD_OVERRIDE instead
String METHOD_OVERRIDE_PROPERTY If this system property is set to true, the GData HTTP client library will use POST to send data to the associated GData service and will specify the actual method using the METHOD_OVERRIDE_HEADER HTTP header.
Fields
protected final HttpAuthToken authToken The auth token used for this request, may be null.
protected int connectTimeout The connection timeout for this request.
protected final HttpUrlConnectionSource connectionSource Source of HttpURLConnection instances.
protected boolean executed Indicates whether request execution has taken place.
protected boolean expectsInput True if the request type expects input from the client.
protected boolean hasOutput True if the request type returns output to the client.
protected HttpURLConnection httpConn Underlying HTTP connection to the GData service.
private InputStream inputStream The input stream from which HTTP response data may be read or null if no response stream or not opened yet via getResponseStream().
protected ContentType inputType Contains the content type of the request data
static final Logger logger
protected int readTimeout The read timeout for this request.
protected URL requestUrl The request URL provided by the client.
protected Service.GDataRequest.RequestType type The GData request type.
Protected Constructors
HttpGDataRequest(Service.GDataRequest.RequestType type, URL requestUrl, ContentType inputType, HttpAuthToken authToken, Map<String, String> headerMap, Map<String, String> privateHeaderMap, HttpUrlConnectionSource connectionSource)
Constructs a new HttpGDataRequest instance of the specified RequestType, targeting the specified URL.
HttpGDataRequest()
Protected default constructor for testing.
Public Methods
void end()
Ends all processing associated with this request and releases any transient resources (such as open data streams) required for execution.
void execute()
Executes the GData service request.
HttpURLConnection getConnection()
Returns the URLConnection instance that represents the underlying connection to the GData service that will be used by this request.
ParseSource getParseSource()
Returns a parse source that can be used to read response data from the GData service.
ContentType getRequestContentType()
Returns the ContentType of the data that will be written to the service by this request or null if no data is written to the server by the request.
OutputStream getRequestStream()
Returns a stream that can be used to write request data to the GData service.
URL getRequestUrl()
Returns the URL that is the target of the GData request
XmlWriter getRequestWriter()
ContentType getResponseContentType()
Returns the content type of the GData response.
DateTime getResponseDateHeader(String headerName)
Returns the value of a header containing a header or null if no response header of this type exists or it could not be parsed as a valid date.
String getResponseHeader(String headerName)
Returns the value of the specified response header name or null if no response header of this type exists.
InputStream getResponseStream()
Returns an input stream that can be used to read response data from the GData service.
void setConnectTimeout(int timeout)
Sets the number of milliseconds to wait for a connection to the remote GData service before timing out.
void setEtag(String etag)
Sets the entity tag value that will be used to conditionalize the request if not null.
void setHeader(String name, String value)
Sets a request header (and logs it, if logging is enabled)
void setIfModifiedSince(DateTime conditionDate)
Sets the If-Modified-Since date precondition to be applied to the request.
void setMethod(String method)
void setPrivateHeader(String name, String value)
Sets request header (and log just the name but not the value, if logging is enabled)
void setReadTimeout(int timeout)
Sets the number of milliseconds to wait for a response from the remote GData service before timing out.
Protected Methods
void checkResponse()
Called after a request is executed to process the response and generate an appropriate exception (on failure).
HttpURLConnection getRequestConnection(URL requestUrl)
Obtains a connection to the GData service.
void handleErrorResponse()
Handles an error response received while executing a GData service request.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.google.gdata.client.Service.GDataRequest

Constants

public static final String METHOD_OVERRIDE_HEADER

This constant is deprecated.
Use METHOD_OVERRIDE instead

Name of HTTP header containing the method name that overrides the normal HTTP method.

Constant Value: "X-HTTP-Method-Override"

public static final String METHOD_OVERRIDE_PROPERTY

If this system property is set to true, the GData HTTP client library will use POST to send data to the associated GData service and will specify the actual method using the METHOD_OVERRIDE_HEADER HTTP header. This can be used as a workaround for HTTP proxies or gateways that do not handle PUT or DELETE HTTP methods properly. If the system property is false, the regular PUT and DELETE HTTP verbs will be used.

Constant Value: "com.google.gdata.UseMethodOverride"

Fields

protected final HttpAuthToken authToken

The auth token used for this request, may be null.

protected int connectTimeout

The connection timeout for this request. A value of -1 means no value has been configured (use JDK default timeout behavior).

protected final HttpUrlConnectionSource connectionSource

Source of HttpURLConnection instances.

protected boolean executed

Indicates whether request execution has taken place. Set to true if executed, false otherwise.

protected boolean expectsInput

True if the request type expects input from the client.

protected boolean hasOutput

True if the request type returns output to the client.

protected HttpURLConnection httpConn

Underlying HTTP connection to the GData service.

private InputStream inputStream

The input stream from which HTTP response data may be read or null if no response stream or not opened yet via getResponseStream().

protected ContentType inputType

Contains the content type of the request data

static final Logger logger

protected int readTimeout

The read timeout for this request. A value of -1 means no value has been configured (use JDK default timeout behavior).

protected URL requestUrl

The request URL provided by the client.

protected Service.GDataRequest.RequestType type

The GData request type.

Protected Constructors

protected HttpGDataRequest (Service.GDataRequest.RequestType type, URL requestUrl, ContentType inputType, HttpAuthToken authToken, Map<String, String> headerMap, Map<String, String> privateHeaderMap, HttpUrlConnectionSource connectionSource)

Constructs a new HttpGDataRequest instance of the specified RequestType, targeting the specified URL.

Parameters
type Type of GDataRequest.
requestUrl Request target URL.
inputType The content type of request data (or null).
authToken The auth token used for this request (or null).
headerMap A set of headers to be included in each request
privateHeaderMap A set of headers to be included in each request
connectionSource Source of HttpURLConnections
Throws
IOException on error initializating service connection.

protected HttpGDataRequest ()

Protected default constructor for testing.

Public Methods

public void end ()

Ends all processing associated with this request and releases any transient resources (such as open data streams) required for execution.

public void execute ()

Executes the GData service request.

Throws
IOException
ServiceException

public HttpURLConnection getConnection ()

Returns the URLConnection instance that represents the underlying connection to the GData service that will be used by this request.

Returns
  • connection to GData service.

public ParseSource getParseSource ()

Returns a parse source that can be used to read response data from the GData service. Parse source is an abstraction over input streams, readers, and other forms of input.

The caller is responsible for ensuring that input streams and readers contained in the parse source are properly closed after the response has been read.

Returns
  • ParseSource providing access to GData response data.
Throws
IOException

public ContentType getRequestContentType ()

Returns the ContentType of the data that will be written to the service by this request or null if no data is written to the server by the request.

public OutputStream getRequestStream ()

Returns a stream that can be used to write request data to the GData service.

Returns
  • OutputStream that can be used to write GData request data.
Throws
IOException

public URL getRequestUrl ()

Returns the URL that is the target of the GData request

public XmlWriter getRequestWriter ()

Throws
IOException

public ContentType getResponseContentType ()

Returns the content type of the GData response.

Returns
  • ContentType the GData response content type or null if no response content.

public DateTime getResponseDateHeader (String headerName)

Returns the value of a header containing a header or null if no response header of this type exists or it could not be parsed as a valid date.

Parameters
headerName Name of header
Returns
  • header value.

public String getResponseHeader (String headerName)

Returns the value of the specified response header name or null if no response header of this type exists.

Parameters
headerName Name of header
Returns
  • header value.

public InputStream getResponseStream ()

Returns an input stream that can be used to read response data from the GData service. Returns null if response data cannot be read as an input stream. Use getParseSource() instead.

The caller is responsible for ensuring that the input stream is properly closed after the response has been read.

Returns
  • InputStream providing access to GData response input stream.
Throws
IOException

public void setConnectTimeout (int timeout)

Sets the number of milliseconds to wait for a connection to the remote GData service before timing out.

Parameters
timeout The read timeout. A value of zero indicates an infinite timeout.

public void setEtag (String etag)

Sets the entity tag value that will be used to conditionalize the request if not null. For a query requests, the tag will cause the target resource to be returned if the resource entity tag does not match the specified value (i.e. if the resource has not changed). For update or delete request types, the entity tag value is used to indicate that the requested operation should occur only if the specified etag value does match the specified value (i.e. if the resource has changed). A request entity tag value may not be associated with other request types.

Parameters
etag

public void setHeader (String name, String value)

Sets a request header (and logs it, if logging is enabled)

Parameters
name The header name
value The header value

public void setIfModifiedSince (DateTime conditionDate)

Sets the If-Modified-Since date precondition to be applied to the request. If this precondition is set, then the request will be performed only if the target resource has been modified since the specified date; otherwise, a NotModifiedException will be thrown. The default value is null, indicating no precondition.

Parameters
conditionDate The date that should be used to limit the operation on the target resource. The operation will only be performed if the resource has been modified later than the specified date.

public void setMethod (String method)

Parameters
method
Throws
ProtocolException

public void setPrivateHeader (String name, String value)

Sets request header (and log just the name but not the value, if logging is enabled)

Parameters
name The header name
value The header value

public void setReadTimeout (int timeout)

Sets the number of milliseconds to wait for a response from the remote GData service before timing out.

Parameters
timeout The read timeout. A value of zero indicates an infinite timeout.

Protected Methods

protected void checkResponse ()

Called after a request is executed to process the response and generate an appropriate exception (on failure).

Throws
IOException
ServiceException

protected HttpURLConnection getRequestConnection (URL requestUrl)

Obtains a connection to the GData service.

Parameters
requestUrl
Throws
IOException

protected void handleErrorResponse ()

Handles an error response received while executing a GData service request. Throws a ServiceException or one of its subclasses, depending on the failure conditions.

Throws
ServiceException exception describing the failure.
IOException error reading the error response from the GData service.