Class CommonGoogleJsonClientRequestInitializer (2.6.0)

public class CommonGoogleJsonClientRequestInitializer extends CommonGoogleClientRequestInitializer

Google JSON client request initializer implementation for setting properties like key and userIp.

The simplest usage is to use it to set the key parameter:


 public static final GoogleClientRequestInitializer KEY_INITIALIZER =
        CommonGoogleJsonClientRequestInitializer.newBuilder()
              .setKey(KEY)
              .build();
 

There is also a constructor to set both the key and userIp parameters:


 public static final GoogleClientRequestInitializer INITIALIZER =
       CommonGoogleJsonClientRequestInitializer.newBuilder()
              .setKey(KEY)
              .setUserIp(USER_IP)
              .build();
 

If you want to implement custom logic, extend it like this:


 public static class MyRequestInitializer extends CommonGoogleJsonClientRequestInitializer {

   {@literal @}Override
   public void initialize(AbstractGoogleJsonClientRequest{@literal <}?{@literal>} request)
     throws IOException {
     // custom logic
   }
 }
 

Finally, to set the key and userIp parameters and insert custom logic, extend it like this:


 public static class MyKeyRequestInitializer extends CommonGoogleJsonClientRequestInitializer {

   public MyKeyRequestInitializer() {
     super(KEY, USER_IP);
   }

   {@literal @}Override
   public void initializeJsonRequest
       (AbstractGoogleJsonClientRequest{@literal <}?{@literal>} request) throws IOException {
     // custom logic
   }
 }
 

Subclasses should be thread-safe.

Inheritance

java.lang.Object > CommonGoogleClientRequestInitializer > CommonGoogleJsonClientRequestInitializer

Constructors

CommonGoogleJsonClientRequestInitializer() (deprecated)

public CommonGoogleJsonClientRequestInitializer()

Deprecated. Please use the builder interface

CommonGoogleJsonClientRequestInitializer(String key) (deprecated)

public CommonGoogleJsonClientRequestInitializer(String key)

Deprecated. Please use the builder interface

Parameter
Name Description
key String

API key or null to leave it unchanged

CommonGoogleJsonClientRequestInitializer(String key, String userIp) (deprecated)

public CommonGoogleJsonClientRequestInitializer(String key, String userIp)

Deprecated. Please use the builder interface

Parameters
Name Description
key String

API key or null to leave it unchanged

userIp String

user IP or null to leave it unchanged

Methods

initialize(AbstractGoogleClientRequest<?> request)

public final void initialize(AbstractGoogleClientRequest<?> request)

Subclasses should call super implementation in order to set the key and userIp.

Parameter
Name Description
request AbstractGoogleClientRequest<?>
Overrides
Exceptions
Type Description
IOException

initializeJsonRequest(AbstractGoogleJsonClientRequest<?> request)

protected void initializeJsonRequest(AbstractGoogleJsonClientRequest<?> request)

Initializes a Google JSON client request.

Default implementation does nothing. Called from #initialize(AbstractGoogleClientRequest).

Parameter
Name Description
request AbstractGoogleJsonClientRequest<?>
Exceptions
Type Description
IOException

I/O exception