# Google Data APIs Client Library (1.43.0)

## com.google.gdata.client.http
Class HttpGDataRequest

    java.lang.Object
      com.google.gdata.client.http.HttpGDataRequest

All Implemented Interfaces:
  Service.GDataRequest

Direct Known Subclasses:
  GoogleGDataRequest

    public class HttpGDataRequest

extends java.lang.Object
implements Service.GDataRequest

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

See Also:
  `Service.GDataRequest`

Nested Class Summary
`static class` `HttpGDataRequest.Factory` The HttpGDataRequest.Factory class is a factory class for constructing new HttpGDataRequest instances.

Nested classes/interfaces inherited from interface com.google.gdata.client.Service.GDataRequest
`Service.GDataRequest.RequestType`

Field Summary
`protected HttpUrlConnectionSource` `connectionSource` Source of `HttpURLConnection` instances.
`protected int` `connectTimeout` The connection timeout for this request.
`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 java.net.HttpURLConnection` `httpConn` Underlying HTTP connection to the GData service.
`protected ContentType` `inputType` Contains the content type of the request data
`static java.lang.String` `METHOD_OVERRIDE_HEADER` Deprecated. Use `GDataProtocol.Header#METHOD_OVERRIDE` instead
`static java.lang.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.
`protected int` `readTimeout` The read timeout for this request.
`protected java.net.URL` `requestUrl` The request URL provided by the client.
`protected Service.GDataRequest.RequestType` `type` The GData request type.

Constructor Summary
`protected` `HttpGDataRequest()` Protected default constructor for testing.

`protected`

`HttpGDataRequest(Service.GDataRequest.RequestType type, java.net.URL requestUrl, ContentType inputType, HttpAuthToken authToken, java.util.Map<java.lang.String,java.lang.String> headerMap, java.util.Map<java.lang.String,java.lang.String> privateHeaderMap, HttpUrlConnectionSource connectionSource)`
Constructs a new HttpGDataRequest instance of the specified RequestType, targeting the specified URL.

Method Summary
`protected void` `checkResponse()` Called after a request is executed to process the response and generate an appropriate exception (on failure).
`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.
`java.net.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.
`protected java.net.HttpURLConnection` `getRequestConnection(java.net.URL requestUrl)` Obtains a connection to 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.
`java.io.OutputStream` `getRequestStream()` Returns a stream that can be used to write request data to the GData service.
`java.net.URL` `getRequestUrl()` Returns the `URL` that is the target of the GData request
`com.google.gdata.util.common.xml.XmlWriter` `getRequestWriter()`
`ContentType` `getResponseContentType()` Returns the content type of the GData response.
`DateTime` `getResponseDateHeader(java.lang.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.
`java.lang.String` `getResponseHeader(java.lang.String headerName)` Returns the value of the specified response header name or `null` if no response header of this type exists.
`java.io.InputStream` `getResponseStream()` Returns an input stream that can be used to read response data from the GData service.
`protected void` `handleErrorResponse()` Handles an error response received while executing a GData service request.
`void` `setConnectTimeout(int timeout)` Sets the number of milliseconds to wait for a connection to the remote GData service before timing out.
`void` `setEtag(java.lang.String etag)` Sets the entity tag value that will be used to conditionalize the request if not `null`.
`void` `setHeader(java.lang.String name, java.lang.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(java.lang.String method)`
`void` `setPrivateHeader(java.lang.String name, java.lang.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.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### METHOD_OVERRIDE_PROPERTY

    public static final java.lang.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.

  See Also:
    Constant Field Values

### METHOD_OVERRIDE_HEADER

    @Deprecated
    public static final java.lang.String METHOD_OVERRIDE_HEADER

  Deprecated. Use `GDataProtocol.Header#METHOD_OVERRIDE` instead
  Name of HTTP header containing the method name that overrides the normal HTTP method.

  See Also:
    Constant Field Values

### connectionSource

    protected final HttpUrlConnectionSource connectionSource

  Source of `HttpURLConnection` instances.

### httpConn

    protected java.net.HttpURLConnection httpConn

  Underlying HTTP connection to the GData service.

### requestUrl

    protected java.net.URL requestUrl

  The request URL provided by the client.

### type

    protected Service.GDataRequest.RequestType type

  The GData request type.

### executed

    protected boolean executed

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

### expectsInput

    protected boolean expectsInput

  True if the request type expects input from the client.

### inputType

    protected ContentType inputType

  Contains the content type of the request data

### hasOutput

    protected boolean hasOutput

  True if the request type returns output to the client.

### connectTimeout

    protected int connectTimeout

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

### readTimeout

    protected int readTimeout

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

Constructor Detail

### HttpGDataRequest

    protected HttpGDataRequest(Service.GDataRequest.RequestType type,
                               java.net.URL requestUrl,
                               ContentType inputType,
                               HttpAuthToken authToken,
                               java.util.Map<java.lang.String,java.lang.String> headerMap,
                               java.util.Map<java.lang.String,java.lang.String> privateHeaderMap,
                               HttpUrlConnectionSource connectionSource)
                        throws java.io.IOException

  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`).
    `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 `HttpURLConnection`s
  Throws:
    `java.io.IOException` - on error initializating service connection.

### HttpGDataRequest

    protected HttpGDataRequest()

  Protected default constructor for testing.

Method Detail

### getRequestUrl

    public java.net.URL getRequestUrl()

  Description copied from interface: `Service.GDataRequest`
  Returns the `URL` that is the target of the GData request

  Specified by:
    `getRequestUrl` in interface `Service.GDataRequest`

### getRequestContentType

    public ContentType getRequestContentType()

  Description copied from interface: `Service.GDataRequest`
  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.

  Specified by:
    `getRequestContentType` in interface `Service.GDataRequest`

### getRequestConnection

    protected java.net.HttpURLConnection getRequestConnection(java.net.URL requestUrl)
                                                       throws java.io.IOException

  Obtains a connection to the GData service.

  Throws:
    `java.io.IOException`

### setConnectTimeout

    public void setConnectTimeout(int timeout)

  Description copied from interface: `Service.GDataRequest`
  Sets the number of milliseconds to wait for a connection to the remote GData service before timing out.

  Specified by:
    `setConnectTimeout` in interface `Service.GDataRequest`
  Parameters:
    `timeout` - the read timeout. A value of zero indicates an infinite timeout.
  See Also:
    `URLConnection.setConnectTimeout(int)`

### setReadTimeout

    public void setReadTimeout(int timeout)

  Description copied from interface: `Service.GDataRequest`
  Sets the number of milliseconds to wait for a response from the remote GData service before timing out.

  Specified by:
    `setReadTimeout` in interface `Service.GDataRequest`
  Parameters:
    `timeout` - the read timeout. A value of zero indicates an infinite timeout.
  See Also:
    `URLConnection.setReadTimeout(int)`

### setIfModifiedSince

    public void setIfModifiedSince(DateTime conditionDate)

  Description copied from interface: `Service.GDataRequest`
  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.

  Specified by:
    `setIfModifiedSince` in interface `Service.GDataRequest`
  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.

### setEtag

    public void setEtag(java.lang.String etag)

  Description copied from interface: `Service.GDataRequest`
  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.

  Specified by:
    `setEtag` in interface `Service.GDataRequest`

### getRequestStream

    public java.io.OutputStream getRequestStream()
                                          throws java.io.IOException

  Description copied from interface: `Service.GDataRequest`
  Returns a stream that can be used to write request data to the GData service.

  Specified by:
    `getRequestStream` in interface `Service.GDataRequest`
  Returns:
    OutputStream that can be used to write GData request data.
  Throws:
    `java.io.IOException` - error obtaining the request output stream.

### getRequestWriter

    public com.google.gdata.util.common.xml.XmlWriter getRequestWriter()
                                                                throws java.io.IOException

  Throws:
    `java.io.IOException`

### setMethod

    public void setMethod(java.lang.String method)
                   throws java.net.ProtocolException

  Throws:
    `java.net.ProtocolException`

### setHeader

    public void setHeader(java.lang.String name,
                          java.lang.String value)

  Description copied from interface: `Service.GDataRequest`
  Sets a request header (and logs it, if logging is enabled)

  Specified by:
    `setHeader` in interface `Service.GDataRequest`
  Parameters:
    `name` - the header name
    `value` - the header value

### setPrivateHeader

    public void setPrivateHeader(java.lang.String name,
                                 java.lang.String value)

  Description copied from interface: `Service.GDataRequest`
  Sets request header (and log just the name but not the value, if logging is enabled)

  Specified by:
    `setPrivateHeader` in interface `Service.GDataRequest`
  Parameters:
    `name` - the header name
    `value` - the header value

### execute

    public void execute()
                 throws java.io.IOException,
                        ServiceException

  Description copied from interface: `Service.GDataRequest`
  Executes the GData service request.

  Specified by:
    `execute` in interface `Service.GDataRequest`
  Throws:
    `java.io.IOException` - error writing to or reading from GData service.
    `ResourceNotFoundException` - invalid request target resource.
    `ServiceException` - system error executing request.

### checkResponse

    protected void checkResponse()
                          throws java.io.IOException,
                                 ServiceException

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

  Throws:
    `java.io.IOException`
    `ServiceException`

### handleErrorResponse

    protected void handleErrorResponse()
                                throws ServiceException,
                                       java.io.IOException

  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.
    `java.io.IOException` - error reading the error response from the GData service.

### getResponseContentType

    public ContentType getResponseContentType()

  Description copied from interface: `Service.GDataRequest`
  Returns the content type of the GData response.

  Specified by:
    `getResponseContentType` in interface `Service.GDataRequest`
  Returns:
    ContentType the GData response content type or `null` if no response content.

### getResponseHeader

    public java.lang.String getResponseHeader(java.lang.String headerName)

  Description copied from interface: `Service.GDataRequest`
  Returns the value of the specified response header name or `null` if no response header of this type exists.

  Specified by:
    `getResponseHeader` in interface `Service.GDataRequest`
  Parameters:
    `headerName` - name of header
  Returns:
    header value.

### getResponseDateHeader

    public DateTime getResponseDateHeader(java.lang.String headerName)

  Description copied from interface: `Service.GDataRequest`
  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.

  Specified by:
    `getResponseDateHeader` in interface `Service.GDataRequest`
  Parameters:
    `headerName` - name of header
  Returns:
    header value.

### getResponseStream

    public java.io.InputStream getResponseStream()
                                          throws java.io.IOException

  Description copied from interface: `Service.GDataRequest`
  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 `Service.GDataRequest.getParseSource()` instead.

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

  Specified by:
    `getResponseStream` in interface `Service.GDataRequest`
  Returns:
    InputStream providing access to GData response input stream.
  Throws:
    `java.io.IOException` - error obtaining the response input stream.

### getParseSource

    public ParseSource getParseSource()
                               throws java.io.IOException

  Description copied from interface: `Service.GDataRequest`
  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.

  Specified by:
    `getParseSource` in interface `Service.GDataRequest`
  Returns:
    ParseSource providing access to GData response data.
  Throws:
    `java.io.IOException` - error obtaining the response data.

### getConnection

    public java.net.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.

### end

    public void end()

  Description copied from interface: `Service.GDataRequest`
  Ends all processing associated with this request and releases any transient resources (such as open data streams) required for execution.

  Specified by:
    `end` in interface `Service.GDataRequest`