Class HttpRequestFactory (1.42.3)

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
NameDescription
urlGenericUrl

HTTP request URL or null for none

Returns
TypeDescription
HttpRequest

new HTTP request

Exceptions
TypeDescription
IOException

buildGetRequest(GenericUrl url)

public HttpRequest buildGetRequest(GenericUrl url)

Builds a GET request for the given URL.

Parameter
NameDescription
urlGenericUrl

HTTP request URL or null for none

Returns
TypeDescription
HttpRequest

new HTTP request

Exceptions
TypeDescription
IOException

buildHeadRequest(GenericUrl url)

public HttpRequest buildHeadRequest(GenericUrl url)

Builds a HEAD request for the given URL.

Parameter
NameDescription
urlGenericUrl

HTTP request URL or null for none

Returns
TypeDescription
HttpRequest

new HTTP request

Exceptions
TypeDescription
IOException

buildPatchRequest(GenericUrl url, HttpContent content)

public HttpRequest buildPatchRequest(GenericUrl url, HttpContent content)

Builds a PATCH request for the given URL and content.

Parameters
NameDescription
urlGenericUrl

HTTP request URL or null for none

contentHttpContent

HTTP request content or null for none

Returns
TypeDescription
HttpRequest

new HTTP request

Exceptions
TypeDescription
IOException

buildPostRequest(GenericUrl url, HttpContent content)

public HttpRequest buildPostRequest(GenericUrl url, HttpContent content)

Builds a POST request for the given URL and content.

Parameters
NameDescription
urlGenericUrl

HTTP request URL or null for none

contentHttpContent

HTTP request content or null for none

Returns
TypeDescription
HttpRequest

new HTTP request

Exceptions
TypeDescription
IOException

buildPutRequest(GenericUrl url, HttpContent content)

public HttpRequest buildPutRequest(GenericUrl url, HttpContent content)

Builds a PUT request for the given URL and content.

Parameters
NameDescription
urlGenericUrl

HTTP request URL or null for none

contentHttpContent

HTTP request content or null for none

Returns
TypeDescription
HttpRequest

new HTTP request

Exceptions
TypeDescription
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
NameDescription
requestMethodString

HTTP request method

urlGenericUrl

HTTP request URL or null for none

contentHttpContent

HTTP request content or null for none

Returns
TypeDescription
HttpRequest

new HTTP request

Exceptions
TypeDescription
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
TypeDescription
HttpRequestInitializer

getTransport()

public HttpTransport getTransport()

Returns the HTTP transport.

Returns
TypeDescription
HttpTransport