public class CommonGoogleJsonClientRequestInitializer extends CommonGoogleClientRequestInitializer
The simplest usage is to use it to set the key parameter:
public static final GoogleClientRequestInitializer KEY_INITIALIZER = new CommonGoogleJsonClientRequestInitializer(KEY);
There is also a constructor to set both the key and userIp parameters:
public static final GoogleClientRequestInitializer INITIALIZER = new CommonGoogleJsonClientRequestInitializer(KEY, USER_IP);
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.
Constructor and Description |
---|
CommonGoogleJsonClientRequestInitializer() |
CommonGoogleJsonClientRequestInitializer(String key) |
CommonGoogleJsonClientRequestInitializer(String key,
String userIp) |
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, getUserIp
public CommonGoogleJsonClientRequestInitializer()
public CommonGoogleJsonClientRequestInitializer(String key)
key
- API key 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–2019 Google. All rights reserved.