Class CommonGoogleClientRequestInitializer (1.35.1)

public class CommonGoogleClientRequestInitializer implements GoogleClientRequestInitializer

Google common 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 =
        CommonGoogleClientRequestInitializer.newBuilder()
              .setKey(KEY)
              .build();
 

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


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

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


 public static class MyRequestInitializer extends CommonGoogleClientRequestInitializer {

   {@literal @}Override
   public void initialize
       (AbstractGoogleClientRequest{@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 MyRequestInitializer2 extends CommonGoogleClientRequestInitializer {

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

   {@literal @}Override
   public void initialize
       (AbstractGoogleClientRequest{@literal <}?{@literal>} request) throws IOException {
     super.initialize(request); // must be called to set the key and userIp parameters
     // insert some additional logic
   }
 }
 

Subclasses should be thread-safe.

Inheritance

java.lang.Object > CommonGoogleClientRequestInitializer

Static Methods

newBuilder()

public static CommonGoogleClientRequestInitializer.Builder newBuilder()

Returns new builder.

Returns
TypeDescription
CommonGoogleClientRequestInitializer.Builder

Constructors

CommonGoogleClientRequestInitializer() (deprecated)

public CommonGoogleClientRequestInitializer()

Deprecated. Please use the builder interface

CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder)

protected CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder)
Parameter
NameDescription
builderCommonGoogleClientRequestInitializer.Builder

CommonGoogleClientRequestInitializer(String key) (deprecated)

public CommonGoogleClientRequestInitializer(String key)

Deprecated. Please use the builder interface

Parameter
NameDescription
keyString

API key or null to leave it unchanged

CommonGoogleClientRequestInitializer(String key, String userIp) (deprecated)

public CommonGoogleClientRequestInitializer(String key, String userIp)

Deprecated. Please use the builder interface

Parameters
NameDescription
keyString

API key or null to leave it unchanged

userIpString

user IP or null to leave it unchanged

Methods

getKey()

public final String getKey()

Returns the API key or null to leave it unchanged.

Returns
TypeDescription
String

getRequestReason()

public final String getRequestReason()

Returns the request reason or null to leave it unchanged.

Returns
TypeDescription
String

getUserAgent()

public final String getUserAgent()

Returns the user agent or null to leave it unchanged.

Returns
TypeDescription
String

getUserIp()

public final String getUserIp()

Returns the user IP or null to leave it unchanged.

Returns
TypeDescription
String

getUserProject()

public final String getUserProject()

Returns the user project or null.

Returns
TypeDescription
String

initialize(AbstractGoogleClientRequest<?> request)

public void initialize(AbstractGoogleClientRequest<?> request)

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

Parameter
NameDescription
requestAbstractGoogleClientRequest<?>
Exceptions
TypeDescription
IOException

I/O exception