com.google.api.client.http
Class HttpRequest

java.lang.Object
  extended by com.google.api.client.http.HttpRequest

public final class HttpRequest
extends Object

HTTP request.

Since:
1.0
Author:
Yaniv Inbar

Field Summary
 int connectTimeout
          Timeout in milliseconds to establish a connection or 0 for an infinite timeout.
 HttpContent content
          HTTP request content or null for none.
 boolean disableContentLogging
          Whether to disable request content logging during execute() (unless Level.ALL is loggable which forces all logging).
 boolean enableGZipContent
          Whether to enable gzip compression of HTTP content (false by default).
 HttpHeaders headers
          HTTP request headers.
 HttpExecuteInterceptor interceptor
          HTTP request execute interceptor to intercept the start of execute() (before executing the HTTP request) or null for none.
 HttpMethod method
          HTTP request method.
 int numRetries
          Set the number of retries that will be allowed to execute as the result of an HttpUnsuccessfulResponseHandler before being terminated or 0 to not retry requests.
 int readTimeout
          Timeout in milliseconds to read data from an established connection or 0 for an infinite timeout.
 HttpHeaders responseHeaders
          HTTP response headers.
 HttpTransport transport
          HTTP transport.
 HttpUnsuccessfulResponseHandler unsuccessfulResponseHandler
          HTTP unsuccessful (non-2XX) response handler.
 GenericUrl url
          HTTP request URL.
static String USER_AGENT_SUFFIX
          User agent suffix for all requests.
 
Method Summary
 void addParser(HttpParser parser)
          Adds an HTTP response content parser.
 HttpResponse execute()
          Execute the HTTP request and returns the HTTP response.
 HttpParser getParser(String contentType)
          Returns the HTTP response content parser to use for the given content type or null if none is defined.
static String normalizeMediaType(String mediaType)
          Returns the normalized media type without parameters of the form type "/" subtype" as specified in Media Types.
 void setUrl(String encodedUrl)
          Deprecated. (scheduled to be removed in 1.5) Use GenericUrl.GenericUrl(String)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USER_AGENT_SUFFIX

public static final String USER_AGENT_SUFFIX
User agent suffix for all requests.

Since:
1.4
See Also:
Constant Field Values

interceptor

public HttpExecuteInterceptor interceptor
HTTP request execute interceptor to intercept the start of execute() (before executing the HTTP request) or null for none.

Since:
1.4

headers

public HttpHeaders headers
HTTP request headers.

For backwards compatibility, its value is initialized by calling clone() on the HttpTransport.defaultHeaders, which by default is an instance of HttpHeaders.


responseHeaders

public HttpHeaders responseHeaders
HTTP response headers.

For example, this can be used if you want to use a subclass of HttpHeaders called MyHeaders to process the response:

  static String executeAndGetValueOfSomeCustomHeader(HttpRequest request) {
    MyHeaders responseHeaders = new MyHeaders();
    request.responseHeaders = responseHeaders;
    HttpResponse response = request.execute();
    return responseHeaders.someCustomHeader;
  }
 

For backwards compatibility, its value is initialized by calling clone() on the HttpTransport.defaultHeaders, which by default is an instance of HttpHeaders.

Since:
1.4

numRetries

public int numRetries
Set the number of retries that will be allowed to execute as the result of an HttpUnsuccessfulResponseHandler before being terminated or 0 to not retry requests. The default value is 10.

Since:
1.4

disableContentLogging

public boolean disableContentLogging
Whether to disable request content logging during execute() (unless Level.ALL is loggable which forces all logging).

Useful for example if content has sensitive data such as an authentication information. Defaults to false.


content

public HttpContent content
HTTP request content or null for none.


transport

public final HttpTransport transport
HTTP transport.


method

public HttpMethod method
HTTP request method.

Since:
1.3

url

public GenericUrl url
HTTP request URL.


connectTimeout

public int connectTimeout
Timeout in milliseconds to establish a connection or 0 for an infinite timeout.

By default it is 20 seconds.

Since:
1.4

readTimeout

public int readTimeout
Timeout in milliseconds to read data from an established connection or 0 for an infinite timeout.

By default it is 20 seconds.

Since:
1.4

unsuccessfulResponseHandler

public HttpUnsuccessfulResponseHandler unsuccessfulResponseHandler
HTTP unsuccessful (non-2XX) response handler.

Since:
1.4

enableGZipContent

public boolean enableGZipContent
Whether to enable gzip compression of HTTP content (false by default).

Upgrade warning: in prior version 1.3, gzip compression was enabled whenever the content length was >= 256 bytes, the content type was text-based ("text/*" or "application/*"), and there was no encoding defined. With version 1.4, the decision is entirely based on this field.

Since:
1.4
Method Detail

setUrl

@Deprecated
public void setUrl(String encodedUrl)
Deprecated. (scheduled to be removed in 1.5) Use GenericUrl.GenericUrl(String)

Sets the url based on the given encoded URL string.


addParser

public void addParser(HttpParser parser)
Adds an HTTP response content parser.

If there is already a previous parser defined for this new parser (as defined by getParser(String) then the previous parser will be removed.

Since:
1.4

getParser

public final HttpParser getParser(String contentType)
Returns the HTTP response content parser to use for the given content type or null if none is defined.

Parameters:
contentType - content type or null for null result
Returns:
HTTP response content parser or null for null input
Since:
1.4

execute

public HttpResponse execute()
                     throws IOException
Execute the HTTP request and returns the HTTP response.

Note that regardless of the returned status code, the HTTP response content has not been parsed yet, and must be parsed by the calling code.

Almost all details of the request and response are logged if Level.CONFIG is loggable. The only exception is the value of the Authorization header which is only logged if Level.ALL is loggable.

Returns:
HTTP response for an HTTP success code
Throws:
HttpResponseException - for an HTTP error code
IOException
See Also:
HttpResponse.isSuccessStatusCode

normalizeMediaType

public static String normalizeMediaType(String mediaType)
Returns the normalized media type without parameters of the form type "/" subtype" as specified in Media Types.

Parameters:
mediaType - unnormalized media type with possible parameters or null for null result
Returns:
normalized media type without parameters or null for null input
Since:
1.4


Copyright © 2010-2011 Google. All Rights Reserved.