public class CommonGoogleClientRequestInitializer implements GoogleClientRequestInitializerGoogle 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.
Implements
GoogleClientRequestInitializerStatic Methods
newBuilder()
public static CommonGoogleClientRequestInitializer.Builder newBuilder()Returns new builder.
| Type | Description |
| CommonGoogleClientRequestInitializer.Builder |
Constructors
CommonGoogleClientRequestInitializer() (deprecated)
public CommonGoogleClientRequestInitializer()Deprecated. Please use the builder interface
CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder)
protected CommonGoogleClientRequestInitializer(CommonGoogleClientRequestInitializer.Builder builder)| Name | Description |
| builder | CommonGoogleClientRequestInitializer.Builder |
CommonGoogleClientRequestInitializer(String key) (deprecated)
public CommonGoogleClientRequestInitializer(String key)Deprecated. Please use the builder interface
| Name | Description |
| key | StringAPI key or |
CommonGoogleClientRequestInitializer(String key, String userIp) (deprecated)
public CommonGoogleClientRequestInitializer(String key, String userIp)Deprecated. Please use the builder interface
| Name | Description |
| key | StringAPI key or |
| userIp | Stringuser IP or |
Methods
getKey()
public final String getKey()Returns the API key or null to leave it unchanged.
| Type | Description |
| String |
getRequestReason()
public final String getRequestReason()Returns the request reason or null to leave it unchanged.
| Type | Description |
| String |
getUserAgent()
public final String getUserAgent()Returns the user agent or null to leave it unchanged.
| Type | Description |
| String |
getUserIp()
public final String getUserIp()Returns the user IP or null to leave it unchanged.
| Type | Description |
| String |
getUserProject()
public final String getUserProject()Returns the user project or null.
| Type | Description |
| String |
initialize(AbstractGoogleClientRequest<?> request)
public void initialize(AbstractGoogleClientRequest<?> request)Subclasses should call super implementation in order to set the key and userIp.
| Name | Description |
| request | AbstractGoogleClientRequest<?> |
| Type | Description |
| IOException | I/O exception |