Skip to content

Commit 12bb34a

Browse files
feat: Enable REST transport for most of Java and Go clients (#230)
- [ ] 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 4a08b21 commit 12bb34a

File tree

42 files changed

+3195
-8
lines changed

Some content is hidden

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

42 files changed

+3195
-8
lines changed

java-essential-contacts/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ If you are using Maven, add this to your pom.xml file:
1919
<dependency>
2020
<groupId>com.google.cloud</groupId>
2121
<artifactId>google-cloud-essential-contacts</artifactId>
22-
<version>2.2.0</version>
22+
<version>2.2.1</version>
2323
</dependency>
2424
```
2525

2626
If you are using Gradle without BOM, add this to your dependencies
2727

2828
```Groovy
29-
implementation 'com.google.cloud:google-cloud-essential-contacts:2.2.0'
29+
implementation 'com.google.cloud:google-cloud-essential-contacts:2.2.1'
3030
```
3131

3232
If you are using SBT, add this to your dependencies
3333

3434
```Scala
35-
libraryDependencies += "com.google.cloud" % "google-cloud-essential-contacts" % "2.2.0"
35+
libraryDependencies += "com.google.cloud" % "google-cloud-essential-contacts" % "2.2.1"
3636
```
3737

3838
## Authentication

java-essential-contacts/google-cloud-essential-contacts/pom.xml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@
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>
65+
<dependency>
66+
<groupId>com.google.api</groupId>
67+
<artifactId>gax-httpjson</artifactId>
68+
</dependency>
6169
<dependency>
6270
<groupId>org.threeten</groupId>
6371
<artifactId>threetenbp</artifactId>
@@ -77,12 +85,36 @@
7785
<scope>test</scope>
7886
</dependency>
7987
<!-- Need testing utility classes for generated gRPC clients tests -->
88+
<dependency>
89+
<groupId>com.google.api</groupId>
90+
<artifactId>gax</artifactId>
91+
<classifier>testlib</classifier>
92+
<scope>test</scope>
93+
</dependency>
94+
<dependency>
95+
<groupId>com.google.api</groupId>
96+
<artifactId>gax</artifactId>
97+
<classifier>testlib</classifier>
98+
<scope>test</scope>
99+
</dependency>
80100
<dependency>
81101
<groupId>com.google.api</groupId>
82102
<artifactId>gax-grpc</artifactId>
83103
<classifier>testlib</classifier>
84104
<scope>test</scope>
85105
</dependency>
106+
<dependency>
107+
<groupId>com.google.api</groupId>
108+
<artifactId>gax-httpjson</artifactId>
109+
<classifier>testlib</classifier>
110+
<scope>test</scope>
111+
</dependency>
112+
<dependency>
113+
<groupId>com.google.api</groupId>
114+
<artifactId>gax-httpjson</artifactId>
115+
<classifier>testlib</classifier>
116+
<scope>test</scope>
117+
</dependency>
86118
</dependencies>
87119

88120
<profiles>

java-essential-contacts/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceClient.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,21 @@
103103
* EssentialContactsServiceClient.create(essentialContactsServiceSettings);
104104
* }</pre>
105105
*
106+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
107+
* the wire:
108+
*
109+
* <pre>{@code
110+
* // This snippet has been automatically generated for illustrative purposes only.
111+
* // It may require modifications to work in your environment.
112+
* EssentialContactsServiceSettings essentialContactsServiceSettings =
113+
* EssentialContactsServiceSettings.newBuilder()
114+
* .setTransportChannelProvider(
115+
* EssentialContactsServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
116+
* .build();
117+
* EssentialContactsServiceClient essentialContactsServiceClient =
118+
* EssentialContactsServiceClient.create(essentialContactsServiceSettings);
119+
* }</pre>
120+
*
106121
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
107122
*/
108123
@Generated("by gapic-generator-java")

java-essential-contacts/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/EssentialContactsServiceSettings.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.api.gax.core.GoogleCredentialsProvider;
2525
import com.google.api.gax.core.InstantiatingExecutorProvider;
2626
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
27+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
2728
import com.google.api.gax.rpc.ApiClientHeaderProvider;
2829
import com.google.api.gax.rpc.ClientContext;
2930
import com.google.api.gax.rpc.ClientSettings;
@@ -139,11 +140,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
139140
return EssentialContactsServiceStubSettings.defaultCredentialsProviderBuilder();
140141
}
141142

142-
/** Returns a builder for the default ChannelProvider for this service. */
143+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
143144
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
144145
return EssentialContactsServiceStubSettings.defaultGrpcTransportProviderBuilder();
145146
}
146147

148+
/** Returns a builder for the default REST ChannelProvider for this service. */
149+
@BetaApi
150+
public static InstantiatingHttpJsonChannelProvider.Builder
151+
defaultHttpJsonTransportProviderBuilder() {
152+
return EssentialContactsServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
153+
}
154+
147155
public static TransportChannelProvider defaultTransportChannelProvider() {
148156
return EssentialContactsServiceStubSettings.defaultTransportChannelProvider();
149157
}
@@ -153,11 +161,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
153161
return EssentialContactsServiceStubSettings.defaultApiClientHeaderProviderBuilder();
154162
}
155163

156-
/** Returns a new builder for this class. */
164+
/** Returns a new gRPC builder for this class. */
157165
public static Builder newBuilder() {
158166
return Builder.createDefault();
159167
}
160168

169+
/** Returns a new REST builder for this class. */
170+
@BetaApi
171+
public static Builder newHttpJsonBuilder() {
172+
return Builder.createHttpJsonDefault();
173+
}
174+
161175
/** Returns a new builder for this class. */
162176
public static Builder newBuilder(ClientContext clientContext) {
163177
return new Builder(clientContext);
@@ -196,6 +210,11 @@ private static Builder createDefault() {
196210
return new Builder(EssentialContactsServiceStubSettings.newBuilder());
197211
}
198212

213+
@BetaApi
214+
private static Builder createHttpJsonDefault() {
215+
return new Builder(EssentialContactsServiceStubSettings.newHttpJsonBuilder());
216+
}
217+
199218
public EssentialContactsServiceStubSettings.Builder getStubSettingsBuilder() {
200219
return ((EssentialContactsServiceStubSettings.Builder) getStubSettings());
201220
}

java-essential-contacts/google-cloud-essential-contacts/src/main/java/com/google/cloud/essentialcontacts/v1/stub/EssentialContactsServiceStubSettings.java

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import com.google.api.gax.grpc.GaxGrpcProperties;
2929
import com.google.api.gax.grpc.GrpcTransportChannel;
3030
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
31+
import com.google.api.gax.httpjson.GaxHttpJsonProperties;
32+
import com.google.api.gax.httpjson.HttpJsonTransportChannel;
33+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
3134
import com.google.api.gax.retrying.RetrySettings;
3235
import com.google.api.gax.rpc.ApiCallContext;
3336
import com.google.api.gax.rpc.ApiClientHeaderProvider;
@@ -268,6 +271,11 @@ public EssentialContactsServiceStub createStub() throws IOException {
268271
.equals(GrpcTransportChannel.getGrpcTransportName())) {
269272
return GrpcEssentialContactsServiceStub.create(this);
270273
}
274+
if (getTransportChannelProvider()
275+
.getTransportName()
276+
.equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
277+
return HttpJsonEssentialContactsServiceStub.create(this);
278+
}
271279
throw new UnsupportedOperationException(
272280
String.format(
273281
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -300,30 +308,56 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
300308
.setUseJwtAccessWithScope(true);
301309
}
302310

303-
/** Returns a builder for the default ChannelProvider for this service. */
311+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
304312
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
305313
return InstantiatingGrpcChannelProvider.newBuilder()
306314
.setMaxInboundMessageSize(Integer.MAX_VALUE);
307315
}
308316

317+
/** Returns a builder for the default REST ChannelProvider for this service. */
318+
@BetaApi
319+
public static InstantiatingHttpJsonChannelProvider.Builder
320+
defaultHttpJsonTransportProviderBuilder() {
321+
return InstantiatingHttpJsonChannelProvider.newBuilder();
322+
}
323+
309324
public static TransportChannelProvider defaultTransportChannelProvider() {
310325
return defaultGrpcTransportProviderBuilder().build();
311326
}
312327

313328
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
314-
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
329+
public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
315330
return ApiClientHeaderProvider.newBuilder()
316331
.setGeneratedLibToken(
317332
"gapic", GaxProperties.getLibraryVersion(EssentialContactsServiceStubSettings.class))
318333
.setTransportToken(
319334
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
320335
}
321336

322-
/** Returns a new builder for this class. */
337+
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
338+
public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
339+
return ApiClientHeaderProvider.newBuilder()
340+
.setGeneratedLibToken(
341+
"gapic", GaxProperties.getLibraryVersion(EssentialContactsServiceStubSettings.class))
342+
.setTransportToken(
343+
GaxHttpJsonProperties.getHttpJsonTokenName(),
344+
GaxHttpJsonProperties.getHttpJsonVersion());
345+
}
346+
347+
public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
348+
return EssentialContactsServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
349+
}
350+
351+
/** Returns a new gRPC builder for this class. */
323352
public static Builder newBuilder() {
324353
return Builder.createDefault();
325354
}
326355

356+
/** Returns a new REST builder for this class. */
357+
public static Builder newHttpJsonBuilder() {
358+
return Builder.createHttpJsonDefault();
359+
}
360+
327361
/** Returns a new builder for this class. */
328362
public static Builder newBuilder(ClientContext clientContext) {
329363
return new Builder(clientContext);
@@ -464,6 +498,19 @@ private static Builder createDefault() {
464498
return initDefaults(builder);
465499
}
466500

501+
private static Builder createHttpJsonDefault() {
502+
Builder builder = new Builder(((ClientContext) null));
503+
504+
builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
505+
builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
506+
builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
507+
builder.setEndpoint(getDefaultEndpoint());
508+
builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
509+
builder.setSwitchToMtlsEndpointAllowed(true);
510+
511+
return initDefaults(builder);
512+
}
513+
467514
private static Builder initDefaults(Builder builder) {
468515
builder
469516
.createContactSettings()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2022 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.essentialcontacts.v1.stub;
18+
19+
import com.google.api.core.BetaApi;
20+
import com.google.api.gax.httpjson.HttpJsonCallSettings;
21+
import com.google.api.gax.httpjson.HttpJsonCallableFactory;
22+
import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable;
23+
import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
24+
import com.google.api.gax.httpjson.longrunning.stub.OperationsStub;
25+
import com.google.api.gax.rpc.BatchingCallSettings;
26+
import com.google.api.gax.rpc.ClientContext;
27+
import com.google.api.gax.rpc.OperationCallSettings;
28+
import com.google.api.gax.rpc.OperationCallable;
29+
import com.google.api.gax.rpc.PagedCallSettings;
30+
import com.google.api.gax.rpc.ServerStreamingCallSettings;
31+
import com.google.api.gax.rpc.ServerStreamingCallable;
32+
import com.google.api.gax.rpc.UnaryCallSettings;
33+
import com.google.api.gax.rpc.UnaryCallable;
34+
import com.google.longrunning.Operation;
35+
import javax.annotation.Generated;
36+
37+
// AUTO-GENERATED DOCUMENTATION AND CLASS.
38+
/**
39+
* REST callable factory implementation for the EssentialContactsService service API.
40+
*
41+
* <p>This class is for advanced usage.
42+
*/
43+
@Generated("by gapic-generator-java")
44+
@BetaApi
45+
public class HttpJsonEssentialContactsServiceCallableFactory
46+
implements HttpJsonStubCallableFactory<Operation, OperationsStub> {
47+
48+
@Override
49+
public <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createUnaryCallable(
50+
HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
51+
UnaryCallSettings<RequestT, ResponseT> callSettings,
52+
ClientContext clientContext) {
53+
return HttpJsonCallableFactory.createUnaryCallable(
54+
httpJsonCallSettings, callSettings, clientContext);
55+
}
56+
57+
@Override
58+
public <RequestT, ResponseT, PagedListResponseT>
59+
UnaryCallable<RequestT, PagedListResponseT> createPagedCallable(
60+
HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
61+
PagedCallSettings<RequestT, ResponseT, PagedListResponseT> callSettings,
62+
ClientContext clientContext) {
63+
return HttpJsonCallableFactory.createPagedCallable(
64+
httpJsonCallSettings, callSettings, clientContext);
65+
}
66+
67+
@Override
68+
public <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createBatchingCallable(
69+
HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
70+
BatchingCallSettings<RequestT, ResponseT> callSettings,
71+
ClientContext clientContext) {
72+
return HttpJsonCallableFactory.createBatchingCallable(
73+
httpJsonCallSettings, callSettings, clientContext);
74+
}
75+
76+
@BetaApi(
77+
"The surface for long-running operations is not stable yet and may change in the future.")
78+
@Override
79+
public <RequestT, ResponseT, MetadataT>
80+
OperationCallable<RequestT, ResponseT, MetadataT> createOperationCallable(
81+
HttpJsonCallSettings<RequestT, Operation> httpJsonCallSettings,
82+
OperationCallSettings<RequestT, ResponseT, MetadataT> callSettings,
83+
ClientContext clientContext,
84+
OperationsStub operationsStub) {
85+
UnaryCallable<RequestT, Operation> innerCallable =
86+
HttpJsonCallableFactory.createBaseUnaryCallable(
87+
httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext);
88+
HttpJsonOperationSnapshotCallable<RequestT, Operation> initialCallable =
89+
new HttpJsonOperationSnapshotCallable<RequestT, Operation>(
90+
innerCallable,
91+
httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory());
92+
return HttpJsonCallableFactory.createOperationCallable(
93+
callSettings, clientContext, operationsStub.longRunningClient(), initialCallable);
94+
}
95+
96+
@Override
97+
public <RequestT, ResponseT>
98+
ServerStreamingCallable<RequestT, ResponseT> createServerStreamingCallable(
99+
HttpJsonCallSettings<RequestT, ResponseT> httpJsonCallSettings,
100+
ServerStreamingCallSettings<RequestT, ResponseT> callSettings,
101+
ClientContext clientContext) {
102+
return HttpJsonCallableFactory.createServerStreamingCallable(
103+
httpJsonCallSettings, callSettings, clientContext);
104+
}
105+
}

0 commit comments

Comments
 (0)