Skip to content

Commit cfb6fd8

Browse files
feat: Enable REST transport for most of Java and Go clients (#1469)
* 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 * chore: fix deps Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Neenu1995 <[email protected]>
1 parent ceb7fa6 commit cfb6fd8

File tree

7 files changed

+564
-5
lines changed

7 files changed

+564
-5
lines changed

gapic-google-cloud-storage-v2/pom.xml

+10
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>com.google.guava</groupId>
6771
<artifactId>guava</artifactId>
@@ -77,6 +81,12 @@
7781
<classifier>testlib</classifier>
7882
<scope>test</scope>
7983
</dependency>
84+
<dependency>
85+
<groupId>com.google.api</groupId>
86+
<artifactId>gax-httpjson</artifactId>
87+
<classifier>testlib</classifier>
88+
<scope>test</scope>
89+
</dependency>
8090

8191
</dependencies>
8292

gapic-google-cloud-storage-v2/src/main/java/com/google/storage/v2/StorageClient.java

+14
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@
119119
* StorageClient storageClient = StorageClient.create(storageSettings);
120120
* }</pre>
121121
*
122+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
123+
* the wire:
124+
*
125+
* <pre>{@code
126+
* // This snippet has been automatically generated for illustrative purposes only.
127+
* // It may require modifications to work in your environment.
128+
* StorageSettings storageSettings =
129+
* StorageSettings.newBuilder()
130+
* .setTransportChannelProvider(
131+
* StorageSettings.defaultHttpJsonTransportProviderBuilder().build())
132+
* .build();
133+
* StorageClient storageClient = StorageClient.create(storageSettings);
134+
* }</pre>
135+
*
122136
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
123137
*/
124138
@Generated("by gapic-generator-java")

gapic-google-cloud-storage-v2/src/main/java/com/google/storage/v2/StorageSettings.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.api.gax.core.GoogleCredentialsProvider;
2727
import com.google.api.gax.core.InstantiatingExecutorProvider;
2828
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
29+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
2930
import com.google.api.gax.rpc.ApiClientHeaderProvider;
3031
import com.google.api.gax.rpc.ClientContext;
3132
import com.google.api.gax.rpc.ClientSettings;
@@ -259,11 +260,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
259260
return StorageStubSettings.defaultCredentialsProviderBuilder();
260261
}
261262

262-
/** Returns a builder for the default ChannelProvider for this service. */
263+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
263264
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
264265
return StorageStubSettings.defaultGrpcTransportProviderBuilder();
265266
}
266267

268+
/** Returns a builder for the default REST ChannelProvider for this service. */
269+
@BetaApi
270+
public static InstantiatingHttpJsonChannelProvider.Builder
271+
defaultHttpJsonTransportProviderBuilder() {
272+
return StorageStubSettings.defaultHttpJsonTransportProviderBuilder();
273+
}
274+
267275
public static TransportChannelProvider defaultTransportChannelProvider() {
268276
return StorageStubSettings.defaultTransportChannelProvider();
269277
}
@@ -273,11 +281,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
273281
return StorageStubSettings.defaultApiClientHeaderProviderBuilder();
274282
}
275283

276-
/** Returns a new builder for this class. */
284+
/** Returns a new gRPC builder for this class. */
277285
public static Builder newBuilder() {
278286
return Builder.createDefault();
279287
}
280288

289+
/** Returns a new REST builder for this class. */
290+
@BetaApi
291+
public static Builder newHttpJsonBuilder() {
292+
return Builder.createHttpJsonDefault();
293+
}
294+
281295
/** Returns a new builder for this class. */
282296
public static Builder newBuilder(ClientContext clientContext) {
283297
return new Builder(clientContext);
@@ -315,6 +329,11 @@ private static Builder createDefault() {
315329
return new Builder(StorageStubSettings.newBuilder());
316330
}
317331

332+
@BetaApi
333+
private static Builder createHttpJsonDefault() {
334+
return new Builder(StorageStubSettings.newHttpJsonBuilder());
335+
}
336+
318337
public StorageStubSettings.Builder getStubSettingsBuilder() {
319338
return ((StorageStubSettings.Builder) getStubSettings());
320339
}
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.storage.v2.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 Storage service API.
40+
*
41+
* <p>This class is for advanced usage.
42+
*/
43+
@Generated("by gapic-generator-java")
44+
@BetaApi
45+
public class HttpJsonStorageCallableFactory
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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.storage.v2.stub;
18+
19+
import com.google.api.core.BetaApi;
20+
import com.google.api.core.InternalApi;
21+
import com.google.api.gax.core.BackgroundResource;
22+
import com.google.api.gax.core.BackgroundResourceAggregation;
23+
import com.google.api.gax.httpjson.ApiMethodDescriptor;
24+
import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
25+
import com.google.api.gax.rpc.ClientContext;
26+
import com.google.protobuf.TypeRegistry;
27+
import java.io.IOException;
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
import java.util.concurrent.TimeUnit;
31+
import javax.annotation.Generated;
32+
33+
// AUTO-GENERATED DOCUMENTATION AND CLASS.
34+
/**
35+
* REST stub implementation for the Storage service API.
36+
*
37+
* <p>This class is for advanced usage and reflects the underlying API directly.
38+
*/
39+
@Generated("by gapic-generator-java")
40+
@BetaApi
41+
public class HttpJsonStorageStub extends StorageStub {
42+
private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
43+
44+
private final BackgroundResource backgroundResources;
45+
private final HttpJsonStubCallableFactory callableFactory;
46+
47+
public static final HttpJsonStorageStub create(StorageStubSettings settings) throws IOException {
48+
return new HttpJsonStorageStub(settings, ClientContext.create(settings));
49+
}
50+
51+
public static final HttpJsonStorageStub create(ClientContext clientContext) throws IOException {
52+
return new HttpJsonStorageStub(StorageStubSettings.newHttpJsonBuilder().build(), clientContext);
53+
}
54+
55+
public static final HttpJsonStorageStub create(
56+
ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
57+
return new HttpJsonStorageStub(
58+
StorageStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory);
59+
}
60+
61+
/**
62+
* Constructs an instance of HttpJsonStorageStub, using the given settings. This is protected so
63+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
64+
* preferred.
65+
*/
66+
protected HttpJsonStorageStub(StorageStubSettings settings, ClientContext clientContext)
67+
throws IOException {
68+
this(settings, clientContext, new HttpJsonStorageCallableFactory());
69+
}
70+
71+
/**
72+
* Constructs an instance of HttpJsonStorageStub, using the given settings. This is protected so
73+
* that it is easy to make a subclass, but otherwise, the static factory methods should be
74+
* preferred.
75+
*/
76+
protected HttpJsonStorageStub(
77+
StorageStubSettings settings,
78+
ClientContext clientContext,
79+
HttpJsonStubCallableFactory callableFactory)
80+
throws IOException {
81+
this.callableFactory = callableFactory;
82+
83+
this.backgroundResources =
84+
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
85+
}
86+
87+
@InternalApi
88+
public static List<ApiMethodDescriptor> getMethodDescriptors() {
89+
List<ApiMethodDescriptor> methodDescriptors = new ArrayList<>();
90+
return methodDescriptors;
91+
}
92+
93+
@Override
94+
public final void close() {
95+
try {
96+
backgroundResources.close();
97+
} catch (RuntimeException e) {
98+
throw e;
99+
} catch (Exception e) {
100+
throw new IllegalStateException("Failed to close resource", e);
101+
}
102+
}
103+
104+
@Override
105+
public void shutdown() {
106+
backgroundResources.shutdown();
107+
}
108+
109+
@Override
110+
public boolean isShutdown() {
111+
return backgroundResources.isShutdown();
112+
}
113+
114+
@Override
115+
public boolean isTerminated() {
116+
return backgroundResources.isTerminated();
117+
}
118+
119+
@Override
120+
public void shutdownNow() {
121+
backgroundResources.shutdownNow();
122+
}
123+
124+
@Override
125+
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
126+
return backgroundResources.awaitTermination(duration, unit);
127+
}
128+
}

0 commit comments

Comments
 (0)