Skip to content

Commit 60faebf

Browse files
feat: Enable REST transport for most of Java and Go clients (#812)
* 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 * 🦉 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 3cd4d69 commit 60faebf

13 files changed

+1425
-10
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
<groupId>com.google.api</groupId>
6464
<artifactId>gax-grpc</artifactId>
6565
</dependency>
66+
<dependency>
67+
<groupId>com.google.api</groupId>
68+
<artifactId>gax-httpjson</artifactId>
69+
</dependency>
6670
<dependency>
6771
<groupId>org.threeten</groupId>
6872
<artifactId>threetenbp</artifactId>
@@ -90,12 +94,24 @@
9094
<scope>test</scope>
9195
</dependency>
9296
<!-- Need testing utility classes for generated gRPC clients tests -->
97+
<dependency>
98+
<groupId>com.google.api</groupId>
99+
<artifactId>gax</artifactId>
100+
<classifier>testlib</classifier>
101+
<scope>test</scope>
102+
</dependency>
93103
<dependency>
94104
<groupId>com.google.api</groupId>
95105
<artifactId>gax-grpc</artifactId>
96106
<classifier>testlib</classifier>
97107
<scope>test</scope>
98108
</dependency>
109+
<dependency>
110+
<groupId>com.google.api</groupId>
111+
<artifactId>gax-httpjson</artifactId>
112+
<classifier>testlib</classifier>
113+
<scope>test</scope>
114+
</dependency>
99115
</dependencies>
100116

101117
<profiles>

java-trace/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/TraceServiceClient.java

+14
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@
107107
* TraceServiceClient traceServiceClient = TraceServiceClient.create(traceServiceSettings);
108108
* }</pre>
109109
*
110+
* <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
111+
* the wire:
112+
*
113+
* <pre>{@code
114+
* // This snippet has been automatically generated for illustrative purposes only.
115+
* // It may require modifications to work in your environment.
116+
* TraceServiceSettings traceServiceSettings =
117+
* TraceServiceSettings.newBuilder()
118+
* .setTransportChannelProvider(
119+
* TraceServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
120+
* .build();
121+
* TraceServiceClient traceServiceClient = TraceServiceClient.create(traceServiceSettings);
122+
* }</pre>
123+
*
110124
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
111125
*/
112126
@Generated("by gapic-generator-java")

java-trace/google-cloud-trace/src/main/java/com/google/cloud/trace/v1/TraceServiceSettings.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.api.gax.core.GoogleCredentialsProvider;
2424
import com.google.api.gax.core.InstantiatingExecutorProvider;
2525
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
26+
import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
2627
import com.google.api.gax.rpc.ApiClientHeaderProvider;
2728
import com.google.api.gax.rpc.ClientContext;
2829
import com.google.api.gax.rpc.ClientSettings;
@@ -117,11 +118,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
117118
return TraceServiceStubSettings.defaultCredentialsProviderBuilder();
118119
}
119120

120-
/** Returns a builder for the default ChannelProvider for this service. */
121+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
121122
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
122123
return TraceServiceStubSettings.defaultGrpcTransportProviderBuilder();
123124
}
124125

126+
/** Returns a builder for the default REST ChannelProvider for this service. */
127+
@BetaApi
128+
public static InstantiatingHttpJsonChannelProvider.Builder
129+
defaultHttpJsonTransportProviderBuilder() {
130+
return TraceServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
131+
}
132+
125133
public static TransportChannelProvider defaultTransportChannelProvider() {
126134
return TraceServiceStubSettings.defaultTransportChannelProvider();
127135
}
@@ -131,11 +139,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
131139
return TraceServiceStubSettings.defaultApiClientHeaderProviderBuilder();
132140
}
133141

134-
/** Returns a new builder for this class. */
142+
/** Returns a new gRPC builder for this class. */
135143
public static Builder newBuilder() {
136144
return Builder.createDefault();
137145
}
138146

147+
/** Returns a new REST builder for this class. */
148+
@BetaApi
149+
public static Builder newHttpJsonBuilder() {
150+
return Builder.createHttpJsonDefault();
151+
}
152+
139153
/** Returns a new builder for this class. */
140154
public static Builder newBuilder(ClientContext clientContext) {
141155
return new Builder(clientContext);
@@ -173,6 +187,11 @@ private static Builder createDefault() {
173187
return new Builder(TraceServiceStubSettings.newBuilder());
174188
}
175189

190+
@BetaApi
191+
private static Builder createHttpJsonDefault() {
192+
return new Builder(TraceServiceStubSettings.newHttpJsonBuilder());
193+
}
194+
176195
public TraceServiceStubSettings.Builder getStubSettingsBuilder() {
177196
return ((TraceServiceStubSettings.Builder) getStubSettings());
178197
}
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.trace.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 TraceService service API.
40+
*
41+
* <p>This class is for advanced usage.
42+
*/
43+
@Generated("by gapic-generator-java")
44+
@BetaApi
45+
public class HttpJsonTraceServiceCallableFactory
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)