com.google.api.client.http
Class HttpRequestFactory

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

public final class HttpRequestFactory
extends Object

Thread-safe light-weight HTTP request factory layer on top of the HTTP transport that has an optional HTTP request initializer for initializing requests.

For example, to use a particular authorization header across all requests, use:

  public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
    return transport.createRequestFactory(new HttpRequestInitializer() {
      public void initialize(HttpRequest request) throws IOException {
        request.getHeaders().setAuthorization("...");
      }
    });
  }
 

Since:
1.4
Author:
Yaniv Inbar

Method Summary
 HttpRequest buildDeleteRequest(GenericUrl url)
          Builds a DELETE request for the given URL.
 HttpRequest buildGetRequest(GenericUrl url)
          Builds a GET request for the given URL.
 HttpRequest buildHeadRequest(GenericUrl url)
          Builds a HEAD request for the given URL.
 HttpRequest buildPatchRequest(GenericUrl url, HttpContent content)
          Builds a PATCH request for the given URL and content.
 HttpRequest buildPostRequest(GenericUrl url, HttpContent content)
          Builds a POST request for the given URL and content.
 HttpRequest buildPutRequest(GenericUrl url, HttpContent content)
          Builds a PUT request for the given URL and content.
 HttpRequest buildRequest(HttpMethod method, GenericUrl url, HttpContent content)
          Builds a request for the given HTTP method, URL, and content.
 HttpRequestInitializer getInitializer()
          Returns the HTTP request initializer or null for none.
 HttpTransport getTransport()
          Returns the HTTP transport.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getTransport

public HttpTransport getTransport()
Returns the HTTP transport.

Since:
1.5

getInitializer

public HttpRequestInitializer getInitializer()
Returns the HTTP request initializer or null for none.

This initializer is invoked before setting its method, URL, or content.

Since:
1.5

buildRequest

public HttpRequest buildRequest(HttpMethod method,
                                GenericUrl url,
                                HttpContent content)
                         throws IOException
Builds a request for the given HTTP method, URL, and content.

Parameters:
method - HTTP request method
url - HTTP request URL or null for none
content - HTTP request content or null for none
Returns:
new HTTP request
Throws:
IOException

buildDeleteRequest

public HttpRequest buildDeleteRequest(GenericUrl url)
                               throws IOException
Builds a DELETE request for the given URL.

Parameters:
url - HTTP request URL or null for none
Returns:
new HTTP request
Throws:
IOException

buildGetRequest

public HttpRequest buildGetRequest(GenericUrl url)
                            throws IOException
Builds a GET request for the given URL.

Parameters:
url - HTTP request URL or null for none
Returns:
new HTTP request
Throws:
IOException

buildPostRequest

public HttpRequest buildPostRequest(GenericUrl url,
                                    HttpContent content)
                             throws IOException
Builds a POST request for the given URL and content.

Parameters:
url - HTTP request URL or null for none
content - HTTP request content or null for none
Returns:
new HTTP request
Throws:
IOException

buildPutRequest

public HttpRequest buildPutRequest(GenericUrl url,
                                   HttpContent content)
                            throws IOException
Builds a PUT request for the given URL and content.

Parameters:
url - HTTP request URL or null for none
content - HTTP request content or null for none
Returns:
new HTTP request
Throws:
IOException

buildPatchRequest

public HttpRequest buildPatchRequest(GenericUrl url,
                                     HttpContent content)
                              throws IOException
Builds a PATCH request for the given URL and content.

Parameters:
url - HTTP request URL or null for none
content - HTTP request content or null for none
Returns:
new HTTP request
Throws:
IOException

buildHeadRequest

public HttpRequest buildHeadRequest(GenericUrl url)
                             throws IOException
Builds a HEAD request for the given URL.

Parameters:
url - HTTP request URL or null for none
Returns:
new HTTP request
Throws:
IOException


Copyright © 2011-2012 Google. All Rights Reserved.