@Beta public class CommonGoogleProtoClientRequestInitializer extends CommonGoogleClientRequestInitializer
Beta
The simplest usage is to use it to set the key parameter:
public static final GoogleClientRequestInitializer KEY_INITIALIZER =
new CommonGoogleProtoClientRequestInitializer(KEY);
There is also a constructor to set both the key and userIp parameters:
public static final GoogleClientRequestInitializer INITIALIZER =
new CommonGoogleProtoClientRequestInitializer(KEY, USER_IP);
If you want to implement custom logic, extend it like this:
public static class MyRequestInitializer extends CommonGoogleProtoClientRequestInitializer {
{@literal @}Override
public void initialize(AbstractGoogleProtoClientRequest{@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 CommonGoogleProtoClientRequestInitializer {
public MyKeyRequestInitializer() {
super(KEY, USER_IP);
}
{@literal @}Override
public void initializeProtoRequest(
AbstractGoogleProtoClientRequest{@literal <}?{@literal >} request) throws IOException {
// custom logic
}
}
Subclasses should be thread-safe.
CommonGoogleClientRequestInitializer.Builder
Constructor and Description |
---|
CommonGoogleProtoClientRequestInitializer() |
CommonGoogleProtoClientRequestInitializer(String key) |
CommonGoogleProtoClientRequestInitializer(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 |
initializeProtoRequest(AbstractGoogleProtoClientRequest<?> request)
Initializes a Google protocol buffer client request.
|
getKey, getRequestReason, getUserAgent, getUserIp, getUserProject, newBuilder
public CommonGoogleProtoClientRequestInitializer()
public CommonGoogleProtoClientRequestInitializer(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 initializeProtoRequest(AbstractGoogleProtoClientRequest<?> request) throws IOException
Default implementation does nothing. Called from initialize(AbstractGoogleClientRequest)
.
IOException
- I/O exceptionCopyright © 2010–2022 Google. All rights reserved.