2.9.3 (latest) 2.9.2 2.8.1 2.7.2 2.6.0 2.5.1 2.4.1 2.1.2 2.0.1 1.35.2 1.34.1 1.33.4

```java
public class CommonGoogleProtoClientRequestInitializer extends CommonGoogleClientRequestInitializer
```
Beta   

Google protocol buffer client request initializer implementation for setting properties like key
and userIp.

The simplest usage is to use it to set the key parameter:

```java

 public static final GoogleClientRequestInitializer KEY_INITIALIZER =
   new CommonGoogleProtoClientRequestInitializer(KEY);
 
```

There is also a constructor to set both the key and userIp parameters:

```java

 public static final GoogleClientRequestInitializer INITIALIZER =
   new CommonGoogleProtoClientRequestInitializer(KEY, USER_IP);
 
```

If you want to implement custom logic, extend it like this:

```java

 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:

```java

 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.

## Inheritance

[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \> [CommonGoogleClientRequestInitializer](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt) \> CommonGoogleProtoClientRequestInitializer

## Inherited Members

[CommonGoogleClientRequestInitializer.getKey()](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_getKey__) [CommonGoogleClientRequestInitializer.getRequestReason()](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_getRequestReason__) [CommonGoogleClientRequestInitializer.getUserAgent()](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_getUserAgent__) [CommonGoogleClientRequestInitializer.getUserIp()](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_getUserIp__) [CommonGoogleClientRequestInitializer.getUserProject()](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_getUserProject__) [CommonGoogleClientRequestInitializer.initialize(AbstractGoogleClientRequest\<?\>)](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_initialize_com_google_api_client_googleapis_services_AbstractGoogleClientRequest____) [CommonGoogleClientRequestInitializer.newBuilder()](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_newBuilder__) [Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) [Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) [Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) [Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) [Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) [Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) [Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) [Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) [Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) [Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) [Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)

## Constructors

### CommonGoogleProtoClientRequestInitializer()

```java
public CommonGoogleProtoClientRequestInitializer()
```

### CommonGoogleProtoClientRequestInitializer(String key)

```java
public CommonGoogleProtoClientRequestInitializer(String key)
```

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `String` API key or `null` to leave it unchanged |

### CommonGoogleProtoClientRequestInitializer(String key, String userIp)

```java
public CommonGoogleProtoClientRequestInitializer(String key, String userIp)
```

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `String` API key or `null` to leave it unchanged |
| `userIp` | `String` user IP or `null` to leave it unchanged |

## Methods

### initialize(AbstractGoogleClientRequest\<?\> request)

```java
public final void initialize(AbstractGoogleClientRequest<?> request)
```
Subclasses should call super implementation in order to set the key and userIp.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `AbstractGoogleClientRequest<?>` |

**Overrides** [CommonGoogleClientRequestInitializer.initialize(AbstractGoogleClientRequest\<?\> request)](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.CommonGoogleClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_CommonGoogleClientRequestInitializer_initialize_com_google_api_client_googleapis_services_AbstractGoogleClientRequest____)

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `IOException` |   |

### initializeProtoRequest(AbstractGoogleProtoClientRequest\<?\> request)

```java
protected void initializeProtoRequest(AbstractGoogleProtoClientRequest<?> request)
```
Initializes a Google protocol buffer client request.

Default implementation does nothing. Called from [#initialize(AbstractGoogleClientRequest)](https://docs.cloud.google.com/java/docs/reference/google-api-client/latest/com.google.api.client.googleapis.services.protobuf.CommonGoogleProtoClientRequestInitializer.md.txt#com_google_api_client_googleapis_services_protobuf_CommonGoogleProtoClientRequestInitializer_initialize_com_google_api_client_googleapis_services_AbstractGoogleClientRequest____).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `request` | `AbstractGoogleProtoClientRequest<?>` |

| **Exceptions** ||
|---|---|
| **Type** | **Description** |
| `IOException` | I/O exception |