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

Commit 808c131

Browse files
feat: Enable REST transport for most of Java and Go clients (#920)
* feat: Enable REST transport for most of Java and Go clients PiperOrigin-RevId: 456641589 Source-Link: googleapis/googleapis@8a251f5 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9 * 🦉 Updates from OwlBot post-processor See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md * deps: adding gax-httpjson Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Tomo Suzuki <[email protected]>
1 parent 6edfbd3 commit 808c131

File tree

93 files changed

+5729
-60
lines changed

Some content is hidden

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

93 files changed

+5729
-60
lines changed

google-cloud-video-intelligence/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
<groupId>com.google.api</groupId>
7575
<artifactId>gax-grpc</artifactId>
7676
</dependency>
77+
<dependency>
78+
<groupId>com.google.api</groupId>
79+
<artifactId>gax-httpjson</artifactId>
80+
</dependency>
7781
<dependency>
7882
<groupId>org.threeten</groupId>
7983
<artifactId>threetenbp</artifactId>
@@ -112,12 +116,24 @@
112116
<scope>test</scope>
113117
</dependency>
114118
<!-- Need testing utility classes for generated gRPC clients tests -->
119+
<dependency>
120+
<groupId>com.google.api</groupId>
121+
<artifactId>gax</artifactId>
122+
<classifier>testlib</classifier>
123+
<scope>test</scope>
124+
</dependency>
115125
<dependency>
116126
<groupId>com.google.api</groupId>
117127
<artifactId>gax-grpc</artifactId>
118128
<classifier>testlib</classifier>
119129
<scope>test</scope>
120130
</dependency>
131+
<dependency>
132+
<groupId>com.google.api</groupId>
133+
<artifactId>gax-httpjson</artifactId>
134+
<classifier>testlib</classifier>
135+
<scope>test</scope>
136+
</dependency>
121137
</dependencies>
122138

123139
<profiles>

google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceClient.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
package com.google.cloud.videointelligence.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.videointelligence.v1.stub.VideoIntelligenceServiceStub;
2425
import com.google.cloud.videointelligence.v1.stub.VideoIntelligenceServiceStubSettings;
2526
import com.google.longrunning.Operation;
26-
import com.google.longrunning.OperationsClient;
2727
import java.io.IOException;
2828
import java.util.List;
2929
import java.util.concurrent.TimeUnit;
@@ -99,13 +99,29 @@
9999
* VideoIntelligenceServiceClient.create(videoIntelligenceServiceSettings);
100100
* }</pre>
101101
*
102+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
103+
* the wire:
104+
*
105+
* <pre>{@code
106+
* // This snippet has been automatically generated for illustrative purposes only.
107+
* // It may require modifications to work in your environment.
108+
* VideoIntelligenceServiceSettings videoIntelligenceServiceSettings =
109+
* VideoIntelligenceServiceSettings.newBuilder()
110+
* .setTransportChannelProvider(
111+
* VideoIntelligenceServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
112+
* .build();
113+
* VideoIntelligenceServiceClient videoIntelligenceServiceClient =
114+
* VideoIntelligenceServiceClient.create(videoIntelligenceServiceSettings);
115+
* }</pre>
116+
*
102117
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
103118
*/
104119
@Generated("by gapic-generator-java")
105120
public class VideoIntelligenceServiceClient implements BackgroundResource {
106121
private final VideoIntelligenceServiceSettings settings;
107122
private final VideoIntelligenceServiceStub stub;
108-
private final OperationsClient operationsClient;
123+
private final OperationsClient httpJsonOperationsClient;
124+
private final com.google.longrunning.OperationsClient operationsClient;
109125

110126
/** Constructs an instance of VideoIntelligenceServiceClient with default settings. */
111127
public static final VideoIntelligenceServiceClient create() throws IOException {
@@ -139,13 +155,17 @@ protected VideoIntelligenceServiceClient(VideoIntelligenceServiceSettings settin
139155
throws IOException {
140156
this.settings = settings;
141157
this.stub = ((VideoIntelligenceServiceStubSettings) 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 VideoIntelligenceServiceClient(VideoIntelligenceServiceStub 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 VideoIntelligenceServiceSettings getSettings() {
@@ -160,10 +180,18 @@ public VideoIntelligenceServiceStub 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
* Performs asynchronous video annotation. Progress and results can be retrieved through the

google-cloud-video-intelligence/src/main/java/com/google/cloud/videointelligence/v1/VideoIntelligenceServiceSettings.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;
@@ -110,11 +111,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
110111
return VideoIntelligenceServiceStubSettings.defaultCredentialsProviderBuilder();
111112
}
112113

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

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

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

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

184+
@BetaApi
185+
private static Builder createHttpJsonDefault() {
186+
return new Builder(VideoIntelligenceServiceStubSettings.newHttpJsonBuilder());
187+
}
188+
170189
public VideoIntelligenceServiceStubSettings.Builder getStubSettingsBuilder() {
171190
return ((VideoIntelligenceServiceStubSettings.Builder) getStubSettings());
172191
}
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.videointelligence.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 VideoIntelligenceService service API.
40+
*
41+
* <p>This class is for advanced usage.
42+
*/
43+
@Generated("by gapic-generator-java")
44+
@BetaApi
45+
public class HttpJsonVideoIntelligenceServiceCallableFactory
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)