public class CommonGoogleJsonClientRequestInitializer extends CommonGoogleClientRequestInitializer
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 { @Override public void initialize(AbstractGoogleJsonClientRequest <? > 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); } @Override public void initializeJsonRequest( AbstractGoogleJsonClientRequest <? > request) throws IOException { // custom logic } }
Subclasses should be thread-safe.
Modifier and Type | Class and Description |
---|---|
static class |
CommonGoogleJsonClientRequestInitializer.Builder
Builder for
CommonGoogleJsonClientRequestInitializer . |
Constructor and Description |
---|
CommonGoogleJsonClientRequestInitializer()
Deprecated.
Please use the builder interface
|
CommonGoogleJsonClientRequestInitializer(String key)
Deprecated.
Please use the builder interface
|
CommonGoogleJsonClientRequestInitializer(String key,
String userIp)
Deprecated.
Please use the builder interface
|
Modifier and Type | Method and Description |
---|---|
void |
initialize(AbstractGoogleClientRequest<?> request)
Subclasses should call super implementation in order to set the key and userIp.
|
protected void |
initializeJsonRequest(AbstractGoogleJsonClientRequest<?> request)
Initializes a Google JSON client request.
|
getKey, getRequestReason, getUserAgent, getUserIp, getUserProject, newBuilder
@Deprecated public CommonGoogleJsonClientRequestInitializer()
@Deprecated public CommonGoogleJsonClientRequestInitializer(String key)
key
- API key or null
to leave it unchanged@Deprecated public CommonGoogleJsonClientRequestInitializer(String key, String userIp)
key
- API key or null
to leave it unchangeduserIp
- user IP or null
to leave it unchangedpublic final void initialize(AbstractGoogleClientRequest<?> request) throws IOException
CommonGoogleClientRequestInitializer
initialize
in interface GoogleClientRequestInitializer
initialize
in class CommonGoogleClientRequestInitializer
IOException
- I/O exceptionprotected void initializeJsonRequest(AbstractGoogleJsonClientRequest<?> request) throws IOException
Default implementation does nothing. Called from initialize(AbstractGoogleClientRequest)
.
IOException
- I/O exceptionCopyright © 2010–2021 Google. All rights reserved.