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

Commit fa586fb

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

File tree

8 files changed

+1958
-11
lines changed

8 files changed

+1958
-11
lines changed

google-cloud-storage-transfer/pom.xml

Lines changed: 16 additions & 0 deletions
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-storage-transfer/src/main/java/com/google/storagetransfer/v1/proto/StorageTransferServiceClient.java

Lines changed: 33 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;
@@ -28,7 +29,6 @@
2829
import com.google.api.gax.rpc.UnaryCallable;
2930
import com.google.common.util.concurrent.MoreExecutors;
3031
import com.google.longrunning.Operation;
31-
import com.google.longrunning.OperationsClient;
3232
import com.google.protobuf.Empty;
3333
import com.google.protobuf.FieldMask;
3434
import com.google.storagetransfer.v1.proto.stub.StorageTransferServiceStub;
@@ -111,13 +111,29 @@
111111
* StorageTransferServiceClient.create(storageTransferServiceSettings);
112112
* }</pre>
113113
*
114+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
115+
* the wire:
116+
*
117+
* <pre>{@code
118+
* // This snippet has been automatically generated for illustrative purposes only.
119+
* // It may require modifications to work in your environment.
120+
* StorageTransferServiceSettings storageTransferServiceSettings =
121+
* StorageTransferServiceSettings.newBuilder()
122+
* .setTransportChannelProvider(
123+
* StorageTransferServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
124+
* .build();
125+
* StorageTransferServiceClient storageTransferServiceClient =
126+
* StorageTransferServiceClient.create(storageTransferServiceSettings);
127+
* }</pre>
128+
*
114129
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
115130
*/
116131
@Generated("by gapic-generator-java")
117132
public class StorageTransferServiceClient implements BackgroundResource {
118133
private final StorageTransferServiceSettings settings;
119134
private final StorageTransferServiceStub stub;
120-
private final OperationsClient operationsClient;
135+
private final OperationsClient httpJsonOperationsClient;
136+
private final com.google.longrunning.OperationsClient operationsClient;
121137

122138
/** Constructs an instance of StorageTransferServiceClient with default settings. */
123139
public static final StorageTransferServiceClient create() throws IOException {
@@ -150,13 +166,17 @@ protected StorageTransferServiceClient(StorageTransferServiceSettings settings)
150166
throws IOException {
151167
this.settings = settings;
152168
this.stub = ((StorageTransferServiceStubSettings) settings.getStubSettings()).createStub();
153-
this.operationsClient = OperationsClient.create(this.stub.getOperationsStub());
169+
this.operationsClient =
170+
com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
171+
this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
154172
}
155173

156174
protected StorageTransferServiceClient(StorageTransferServiceStub stub) {
157175
this.settings = null;
158176
this.stub = stub;
159-
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());
160180
}
161181

162182
public final StorageTransferServiceSettings getSettings() {
@@ -171,10 +191,18 @@ public StorageTransferServiceStub getStub() {
171191
* Returns the OperationsClient that can be used to query the status of a long-running operation
172192
* returned by another API method call.
173193
*/
174-
public final OperationsClient getOperationsClient() {
194+
public final com.google.longrunning.OperationsClient getOperationsClient() {
175195
return operationsClient;
176196
}
177197

198+
/**
199+
* Returns the OperationsClient that can be used to query the status of a long-running operation
200+
* returned by another API method call.
201+
*/
202+
public final OperationsClient getHttpJsonOperationsClient() {
203+
return httpJsonOperationsClient;
204+
}
205+
178206
// AUTO-GENERATED DOCUMENTATION AND METHOD.
179207
/**
180208
* Returns the Google service account that is used by Storage Transfer Service to access buckets

google-cloud-storage-transfer/src/main/java/com/google/storagetransfer/v1/proto/StorageTransferServiceSettings.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;
@@ -197,11 +198,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
197198
return StorageTransferServiceStubSettings.defaultCredentialsProviderBuilder();
198199
}
199200

200-
/** Returns a builder for the default ChannelProvider for this service. */
201+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
201202
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
202203
return StorageTransferServiceStubSettings.defaultGrpcTransportProviderBuilder();
203204
}
204205

206+
/** Returns a builder for the default REST ChannelProvider for this service. */
207+
@BetaApi
208+
public static InstantiatingHttpJsonChannelProvider.Builder
209+
defaultHttpJsonTransportProviderBuilder() {
210+
return StorageTransferServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
211+
}
212+
205213
public static TransportChannelProvider defaultTransportChannelProvider() {
206214
return StorageTransferServiceStubSettings.defaultTransportChannelProvider();
207215
}
@@ -211,11 +219,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
211219
return StorageTransferServiceStubSettings.defaultApiClientHeaderProviderBuilder();
212220
}
213221

214-
/** Returns a new builder for this class. */
222+
/** Returns a new gRPC builder for this class. */
215223
public static Builder newBuilder() {
216224
return Builder.createDefault();
217225
}
218226

227+
/** Returns a new REST builder for this class. */
228+
@BetaApi
229+
public static Builder newHttpJsonBuilder() {
230+
return Builder.createHttpJsonDefault();
231+
}
232+
219233
/** Returns a new builder for this class. */
220234
public static Builder newBuilder(ClientContext clientContext) {
221235
return new Builder(clientContext);
@@ -254,6 +268,11 @@ private static Builder createDefault() {
254268
return new Builder(StorageTransferServiceStubSettings.newBuilder());
255269
}
256270

271+
@BetaApi
272+
private static Builder createHttpJsonDefault() {
273+
return new Builder(StorageTransferServiceStubSettings.newHttpJsonBuilder());
274+
}
275+
257276
public StorageTransferServiceStubSettings.Builder getStubSettingsBuilder() {
258277
return ((StorageTransferServiceStubSettings.Builder) getStubSettings());
259278
}
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.storagetransfer.v1.proto.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 StorageTransferService service API.
40+
*
41+
* <p>This class is for advanced usage.
42+
*/
43+
@Generated("by gapic-generator-java")
44+
@BetaApi
45+
public class HttpJsonStorageTransferServiceCallableFactory
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)