Class MethodOverride (2.0.0)

public final class MethodOverride implements HttpExecuteInterceptor, HttpRequestInitializer

Thread-safe HTTP request execute interceptor for Google API's that wraps HTTP requests inside of a POST request and uses #HEADER header to specify the actual HTTP method.

Use this for example for an HTTP transport that doesn't support PATCH like NetHttpTransport or UrlFetchTransport. By default, only the methods not supported by the transport will be overridden. When running behind a firewall that does not support certain verbs like PATCH, use the MethodOverride.Builder#setOverrideAllMethods(boolean) constructor instead to specify to override all methods. POST is never overridden.

This class also allows GET requests with a long URL (> 2048 chars) to be instead sent using method override as a POST request.

Sample usage, taking advantage that this class implements HttpRequestInitializer:


 public static HttpRequestFactory createRequestFactory(HttpTransport transport) {
   return transport.createRequestFactory(new MethodOverride());
 }
 

If you have a custom request initializer, take a look at the sample usage for HttpExecuteInterceptor, which this class also implements.

Inheritance

java.lang.Object > MethodOverride

Implements

com.google.api.client.http.HttpExecuteInterceptor, com.google.api.client.http.HttpRequestInitializer

Static Fields

HEADER

public static final String HEADER

Name of the method override header.

Field Value
TypeDescription
String

Constructors

MethodOverride()

public MethodOverride()

Only overrides HTTP methods that the HTTP transport does not support.

Methods

initialize(HttpRequest request)

public void initialize(HttpRequest request)
Parameter
NameDescription
requestcom.google.api.client.http.HttpRequest

intercept(HttpRequest request)

public void intercept(HttpRequest request)
Parameter
NameDescription
requestcom.google.api.client.http.HttpRequest
Exceptions
TypeDescription
IOException