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

Commit 42ffff7

Browse files
feat: Enable REST transport for most of Java and Go clients (#1168)
- [ ] 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 8bafc76 commit 42ffff7

File tree

256 files changed

+19268
-44
lines changed

Some content is hidden

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

256 files changed

+19268
-44
lines changed

google-cloud-automl/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@
6262
<groupId>com.google.api</groupId>
6363
<artifactId>gax-grpc</artifactId>
6464
</dependency>
65+
<dependency>
66+
<groupId>com.google.api</groupId>
67+
<artifactId>gax-httpjson</artifactId>
68+
</dependency>
6569
<dependency>
6670
<groupId>org.threeten</groupId>
6771
<artifactId>threetenbp</artifactId>
@@ -85,12 +89,24 @@
8589
<scope>test</scope>
8690
</dependency>
8791
<!-- Need testing utility classes for generated gRPC clients tests -->
92+
<dependency>
93+
<groupId>com.google.api</groupId>
94+
<artifactId>gax</artifactId>
95+
<classifier>testlib</classifier>
96+
<scope>test</scope>
97+
</dependency>
8898
<dependency>
8999
<groupId>com.google.api</groupId>
90100
<artifactId>gax-grpc</artifactId>
91101
<classifier>testlib</classifier>
92102
<scope>test</scope>
93103
</dependency>
104+
<dependency>
105+
<groupId>com.google.api</groupId>
106+
<artifactId>gax-httpjson</artifactId>
107+
<classifier>testlib</classifier>
108+
<scope>test</scope>
109+
</dependency>
94110
</dependencies>
95111

96112
<profiles>

google-cloud-automl/src/main/java/com/google/cloud/automl/v1/AutoMlClient.java

Lines changed: 32 additions & 5 deletions
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.automl.v1.stub.AutoMlStubSettings;
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 com.google.protobuf.FieldMask;
3636
import java.io.IOException;
@@ -113,13 +113,28 @@
113113
* AutoMlClient autoMlClient = AutoMlClient.create(autoMlSettings);
114114
* }</pre>
115115
*
116+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
117+
* the wire:
118+
*
119+
* <pre>{@code
120+
* // This snippet has been automatically generated for illustrative purposes only.
121+
* // It may require modifications to work in your environment.
122+
* AutoMlSettings autoMlSettings =
123+
* AutoMlSettings.newBuilder()
124+
* .setTransportChannelProvider(
125+
* AutoMlSettings.defaultHttpJsonTransportProviderBuilder().build())
126+
* .build();
127+
* AutoMlClient autoMlClient = AutoMlClient.create(autoMlSettings);
128+
* }</pre>
129+
*
116130
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
117131
*/
118132
@Generated("by gapic-generator-java")
119133
public class AutoMlClient implements BackgroundResource {
120134
private final AutoMlSettings settings;
121135
private final AutoMlStub stub;
122-
private final OperationsClient operationsClient;
136+
private final OperationsClient httpJsonOperationsClient;
137+
private final com.google.longrunning.OperationsClient operationsClient;
123138

124139
/** Constructs an instance of AutoMlClient with default settings. */
125140
public static final AutoMlClient create() throws IOException {
@@ -149,13 +164,17 @@ public static final AutoMlClient create(AutoMlStub stub) {
149164
protected AutoMlClient(AutoMlSettings settings) throws IOException {
150165
this.settings = settings;
151166
this.stub = ((AutoMlStubSettings) settings.getStubSettings()).createStub();
152-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
167+
this.operationsClient =
168+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
169+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
153170
}
154171

155172
protected AutoMlClient(AutoMlStub stub) {
156173
this.settings = null;
157174
this.stub = stub;
158-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
175+
this.operationsClient =
176+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
177+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
159178
}
160179

161180
public final AutoMlSettings getSettings() {
@@ -170,10 +189,18 @@ public AutoMlStub getStub() {
170189
* Returns the OperationsClient that can be used to query the status of a long-running operation
171190
* returned by another API method call.
172191
*/
173-
public final OperationsClient getOperationsClient() {
192+
public final com.google.longrunning.OperationsClient getOperationsClient() {
174193
return operationsClient;
175194
}
176195

196+
/**
197+
* Returns the OperationsClient that can be used to query the status of a long-running operation
198+
* returned by another API method call.
199+
*/
200+
public final OperationsClient getHttpJsonOperationsClient() {
201+
return httpJsonOperationsClient;
202+
}
203+
177204
// AUTO-GENERATED DOCUMENTATION AND METHOD.
178205
/**
179206
* Creates a dataset.

google-cloud-automl/src/main/java/com/google/cloud/automl/v1/AutoMlSettings.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.api.gax.core.GoogleCredentialsProvider;
2626
import com.google.api.gax.core.InstantiatingExecutorProvider;
2727
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
28+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
2829
import com.google.api.gax.rpc.ApiClientHeaderProvider;
2930
import com.google.api.gax.rpc.ClientContext;
3031
import com.google.api.gax.rpc.ClientSettings;
@@ -250,11 +251,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
250251
return AutoMlStubSettings.defaultCredentialsProviderBuilder();
251252
}
252253

253-
/** Returns a builder for the default ChannelProvider for this service. */
254+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
254255
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
255256
return AutoMlStubSettings.defaultGrpcTransportProviderBuilder();
256257
}
257258

259+
/** Returns a builder for the default REST ChannelProvider for this service. */
260+
@BetaApi
261+
public static InstantiatingHttpJsonChannelProvider.Builder
262+
defaultHttpJsonTransportProviderBuilder() {
263+
return AutoMlStubSettings.defaultHttpJsonTransportProviderBuilder();
264+
}
265+
258266
public static TransportChannelProvider defaultTransportChannelProvider() {
259267
return AutoMlStubSettings.defaultTransportChannelProvider();
260268
}
@@ -264,11 +272,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
264272
return AutoMlStubSettings.defaultApiClientHeaderProviderBuilder();
265273
}
266274

267-
/** Returns a new builder for this class. */
275+
/** Returns a new gRPC builder for this class. */
268276
public static Builder newBuilder() {
269277
return Builder.createDefault();
270278
}
271279

280+
/** Returns a new REST builder for this class. */
281+
@BetaApi
282+
public static Builder newHttpJsonBuilder() {
283+
return Builder.createHttpJsonDefault();
284+
}
285+
272286
/** Returns a new builder for this class. */
273287
public static Builder newBuilder(ClientContext clientContext) {
274288
return new Builder(clientContext);
@@ -306,6 +320,11 @@ private static Builder createDefault() {
306320
return new Builder(AutoMlStubSettings.newBuilder());
307321
}
308322

323+
@BetaApi
324+
private static Builder createHttpJsonDefault() {
325+
return new Builder(AutoMlStubSettings.newHttpJsonBuilder());
326+
}
327+
309328
public AutoMlStubSettings.Builder getStubSettingsBuilder() {
310329
return ((AutoMlStubSettings.Builder) getStubSettings());
311330
}

google-cloud-automl/src/main/java/com/google/cloud/automl/v1/PredictionServiceClient.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
package com.google.cloud.automl.v1;
1818

1919
import com.google.api.gax.core.BackgroundResource;
20+
import com.google.api.gax.httpjson.longrunning.OperationsClient;
2021
import com.google.api.gax.longrunning.OperationFuture;
2122
import com.google.api.gax.rpc.OperationCallable;
2223
import com.google.api.gax.rpc.UnaryCallable;
2324
import com.google.cloud.automl.v1.stub.PredictionServiceStub;
2425
import com.google.cloud.automl.v1.stub.PredictionServiceStubSettings;
2526
import com.google.longrunning.Operation;
26-
import com.google.longrunning.OperationsClient;
2727
import java.io.IOException;
2828
import java.util.Map;
2929
import java.util.concurrent.TimeUnit;
@@ -101,13 +101,29 @@
101101
* PredictionServiceClient.create(predictionServiceSettings);
102102
* }</pre>
103103
*
104+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
105+
* the wire:
106+
*
107+
* <pre>{@code
108+
* // This snippet has been automatically generated for illustrative purposes only.
109+
* // It may require modifications to work in your environment.
110+
* PredictionServiceSettings predictionServiceSettings =
111+
* PredictionServiceSettings.newBuilder()
112+
* .setTransportChannelProvider(
113+
* PredictionServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
114+
* .build();
115+
* PredictionServiceClient predictionServiceClient =
116+
* PredictionServiceClient.create(predictionServiceSettings);
117+
* }</pre>
118+
*
104119
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
105120
*/
106121
@Generated("by gapic-generator-java")
107122
public class PredictionServiceClient implements BackgroundResource {
108123
private final PredictionServiceSettings settings;
109124
private final PredictionServiceStub stub;
110-
private final OperationsClient operationsClient;
125+
private final OperationsClient httpJsonOperationsClient;
126+
private final com.google.longrunning.OperationsClient operationsClient;
111127

112128
/** Constructs an instance of PredictionServiceClient with default settings. */
113129
public static final PredictionServiceClient create() throws IOException {
@@ -139,13 +155,17 @@ public static final PredictionServiceClient create(PredictionServiceStub stub) {
139155
protected PredictionServiceClient(PredictionServiceSettings settings) throws IOException {
140156
this.settings = settings;
141157
this.stub = ((PredictionServiceStubSettings) settings.getStubSettings()).createStub();
142-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
158+
this.operationsClient =
159+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
160+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
143161
}
144162

145163
protected PredictionServiceClient(PredictionServiceStub stub) {
146164
this.settings = null;
147165
this.stub = stub;
148-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
166+
this.operationsClient =
167+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
168+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
149169
}
150170

151171
public final PredictionServiceSettings getSettings() {
@@ -160,10 +180,18 @@ public PredictionServiceStub getStub() {
160180
* Returns the OperationsClient that can be used to query the status of a long-running operation
161181
* returned by another API method call.
162182
*/
163-
public final OperationsClient getOperationsClient() {
183+
public final com.google.longrunning.OperationsClient getOperationsClient() {
164184
return operationsClient;
165185
}
166186

187+
/**
188+
* Returns the OperationsClient that can be used to query the status of a long-running operation
189+
* returned by another API method call.
190+
*/
191+
public final OperationsClient getHttpJsonOperationsClient() {
192+
return httpJsonOperationsClient;
193+
}
194+
167195
// AUTO-GENERATED DOCUMENTATION AND METHOD.
168196
/**
169197
* Perform an online prediction. The prediction result is directly returned in the response.

google-cloud-automl/src/main/java/com/google/cloud/automl/v1/PredictionServiceSettings.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.google.api.gax.core.GoogleCredentialsProvider;
2222
import com.google.api.gax.core.InstantiatingExecutorProvider;
2323
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
24+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
2425
import com.google.api.gax.rpc.ApiClientHeaderProvider;
2526
import com.google.api.gax.rpc.ClientContext;
2627
import com.google.api.gax.rpc.ClientSettings;
@@ -111,11 +112,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
111112
return PredictionServiceStubSettings.defaultCredentialsProviderBuilder();
112113
}
113114

114-
/** Returns a builder for the default ChannelProvider for this service. */
115+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
115116
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
116117
return PredictionServiceStubSettings.defaultGrpcTransportProviderBuilder();
117118
}
118119

120+
/** Returns a builder for the default REST ChannelProvider for this service. */
121+
@BetaApi
122+
public static InstantiatingHttpJsonChannelProvider.Builder
123+
defaultHttpJsonTransportProviderBuilder() {
124+
return PredictionServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
125+
}
126+
119127
public static TransportChannelProvider defaultTransportChannelProvider() {
120128
return PredictionServiceStubSettings.defaultTransportChannelProvider();
121129
}
@@ -125,11 +133,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
125133
return PredictionServiceStubSettings.defaultApiClientHeaderProviderBuilder();
126134
}
127135

128-
/** Returns a new builder for this class. */
136+
/** Returns a new gRPC builder for this class. */
129137
public static Builder newBuilder() {
130138
return Builder.createDefault();
131139
}
132140

141+
/** Returns a new REST builder for this class. */
142+
@BetaApi
143+
public static Builder newHttpJsonBuilder() {
144+
return Builder.createHttpJsonDefault();
145+
}
146+
133147
/** Returns a new builder for this class. */
134148
public static Builder newBuilder(ClientContext clientContext) {
135149
return new Builder(clientContext);
@@ -167,6 +181,11 @@ private static Builder createDefault() {
167181
return new Builder(PredictionServiceStubSettings.newBuilder());
168182
}
169183

184+
@BetaApi
185+
private static Builder createHttpJsonDefault() {
186+
return new Builder(PredictionServiceStubSettings.newHttpJsonBuilder());
187+
}
188+
170189
public PredictionServiceStubSettings.Builder getStubSettingsBuilder() {
171190
return ((PredictionServiceStubSettings.Builder) getStubSettings());
172191
}

google-cloud-automl/src/main/java/com/google/cloud/automl/v1/stub/AutoMlStub.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@
6464
public abstract class AutoMlStub implements BackgroundResource {
6565

6666
public OperationsStub getOperationsStub() {
67-
throw new UnsupportedOperationException("Not implemented: getOperationsStub()");
67+
return null;
68+
}
69+
70+
public com.google.api.gax.httpjson.longrunning.stub.OperationsStub getHttpJsonOperationsStub() {
71+
return null;
6872
}
6973

7074
public OperationCallable<CreateDatasetRequest, Dataset, OperationMetadata>

0 commit comments

Comments
 (0)