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

Commit b72b7a5

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

File tree

14 files changed

+680
-7
lines changed

14 files changed

+680
-7
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ If you are using Maven, add this to your pom.xml file:
3030
If you are using Gradle without BOM, add this to your dependencies
3131

3232
```Groovy
33-
implementation 'com.google.cloud:google-cloud-mediatranslation:0.8.0'
33+
implementation 'com.google.cloud:google-cloud-mediatranslation:0.8.1'
3434
```
3535

3636
If you are using SBT, add this to your dependencies
3737

3838
```Scala
39-
libraryDependencies += "com.google.cloud" % "google-cloud-mediatranslation" % "0.8.0"
39+
libraryDependencies += "com.google.cloud" % "google-cloud-mediatranslation" % "0.8.1"
4040
```
4141

4242
## Authentication

google-cloud-mediatranslation/pom.xml

+10
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>
@@ -82,6 +86,12 @@
8286
<classifier>testlib</classifier>
8387
<scope>test</scope>
8488
</dependency>
89+
<dependency>
90+
<groupId>com.google.api</groupId>
91+
<artifactId>gax-httpjson</artifactId>
92+
<classifier>testlib</classifier>
93+
<scope>test</scope>
94+
</dependency>
8595
</dependencies>
8696

8797
<profiles>

google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClient.java

+15
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@
9999
* SpeechTranslationServiceClient.create(speechTranslationServiceSettings);
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+
* SpeechTranslationServiceSettings speechTranslationServiceSettings =
109+
* SpeechTranslationServiceSettings.newBuilder()
110+
* .setTransportChannelProvider(
111+
* SpeechTranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
112+
* .build();
113+
* SpeechTranslationServiceClient speechTranslationServiceClient =
114+
* SpeechTranslationServiceClient.create(speechTranslationServiceSettings);
115+
* }</pre>
116+
*
102117
* <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
103118
*/
104119
@BetaApi

google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceSettings.java

+21-2
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;
@@ -105,11 +106,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
105106
return SpeechTranslationServiceStubSettings.defaultCredentialsProviderBuilder();
106107
}
107108

108-
/** Returns a builder for the default ChannelProvider for this service. */
109+
/** Returns a builder for the default gRPC ChannelProvider for this service. */
109110
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
110111
return SpeechTranslationServiceStubSettings.defaultGrpcTransportProviderBuilder();
111112
}
112113

114+
/** Returns a builder for the default REST ChannelProvider for this service. */
115+
@BetaApi
116+
public static InstantiatingHttpJsonChannelProvider.Builder
117+
defaultHttpJsonTransportProviderBuilder() {
118+
return SpeechTranslationServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
119+
}
120+
113121
public static TransportChannelProvider defaultTransportChannelProvider() {
114122
return SpeechTranslationServiceStubSettings.defaultTransportChannelProvider();
115123
}
@@ -119,11 +127,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
119127
return SpeechTranslationServiceStubSettings.defaultApiClientHeaderProviderBuilder();
120128
}
121129

122-
/** Returns a new builder for this class. */
130+
/** Returns a new gRPC builder for this class. */
123131
public static Builder newBuilder() {
124132
return Builder.createDefault();
125133
}
126134

135+
/** Returns a new REST builder for this class. */
136+
@BetaApi
137+
public static Builder newHttpJsonBuilder() {
138+
return Builder.createHttpJsonDefault();
139+
}
140+
127141
/** Returns a new builder for this class. */
128142
public static Builder newBuilder(ClientContext clientContext) {
129143
return new Builder(clientContext);
@@ -162,6 +176,11 @@ private static Builder createDefault() {
162176
return new Builder(SpeechTranslationServiceStubSettings.newBuilder());
163177
}
164178

179+
@BetaApi
180+
private static Builder createHttpJsonDefault() {
181+
return new Builder(SpeechTranslationServiceStubSettings.newHttpJsonBuilder());
182+
}
183+
165184
public SpeechTranslationServiceStubSettings.Builder getStubSettingsBuilder() {
166185
return ((SpeechTranslationServiceStubSettings.Builder) getStubSettings());
167186
}
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.mediatranslation.v1beta1.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 SpeechTranslationService service API.
40+
*
41+
* <p>This class is for advanced usage.
42+
*/
43+
@BetaApi
44+
@Generated("by gapic-generator-java")
45+
public class HttpJsonSpeechTranslationServiceCallableFactory
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,134 @@
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.mediatranslation.v1beta1.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 SpeechTranslationService service API.
36+
*
37+
* <p>This class is for advanced usage and reflects the underlying API directly.
38+
*/
39+
@BetaApi
40+
@Generated("by gapic-generator-java")
41+
public class HttpJsonSpeechTranslationServiceStub extends SpeechTranslationServiceStub {
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 HttpJsonSpeechTranslationServiceStub create(
48+
SpeechTranslationServiceStubSettings settings) throws IOException {
49+
return new HttpJsonSpeechTranslationServiceStub(settings, ClientContext.create(settings));
50+
}
51+
52+
public static final HttpJsonSpeechTranslationServiceStub create(ClientContext clientContext)
53+
throws IOException {
54+
return new HttpJsonSpeechTranslationServiceStub(
55+
SpeechTranslationServiceStubSettings.newHttpJsonBuilder().build(), clientContext);
56+
}
57+
58+
public static final HttpJsonSpeechTranslationServiceStub create(
59+
ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
60+
return new HttpJsonSpeechTranslationServiceStub(
61+
SpeechTranslationServiceStubSettings.newHttpJsonBuilder().build(),
62+
clientContext,
63+
callableFactory);
64+
}
65+
66+
/**
67+
* Constructs an instance of HttpJsonSpeechTranslationServiceStub, using the given settings. This
68+
* is protected so that it is easy to make a subclass, but otherwise, the static factory methods
69+
* should be preferred.
70+
*/
71+
protected HttpJsonSpeechTranslationServiceStub(
72+
SpeechTranslationServiceStubSettings settings, ClientContext clientContext)
73+
throws IOException {
74+
this(settings, clientContext, new HttpJsonSpeechTranslationServiceCallableFactory());
75+
}
76+
77+
/**
78+
* Constructs an instance of HttpJsonSpeechTranslationServiceStub, using the given settings. This
79+
* is protected so that it is easy to make a subclass, but otherwise, the static factory methods
80+
* should be preferred.
81+
*/
82+
protected HttpJsonSpeechTranslationServiceStub(
83+
SpeechTranslationServiceStubSettings settings,
84+
ClientContext clientContext,
85+
HttpJsonStubCallableFactory callableFactory)
86+
throws IOException {
87+
this.callableFactory = callableFactory;
88+
89+
this.backgroundResources =
90+
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
91+
}
92+
93+
@InternalApi
94+
public static List<ApiMethodDescriptor> getMethodDescriptors() {
95+
List<ApiMethodDescriptor> methodDescriptors = new ArrayList<>();
96+
return methodDescriptors;
97+
}
98+
99+
@Override
100+
public final void close() {
101+
try {
102+
backgroundResources.close();
103+
} catch (RuntimeException e) {
104+
throw e;
105+
} catch (Exception e) {
106+
throw new IllegalStateException("Failed to close resource", e);
107+
}
108+
}
109+
110+
@Override
111+
public void shutdown() {
112+
backgroundResources.shutdown();
113+
}
114+
115+
@Override
116+
public boolean isShutdown() {
117+
return backgroundResources.isShutdown();
118+
}
119+
120+
@Override
121+
public boolean isTerminated() {
122+
return backgroundResources.isTerminated();
123+
}
124+
125+
@Override
126+
public void shutdownNow() {
127+
backgroundResources.shutdownNow();
128+
}
129+
130+
@Override
131+
public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
132+
return backgroundResources.awaitTermination(duration, unit);
133+
}
134+
}

0 commit comments

Comments
 (0)