Skip to content
This repository was archived by the owner on Sep 16, 2023. It is now read-only.

Commit b2260c8

Browse files
feat: Enable REST transport for most of Java and Go clients (#311)
- [ ] Regenerate this pull request now. PiperOrigin-RevId: 456641589 Source-Link: googleapis/googleapis@8a251f5 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9
1 parent da0379e commit b2260c8

File tree

149 files changed

+13454
-11
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+13454
-11
lines changed

google-cloud-channel/pom.xml

+16
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@
5858
<groupId>com.google.api</groupId>
5959
<artifactId>gax-grpc</artifactId>
6060
</dependency>
61+
<dependency>
62+
<groupId>com.google.api</groupId>
63+
<artifactId>gax-httpjson</artifactId>
64+
</dependency>
6165
<dependency>
6266
<groupId>org.threeten</groupId>
6367
<artifactId>threetenbp</artifactId>
@@ -77,12 +81,24 @@
7781
<scope>test</scope>
7882
</dependency>
7983
<!-- Need testing utility classes for generated gRPC clients tests -->
84+
<dependency>
85+
<groupId>com.google.api</groupId>
86+
<artifactId>gax</artifactId>
87+
<classifier>testlib</classifier>
88+
<scope>test</scope>
89+
</dependency>
8090
<dependency>
8191
<groupId>com.google.api</groupId>
8292
<artifactId>gax-grpc</artifactId>
8393
<classifier>testlib</classifier>
8494
<scope>test</scope>
8595
</dependency>
96+
<dependency>
97+
<groupId>com.google.api</groupId>
98+
<artifactId>gax-httpjson</artifactId>
99+
<classifier>testlib</classifier>
100+
<scope>test</scope>
101+
</dependency>
86102
</dependencies>
87103

88104
<profiles>

google-cloud-channel/src/main/java/com/google/cloud/channel/v1/CloudChannelServiceClient.java

+33-5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.api.core.ApiFuture;
2020
import com.google.api.core.ApiFutures;
2121
import com.google.api.gax.core.BackgroundResource;
22+
import com.google.api.gax.httpjson.longrunning.OperationsClient;
2223
import com.google.api.gax.longrunning.OperationFuture;
2324
import com.google.api.gax.paging.AbstractFixedSizeCollection;
2425
import com.google.api.gax.paging.AbstractPage;
@@ -30,7 +31,6 @@
3031
import com.google.cloud.channel.v1.stub.CloudChannelServiceStubSettings;
3132
import com.google.common.util.concurrent.MoreExecutors;
3233
import com.google.longrunning.Operation;
33-
import com.google.longrunning.OperationsClient;
3434
import com.google.protobuf.Empty;
3535
import java.io.IOException;
3636
import java.util.List;
@@ -120,13 +120,29 @@
120120
* CloudChannelServiceClient.create(cloudChannelServiceSettings);
121121
* }</pre>
122122
*
123+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
124+
* the wire:
125+
*
126+
* <pre>{@code
127+
* // This snippet has been automatically generated for illustrative purposes only.
128+
* // It may require modifications to work in your environment.
129+
* CloudChannelServiceSettings cloudChannelServiceSettings =
130+
* CloudChannelServiceSettings.newBuilder()
131+
* .setTransportChannelProvider(
132+
* CloudChannelServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
133+
* .build();
134+
* CloudChannelServiceClient cloudChannelServiceClient =
135+
* CloudChannelServiceClient.create(cloudChannelServiceSettings);
136+
* }</pre>
137+
*
123138
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
124139
*/
125140
@Generated("by gapic-generator-java")
126141
public class CloudChannelServiceClient implements BackgroundResource {
127142
private final CloudChannelServiceSettings settings;
128143
private final CloudChannelServiceStub stub;
129-
private final OperationsClient operationsClient;
144+
private final OperationsClient httpJsonOperationsClient;
145+
private final com.google.longrunning.OperationsClient operationsClient;
130146

131147
/** Constructs an instance of CloudChannelServiceClient with default settings. */
132148
public static final CloudChannelServiceClient create() throws IOException {
@@ -158,13 +174,17 @@ public static final CloudChannelServiceClient create(CloudChannelServiceStub stu
158174
protected CloudChannelServiceClient(CloudChannelServiceSettings settings) throws IOException {
159175
this.settings = settings;
160176
this.stub = ((CloudChannelServiceStubSettings) settings.getStubSettings()).createStub();
161-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
177+
this.operationsClient =
178+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
179+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
162180
}
163181

164182
protected CloudChannelServiceClient(CloudChannelServiceStub stub) {
165183
this.settings = null;
166184
this.stub = stub;
167-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
185+
this.operationsClient =
186+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
187+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
168188
}
169189

170190
public final CloudChannelServiceSettings getSettings() {
@@ -179,10 +199,18 @@ public CloudChannelServiceStub getStub() {
179199
* Returns the OperationsClient that can be used to query the status of a long-running operation
180200
* returned by another API method call.
181201
*/
182-
public final OperationsClient getOperationsClient() {
202+
public final com.google.longrunning.OperationsClient getOperationsClient() {
183203
return operationsClient;
184204
}
185205

206+
/**
207+
* Returns the OperationsClient that can be used to query the status of a long-running operation
208+
* returned by another API method call.
209+
*/
210+
public final OperationsClient getHttpJsonOperationsClient() {
211+
return httpJsonOperationsClient;
212+
}
213+
186214
// AUTO-GENERATED DOCUMENTATION AND METHOD.
187215
/**
188216
* List [Customer][google.cloud.channel.v1.Customer]s.

google-cloud-channel/src/main/java/com/google/cloud/channel/v1/CloudChannelServiceSettings.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import com.google.api.gax.core.GoogleCredentialsProvider;
3636
import com.google.api.gax.core.InstantiatingExecutorProvider;
3737
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
38+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
3839
import com.google.api.gax.rpc.ApiClientHeaderProvider;
3940
import com.google.api.gax.rpc.ClientContext;
4041
import com.google.api.gax.rpc.ClientSettings;
@@ -480,11 +481,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
480481
return CloudChannelServiceStubSettings.defaultCredentialsProviderBuilder();
481482
}
482483

483-
/** Returns a builder for the default ChannelProvider for this service. */
484+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
484485
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
485486
return CloudChannelServiceStubSettings.defaultGrpcTransportProviderBuilder();
486487
}
487488

489+
/** Returns a builder for the default REST ChannelProvider for this service. */
490+
@BetaApi
491+
public static InstantiatingHttpJsonChannelProvider.Builder
492+
defaultHttpJsonTransportProviderBuilder() {
493+
return CloudChannelServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
494+
}
495+
488496
public static TransportChannelProvider defaultTransportChannelProvider() {
489497
return CloudChannelServiceStubSettings.defaultTransportChannelProvider();
490498
}
@@ -494,11 +502,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
494502
return CloudChannelServiceStubSettings.defaultApiClientHeaderProviderBuilder();
495503
}
496504

497-
/** Returns a new builder for this class. */
505+
/** Returns a new gRPC builder for this class. */
498506
public static Builder newBuilder() {
499507
return Builder.createDefault();
500508
}
501509

510+
/** Returns a new REST builder for this class. */
511+
@BetaApi
512+
public static Builder newHttpJsonBuilder() {
513+
return Builder.createHttpJsonDefault();
514+
}
515+
502516
/** Returns a new builder for this class. */
503517
public static Builder newBuilder(ClientContext clientContext) {
504518
return new Builder(clientContext);
@@ -536,6 +550,11 @@ private static Builder createDefault() {
536550
return new Builder(CloudChannelServiceStubSettings.newBuilder());
537551
}
538552

553+
@BetaApi
554+
private static Builder createHttpJsonDefault() {
555+
return new Builder(CloudChannelServiceStubSettings.newHttpJsonBuilder());
556+
}
557+
539558
public CloudChannelServiceStubSettings.Builder getStubSettingsBuilder() {
540559
return ((CloudChannelServiceStubSettings.Builder) getStubSettings());
541560
}

google-cloud-channel/src/main/java/com/google/cloud/channel/v1/stub/CloudChannelServiceStub.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,11 @@
117117
public abstract class CloudChannelServiceStub implements BackgroundResource {
118118

119119
public OperationsStub getOperationsStub() {
120-
throw new UnsupportedOperationException("Not implemented: getOperationsStub()");
120+
return null;
121+
}
122+
123+
public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() {
124+
return null;
121125
}
122126

123127
public UnaryCallable<ListCustomersRequest, ListCustomersPagedResponse>

google-cloud-channel/src/main/java/com/google/cloud/channel/v1/stub/CloudChannelServiceStubSettings.java

+50-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
import com.google.api.gax.grpc.GrpcTransportChannel;
4141
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
4242
import com.google.api.gax.grpc.ProtoOperationTransformers;
43+
import com.google.api.gax.httpjson.GaxHttpJsonProperties;
44+
import com.google.api.gax.httpjson.HttpJsonTransportChannel;
45+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
4346
import com.google.api.gax.longrunning.OperationSnapshot;
4447
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
4548
import com.google.api.gax.retrying.RetrySettings;
@@ -1485,6 +1488,11 @@ public CloudChannelServiceStub createStub() throws IOException {
14851488
.equals(GrpcTransportChannel.getGrpcTransportName())) {
14861489
return GrpcCloudChannelServiceStub.create(this);
14871490
}
1491+
if (getTransportChannelProvider()
1492+
.getTransportName()
1493+
.equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
1494+
return HttpJsonCloudChannelServiceStub.create(this);
1495+
}
14881496
throw new UnsupportedOperationException(
14891497
String.format(
14901498
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -1517,30 +1525,56 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
15171525
.setUseJwtAccessWithScope(true);
15181526
}
15191527

1520-
/** Returns a builder for the default ChannelProvider for this service. */
1528+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
15211529
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
15221530
return InstantiatingGrpcChannelProvider.newBuilder()
15231531
.setMaxInboundMessageSize(Integer.MAX_VALUE);
15241532
}
15251533

1534+
/** Returns a builder for the default REST ChannelProvider for this service. */
1535+
@BetaApi
1536+
public static InstantiatingHttpJsonChannelProvider.Builder
1537+
defaultHttpJsonTransportProviderBuilder() {
1538+
return InstantiatingHttpJsonChannelProvider.newBuilder();
1539+
}
1540+
15261541
public static TransportChannelProvider defaultTransportChannelProvider() {
15271542
return defaultGrpcTransportProviderBuilder().build();
15281543
}
15291544

15301545
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
1531-
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
1546+
public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
15321547
return ApiClientHeaderProvider.newBuilder()
15331548
.setGeneratedLibToken(
15341549
"gapic", GaxProperties.getLibraryVersion(CloudChannelServiceStubSettings.class))
15351550
.setTransportToken(
15361551
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
15371552
}
15381553

1539-
/** Returns a new builder for this class. */
1554+
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
1555+
public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
1556+
return ApiClientHeaderProvider.newBuilder()
1557+
.setGeneratedLibToken(
1558+
"gapic", GaxProperties.getLibraryVersion(CloudChannelServiceStubSettings.class))
1559+
.setTransportToken(
1560+
GaxHttpJsonProperties.getHttpJsonTokenName(),
1561+
GaxHttpJsonProperties.getHttpJsonVersion());
1562+
}
1563+
1564+
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
1565+
return CloudChannelServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
1566+
}
1567+
1568+
/** Returns a new gRPC builder for this class. */
15401569
public static Builder newBuilder() {
15411570
return Builder.createDefault();
15421571
}
15431572

1573+
/** Returns a new REST builder for this class. */
1574+
public static Builder newHttpJsonBuilder() {
1575+
return Builder.createHttpJsonDefault();
1576+
}
1577+
15441578
/** Returns a new builder for this class. */
15451579
public static Builder newBuilder(ClientContext clientContext) {
15461580
return new Builder(clientContext);
@@ -2086,6 +2120,19 @@ private static Builder createDefault() {
20862120
return initDefaults(builder);
20872121
}
20882122

2123+
private static Builder createHttpJsonDefault() {
2124+
Builder builder = new Builder(((ClientContext) null));
2125+
2126+
builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
2127+
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
2128+
builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
2129+
builder.setEndpoint(getDefaultEndpoint());
2130+
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
2131+
builder.setSwitchToMtlsEndpointAllowed(true);
2132+
2133+
return initDefaults(builder);
2134+
}
2135+
20892136
private static Builder initDefaults(Builder builder) {
20902137
builder
20912138
.listCustomersSettings()

0 commit comments

Comments
 (0)