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 > CommonGoogleJsonClientRequestInitializerConstructors
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 |
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 |
userIp |
String user IP or |
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<?> |
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 |