Class HttpRequestFactory (1.43.2)

public final class HttpRequestFactory

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("..."); } }); }

Inheritance

java.lang.Object > HttpRequestFactory

Methods

buildDeleteRequest(GenericUrl url)

public HttpRequest buildDeleteRequest(GenericUrl url)

Builds a DELETE request for the given URL.

Parameter
Name Description
url GenericUrl

HTTP request URL or null for none

Returns
Type Description
HttpRequest

new HTTP request

Exceptions
Type Description
IOException

buildGetRequest(GenericUrl url)

public HttpRequest buildGetRequest(GenericUrl url)

Builds a GET request for the given URL.

Parameter
Name Description
url GenericUrl

HTTP request URL or null for none

Returns
Type Description
HttpRequest

new HTTP request

Exceptions
Type Description
IOException

buildHeadRequest(GenericUrl url)

public HttpRequest buildHeadRequest(GenericUrl url)

Builds a HEAD request for the given URL.

Parameter
Name Description
url GenericUrl

HTTP request URL or null for none

Returns
Type Description
HttpRequest

new HTTP request

Exceptions
Type Description
IOException

buildPatchRequest(GenericUrl url, HttpContent content)

public HttpRequest buildPatchRequest(GenericUrl url, HttpContent content)

Builds a PATCH request for the given URL and content.

Parameters
Name Description
url GenericUrl

HTTP request URL or null for none

content HttpContent

HTTP request content or null for none

Returns
Type Description
HttpRequest

new HTTP request

Exceptions
Type Description
IOException

buildPostRequest(GenericUrl url, HttpContent content)

public HttpRequest buildPostRequest(GenericUrl url, HttpContent content)

Builds a POST request for the given URL and content.

Parameters
Name Description
url GenericUrl

HTTP request URL or null for none

content HttpContent

HTTP request content or null for none

Returns
Type Description
HttpRequest

new HTTP request

Exceptions
Type Description
IOException

buildPutRequest(GenericUrl url, HttpContent content)

public HttpRequest buildPutRequest(GenericUrl url, HttpContent content)

Builds a PUT request for the given URL and content.

Parameters
Name Description
url GenericUrl

HTTP request URL or null for none

content HttpContent

HTTP request content or null for none

Returns
Type Description
HttpRequest

new HTTP request

Exceptions
Type Description
IOException

buildRequest(String requestMethod, GenericUrl url, HttpContent content)

public HttpRequest buildRequest(String requestMethod, GenericUrl url, HttpContent content)

Builds a request for the given HTTP method, URL, and content.

Parameters
Name Description
requestMethod String

HTTP request method

url GenericUrl

HTTP request URL or null for none

content HttpContent

HTTP request content or null for none

Returns
Type Description
HttpRequest

new HTTP request

Exceptions
Type Description
IOException

getInitializer()

public HttpRequestInitializer getInitializer()

Returns the HTTP request initializer or null for none.

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

Returns
Type Description
HttpRequestInitializer

getTransport()

public HttpTransport getTransport()

Returns the HTTP transport.

Returns
Type Description
HttpTransport