public static interface

Service.GDataRequest

com.google.gdata.client.Service.GDataRequest
Known Indirect Subclasses

Class Overview

The GDataRequest interface represents a streaming connection to a GData service that can be used either to send request data to the service using an OutputStream (or XmlWriter for XML content) or to receive response data from the service as an InputStream (or ParseSource for XML data). The calling client then has full control of the request data generation and response data parsing. This can be used to integrate GData services with an external Atom or RSS parsing library, such as Rome.

A GDataRequest instance will be returned by the streaming client APIs of the Service class. The basic usage pattern is:

 GDataRequest request = ...     // createXXXRequest API call
 try {
    OutputStream requestStream = request.getRequestStream();
    // stream request data, if any
    request.execute()                // execute the request
    InputStream responseStream = request.getResponseStream();
    // process the response data, if any
 }
 catch (IOException ioe) {
    // handle errors writing to / reading from server
 } catch (ServiceException se) {
    // handle service invocation errors
 } finally {
   request.end();
 }
 

Summary

Nested Classes
enum Service.GDataRequest.RequestType The RequestType enumeration defines the set of expected GData request types. 
Public Methods
abstract void end()
Ends all processing associated with this request and releases any transient resources (such as open data streams) required for execution.
abstract void execute()
Executes the GData service request.
abstract ParseSource getParseSource()
Returns a parse source that can be used to read response data from the GData service.
abstract 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.
abstract OutputStream getRequestStream()
Returns a stream that can be used to write request data to the GData service.
abstract URL getRequestUrl()
Returns the URL that is the target of the GData request
abstract ContentType getResponseContentType()
Returns the content type of the GData response.
abstract 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.
abstract String getResponseHeader(String headerName)
Returns the value of the specified response header name or null if no response header of this type exists.
abstract InputStream getResponseStream()
Returns an input stream that can be used to read response data from the GData service.
abstract void setConnectTimeout(int timeout)
Sets the number of milliseconds to wait for a connection to the remote GData service before timing out.
abstract void setEtag(String etag)
Sets the entity tag value that will be used to conditionalize the request if not null.
abstract void setHeader(String name, String value)
Sets a request header (and logs it, if logging is enabled)
abstract void setIfModifiedSince(DateTime conditionDate)
Sets the If-Modified-Since date precondition to be applied to the request.
abstract void setPrivateHeader(String name, String value)
Sets request header (and log just the name but not the value, if logging is enabled)
abstract void setReadTimeout(int timeout)
Sets the number of milliseconds to wait for a response from the remote GData service before timing out.

Public Methods

public abstract void end ()

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

public abstract void execute ()

Executes the GData service request.

Throws
IOException error writing to or reading from GData service.
ResourceNotFoundException invalid request target resource.
ServiceException system error executing request.

public abstract 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
IllegalStateException attempt to read response without first calling execute().
IOException error obtaining the response data.
ServiceException error obtaining the response data.

public abstract 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 abstract 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 error obtaining the request output stream.

public abstract URL getRequestUrl ()

Returns the URL that is the target of the GData request

public abstract ContentType getResponseContentType ()

Returns the content type of the GData response.

Returns
  • ContentType the GData response content type or null if no response content.
Throws
IllegalStateException attempt to read content type without first calling execute().
IOException error obtaining the response content type.
ServiceException error obtaining the response content type.

public abstract 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 abstract 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 abstract 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
IllegalStateException attempt to read response without first calling execute().
IOException error obtaining the response input stream.

public abstract 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.
Throws
IllegalArgumentException if the timeout value is negative.

public abstract 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 abstract 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 abstract 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 abstract 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 abstract 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.
Throws
IllegalArgumentException if the timeout value is negative.