Skip to content

Commit f92b260

Browse files
feat: Enable REST transport for most of Java and Go clients (#773)
- [ ] 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 47aa256 commit f92b260

File tree

108 files changed

+8985
-12
lines changed

Some content is hidden

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

108 files changed

+8985
-12
lines changed

java-recommender/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ implementation 'com.google.cloud:google-cloud-recommender'
5656
If you are using Gradle without BOM, add this to your dependencies
5757

5858
```Groovy
59-
implementation 'com.google.cloud:google-cloud-recommender:2.4.0'
59+
implementation 'com.google.cloud:google-cloud-recommender:2.4.1'
6060
```
6161

6262
If you are using SBT, add this to your dependencies
6363

6464
```Scala
65-
libraryDependencies += "com.google.cloud" % "google-cloud-recommender" % "2.4.0"
65+
libraryDependencies += "com.google.cloud" % "google-cloud-recommender" % "2.4.1"
6666
```
6767

6868
## Authentication

java-recommender/google-cloud-recommender/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@
6969
<groupId>com.google.api</groupId>
7070
<artifactId>gax-grpc</artifactId>
7171
</dependency>
72+
<dependency>
73+
<groupId>com.google.api</groupId>
74+
<artifactId>gax-httpjson</artifactId>
75+
</dependency>
7276
<dependency>
7377
<groupId>org.threeten</groupId>
7478
<artifactId>threetenbp</artifactId>
@@ -96,12 +100,24 @@
96100
<scope>test</scope>
97101
</dependency>
98102
<!-- Need testing utility classes for generated gRPC clients tests -->
103+
<dependency>
104+
<groupId>com.google.api</groupId>
105+
<artifactId>gax</artifactId>
106+
<classifier>testlib</classifier>
107+
<scope>test</scope>
108+
</dependency>
99109
<dependency>
100110
<groupId>com.google.api</groupId>
101111
<artifactId>gax-grpc</artifactId>
102112
<classifier>testlib</classifier>
103113
<scope>test</scope>
104114
</dependency>
115+
<dependency>
116+
<groupId>com.google.api</groupId>
117+
<artifactId>gax-httpjson</artifactId>
118+
<classifier>testlib</classifier>
119+
<scope>test</scope>
120+
</dependency>
105121
<dependency>
106122
<groupId>com.google.truth</groupId>
107123
<artifactId>truth</artifactId>

java-recommender/google-cloud-recommender/src/main/java/com/google/cloud/recommender/v1/RecommenderClient.java

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

java-recommender/google-cloud-recommender/src/main/java/com/google/cloud/recommender/v1/RecommenderSettings.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;
@@ -141,11 +142,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
141142
return RecommenderStubSettings.defaultCredentialsProviderBuilder();
142143
}
143144

144-
/** Returns a builder for the default ChannelProvider for this service. */
145+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
145146
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
146147
return RecommenderStubSettings.defaultGrpcTransportProviderBuilder();
147148
}
148149

150+
/** Returns a builder for the default REST ChannelProvider for this service. */
151+
@BetaApi
152+
public static InstantiatingHttpJsonChannelProvider.Builder
153+
defaultHttpJsonTransportProviderBuilder() {
154+
return RecommenderStubSettings.defaultHttpJsonTransportProviderBuilder();
155+
}
156+
149157
public static TransportChannelProvider defaultTransportChannelProvider() {
150158
return RecommenderStubSettings.defaultTransportChannelProvider();
151159
}
@@ -155,11 +163,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
155163
return RecommenderStubSettings.defaultApiClientHeaderProviderBuilder();
156164
}
157165

158-
/** Returns a new builder for this class. */
166+
/** Returns a new gRPC builder for this class. */
159167
public static Builder newBuilder() {
160168
return Builder.createDefault();
161169
}
162170

171+
/** Returns a new REST builder for this class. */
172+
@BetaApi
173+
public static Builder newHttpJsonBuilder() {
174+
return Builder.createHttpJsonDefault();
175+
}
176+
163177
/** Returns a new builder for this class. */
164178
public static Builder newBuilder(ClientContext clientContext) {
165179
return new Builder(clientContext);
@@ -197,6 +211,11 @@ private static Builder createDefault() {
197211
return new Builder(RecommenderStubSettings.newBuilder());
198212
}
199213

214+
@BetaApi
215+
private static Builder createHttpJsonDefault() {
216+
return new Builder(RecommenderStubSettings.newHttpJsonBuilder());
217+
}
218+
200219
public RecommenderStubSettings.Builder getStubSettingsBuilder() {
201220
return ((RecommenderStubSettings.Builder) getStubSettings());
202221
}
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.recommender.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 Recommender service API.
40+
*
41+
* <p>This class is for advanced usage.
42+
*/
43+
@Generated("by gapic-generator-java")
44+
@BetaApi
45+
public class HttpJsonRecommenderCallableFactory
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)