From 89943a92dc74f8e638adcd65372ac995432fb80d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Thu, 23 Jun 2022 21:28:16 +0000 Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients (#658) - [ ] Regenerate this pull request now. PiperOrigin-RevId: 456641589 Source-Link: https://github.com/googleapis/googleapis/commit/8a251f5225b789b2383207ffd978f6aa3d77fcf7 Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9 --- java-mediatranslation/README.md | 4 +- .../google-cloud-mediatranslation/pom.xml | 10 ++ .../SpeechTranslationServiceClient.java | 15 ++ .../SpeechTranslationServiceSettings.java | 23 ++- ...eechTranslationServiceCallableFactory.java | 105 ++++++++++++++ .../HttpJsonSpeechTranslationServiceStub.java | 134 ++++++++++++++++++ .../SpeechTranslationServiceStubSettings.java | 53 ++++++- ...hTranslationServiceClientHttpJsonTest.java | 70 +++++++++ .../SyncCreateSetCredentialsProvider.java | 44 ++++++ .../SyncCreateSetCredentialsProvider1.java | 43 ++++++ .../create/SyncCreateSetEndpoint.java | 39 +++++ .../AsyncStreamingTranslateSpeech.java | 49 +++++++ .../SyncStreamingTranslateSpeech.java | 49 +++++++ .../SyncStreamingTranslateSpeech.java | 49 +++++++ 14 files changed, 680 insertions(+), 7 deletions(-) create mode 100644 java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceCallableFactory.java create mode 100644 java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceStub.java create mode 100644 java-mediatranslation/google-cloud-mediatranslation/src/test/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClientHttpJsonTest.java create mode 100644 java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider.java create mode 100644 java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider1.java create mode 100644 java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetEndpoint.java create mode 100644 java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/streamingtranslatespeech/AsyncStreamingTranslateSpeech.java create mode 100644 java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationservicesettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java create mode 100644 java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/stub/speechtranslationservicestubsettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java diff --git a/java-mediatranslation/README.md b/java-mediatranslation/README.md index 566fa3183c48..32614ebe77c8 100644 --- a/java-mediatranslation/README.md +++ b/java-mediatranslation/README.md @@ -30,13 +30,13 @@ If you are using Maven, add this to your pom.xml file: If you are using Gradle without BOM, add this to your dependencies ```Groovy -implementation 'com.google.cloud:google-cloud-mediatranslation:0.8.0' +implementation 'com.google.cloud:google-cloud-mediatranslation:0.8.1' ``` If you are using SBT, add this to your dependencies ```Scala -libraryDependencies += "com.google.cloud" % "google-cloud-mediatranslation" % "0.8.0" +libraryDependencies += "com.google.cloud" % "google-cloud-mediatranslation" % "0.8.1" ``` ## Authentication diff --git a/java-mediatranslation/google-cloud-mediatranslation/pom.xml b/java-mediatranslation/google-cloud-mediatranslation/pom.xml index 0cf4509a3d7c..8446903ea993 100644 --- a/java-mediatranslation/google-cloud-mediatranslation/pom.xml +++ b/java-mediatranslation/google-cloud-mediatranslation/pom.xml @@ -58,6 +58,10 @@ com.google.api gax-grpc + + com.google.api + gax-httpjson + org.threeten threetenbp @@ -82,6 +86,12 @@ testlib test + + com.google.api + gax-httpjson + testlib + test + diff --git a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClient.java b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClient.java index bb040228ffc7..10b6dd3dc3f3 100644 --- a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClient.java +++ b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClient.java @@ -99,6 +99,21 @@ * SpeechTranslationServiceClient.create(speechTranslationServiceSettings); * } * + *

To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over + * the wire: + * + *

{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * SpeechTranslationServiceSettings speechTranslationServiceSettings =
+ *     SpeechTranslationServiceSettings.newBuilder()
+ *         .setTransportChannelProvider(
+ *             SpeechTranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ *         .build();
+ * SpeechTranslationServiceClient speechTranslationServiceClient =
+ *     SpeechTranslationServiceClient.create(speechTranslationServiceSettings);
+ * }
+ * *

Please refer to the GitHub repository's samples for more quickstart code snippets. */ @BetaApi diff --git a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceSettings.java b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceSettings.java index 43c9f0a67fbc..4e5fc6fff408 100644 --- a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceSettings.java +++ b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceSettings.java @@ -21,6 +21,7 @@ import com.google.api.gax.core.GoogleCredentialsProvider; import com.google.api.gax.core.InstantiatingExecutorProvider; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; import com.google.api.gax.rpc.ClientSettings; @@ -105,11 +106,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde return SpeechTranslationServiceStubSettings.defaultCredentialsProviderBuilder(); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return SpeechTranslationServiceStubSettings.defaultGrpcTransportProviderBuilder(); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return SpeechTranslationServiceStubSettings.defaultHttpJsonTransportProviderBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return SpeechTranslationServiceStubSettings.defaultTransportChannelProvider(); } @@ -119,11 +127,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil return SpeechTranslationServiceStubSettings.defaultApiClientHeaderProviderBuilder(); } - /** Returns a new builder for this class. */ + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + @BetaApi + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -162,6 +176,11 @@ private static Builder createDefault() { return new Builder(SpeechTranslationServiceStubSettings.newBuilder()); } + @BetaApi + private static Builder createHttpJsonDefault() { + return new Builder(SpeechTranslationServiceStubSettings.newHttpJsonBuilder()); + } + public SpeechTranslationServiceStubSettings.Builder getStubSettingsBuilder() { return ((SpeechTranslationServiceStubSettings.Builder) getStubSettings()); } diff --git a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceCallableFactory.java b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceCallableFactory.java new file mode 100644 index 000000000000..4f21361d795f --- /dev/null +++ b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceCallableFactory.java @@ -0,0 +1,105 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.gax.httpjson.HttpJsonCallSettings; +import com.google.api.gax.httpjson.HttpJsonCallableFactory; +import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.httpjson.longrunning.stub.OperationsStub; +import com.google.api.gax.rpc.BatchingCallSettings; +import com.google.api.gax.rpc.ClientContext; +import com.google.api.gax.rpc.OperationCallSettings; +import com.google.api.gax.rpc.OperationCallable; +import com.google.api.gax.rpc.PagedCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallSettings; +import com.google.api.gax.rpc.ServerStreamingCallable; +import com.google.api.gax.rpc.UnaryCallSettings; +import com.google.api.gax.rpc.UnaryCallable; +import com.google.longrunning.Operation; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST callable factory implementation for the SpeechTranslationService service API. + * + *

This class is for advanced usage. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonSpeechTranslationServiceCallableFactory + implements HttpJsonStubCallableFactory { + + @Override + public UnaryCallable createUnaryCallable( + HttpJsonCallSettings httpJsonCallSettings, + UnaryCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createUnaryCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public + UnaryCallable createPagedCallable( + HttpJsonCallSettings httpJsonCallSettings, + PagedCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createPagedCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @Override + public UnaryCallable createBatchingCallable( + HttpJsonCallSettings httpJsonCallSettings, + BatchingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createBatchingCallable( + httpJsonCallSettings, callSettings, clientContext); + } + + @BetaApi( + "The surface for long-running operations is not stable yet and may change in the future.") + @Override + public + OperationCallable createOperationCallable( + HttpJsonCallSettings httpJsonCallSettings, + OperationCallSettings callSettings, + ClientContext clientContext, + OperationsStub operationsStub) { + UnaryCallable innerCallable = + HttpJsonCallableFactory.createBaseUnaryCallable( + httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext); + HttpJsonOperationSnapshotCallable initialCallable = + new HttpJsonOperationSnapshotCallable( + innerCallable, + httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory()); + return HttpJsonCallableFactory.createOperationCallable( + callSettings, clientContext, operationsStub.longRunningClient(), initialCallable); + } + + @Override + public + ServerStreamingCallable createServerStreamingCallable( + HttpJsonCallSettings httpJsonCallSettings, + ServerStreamingCallSettings callSettings, + ClientContext clientContext) { + return HttpJsonCallableFactory.createServerStreamingCallable( + httpJsonCallSettings, callSettings, clientContext); + } +} diff --git a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceStub.java b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceStub.java new file mode 100644 index 000000000000..56f363a4c30f --- /dev/null +++ b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/HttpJsonSpeechTranslationServiceStub.java @@ -0,0 +1,134 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.stub; + +import com.google.api.core.BetaApi; +import com.google.api.core.InternalApi; +import com.google.api.gax.core.BackgroundResource; +import com.google.api.gax.core.BackgroundResourceAggregation; +import com.google.api.gax.httpjson.ApiMethodDescriptor; +import com.google.api.gax.httpjson.HttpJsonStubCallableFactory; +import com.google.api.gax.rpc.ClientContext; +import com.google.protobuf.TypeRegistry; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +/** + * REST stub implementation for the SpeechTranslationService service API. + * + *

This class is for advanced usage and reflects the underlying API directly. + */ +@BetaApi +@Generated("by gapic-generator-java") +public class HttpJsonSpeechTranslationServiceStub extends SpeechTranslationServiceStub { + private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build(); + + private final BackgroundResource backgroundResources; + private final HttpJsonStubCallableFactory callableFactory; + + public static final HttpJsonSpeechTranslationServiceStub create( + SpeechTranslationServiceStubSettings settings) throws IOException { + return new HttpJsonSpeechTranslationServiceStub(settings, ClientContext.create(settings)); + } + + public static final HttpJsonSpeechTranslationServiceStub create(ClientContext clientContext) + throws IOException { + return new HttpJsonSpeechTranslationServiceStub( + SpeechTranslationServiceStubSettings.newHttpJsonBuilder().build(), clientContext); + } + + public static final HttpJsonSpeechTranslationServiceStub create( + ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { + return new HttpJsonSpeechTranslationServiceStub( + SpeechTranslationServiceStubSettings.newHttpJsonBuilder().build(), + clientContext, + callableFactory); + } + + /** + * Constructs an instance of HttpJsonSpeechTranslationServiceStub, using the given settings. This + * is protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonSpeechTranslationServiceStub( + SpeechTranslationServiceStubSettings settings, ClientContext clientContext) + throws IOException { + this(settings, clientContext, new HttpJsonSpeechTranslationServiceCallableFactory()); + } + + /** + * Constructs an instance of HttpJsonSpeechTranslationServiceStub, using the given settings. This + * is protected so that it is easy to make a subclass, but otherwise, the static factory methods + * should be preferred. + */ + protected HttpJsonSpeechTranslationServiceStub( + SpeechTranslationServiceStubSettings settings, + ClientContext clientContext, + HttpJsonStubCallableFactory callableFactory) + throws IOException { + this.callableFactory = callableFactory; + + this.backgroundResources = + new BackgroundResourceAggregation(clientContext.getBackgroundResources()); + } + + @InternalApi + public static List getMethodDescriptors() { + List methodDescriptors = new ArrayList<>(); + return methodDescriptors; + } + + @Override + public final void close() { + try { + backgroundResources.close(); + } catch (RuntimeException e) { + throw e; + } catch (Exception e) { + throw new IllegalStateException("Failed to close resource", e); + } + } + + @Override + public void shutdown() { + backgroundResources.shutdown(); + } + + @Override + public boolean isShutdown() { + return backgroundResources.isShutdown(); + } + + @Override + public boolean isTerminated() { + return backgroundResources.isTerminated(); + } + + @Override + public void shutdownNow() { + backgroundResources.shutdownNow(); + } + + @Override + public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { + return backgroundResources.awaitTermination(duration, unit); + } +} diff --git a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/SpeechTranslationServiceStubSettings.java b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/SpeechTranslationServiceStubSettings.java index ff02c5c73843..8bd813b01749 100644 --- a/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/SpeechTranslationServiceStubSettings.java +++ b/java-mediatranslation/google-cloud-mediatranslation/src/main/java/com/google/cloud/mediatranslation/v1beta1/stub/SpeechTranslationServiceStubSettings.java @@ -24,6 +24,9 @@ import com.google.api.gax.grpc.GaxGrpcProperties; import com.google.api.gax.grpc.GrpcTransportChannel; import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider; +import com.google.api.gax.httpjson.GaxHttpJsonProperties; +import com.google.api.gax.httpjson.HttpJsonTransportChannel; +import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider; import com.google.api.gax.retrying.RetrySettings; import com.google.api.gax.rpc.ApiClientHeaderProvider; import com.google.api.gax.rpc.ClientContext; @@ -103,6 +106,11 @@ public SpeechTranslationServiceStub createStub() throws IOException { .equals(GrpcTransportChannel.getGrpcTransportName())) { return GrpcSpeechTranslationServiceStub.create(this); } + if (getTransportChannelProvider() + .getTransportName() + .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) { + return HttpJsonSpeechTranslationServiceStub.create(this); + } throw new UnsupportedOperationException( String.format( "Transport not supported: %s", getTransportChannelProvider().getTransportName())); @@ -135,18 +143,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde .setUseJwtAccessWithScope(true); } - /** Returns a builder for the default ChannelProvider for this service. */ + /** Returns a builder for the default gRPC ChannelProvider for this service. */ public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() { return InstantiatingGrpcChannelProvider.newBuilder() .setMaxInboundMessageSize(Integer.MAX_VALUE); } + /** Returns a builder for the default REST ChannelProvider for this service. */ + @BetaApi + public static InstantiatingHttpJsonChannelProvider.Builder + defaultHttpJsonTransportProviderBuilder() { + return InstantiatingHttpJsonChannelProvider.newBuilder(); + } + public static TransportChannelProvider defaultTransportChannelProvider() { return defaultGrpcTransportProviderBuilder().build(); } @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") - public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() { return ApiClientHeaderProvider.newBuilder() .setGeneratedLibToken( "gapic", GaxProperties.getLibraryVersion(SpeechTranslationServiceStubSettings.class)) @@ -154,11 +169,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion()); } - /** Returns a new builder for this class. */ + @BetaApi("The surface for customizing headers is not stable yet and may change in the future.") + public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() { + return ApiClientHeaderProvider.newBuilder() + .setGeneratedLibToken( + "gapic", GaxProperties.getLibraryVersion(SpeechTranslationServiceStubSettings.class)) + .setTransportToken( + GaxHttpJsonProperties.getHttpJsonTokenName(), + GaxHttpJsonProperties.getHttpJsonVersion()); + } + + public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() { + return SpeechTranslationServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder(); + } + + /** Returns a new gRPC builder for this class. */ public static Builder newBuilder() { return Builder.createDefault(); } + /** Returns a new REST builder for this class. */ + public static Builder newHttpJsonBuilder() { + return Builder.createHttpJsonDefault(); + } + /** Returns a new builder for this class. */ public static Builder newBuilder(ClientContext clientContext) { return new Builder(clientContext); @@ -243,6 +277,19 @@ private static Builder createDefault() { return initDefaults(builder); } + private static Builder createHttpJsonDefault() { + Builder builder = new Builder(((ClientContext) null)); + + builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build()); + builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build()); + builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build()); + builder.setEndpoint(getDefaultEndpoint()); + builder.setMtlsEndpoint(getDefaultMtlsEndpoint()); + builder.setSwitchToMtlsEndpointAllowed(true); + + return initDefaults(builder); + } + private static Builder initDefaults(Builder builder) { return builder; } diff --git a/java-mediatranslation/google-cloud-mediatranslation/src/test/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClientHttpJsonTest.java b/java-mediatranslation/google-cloud-mediatranslation/src/test/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClientHttpJsonTest.java new file mode 100644 index 000000000000..3a34f73df6e6 --- /dev/null +++ b/java-mediatranslation/google-cloud-mediatranslation/src/test/java/com/google/cloud/mediatranslation/v1beta1/SpeechTranslationServiceClientHttpJsonTest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.httpjson.testing.MockHttpService; +import com.google.cloud.mediatranslation.v1beta1.stub.HttpJsonSpeechTranslationServiceStub; +import java.io.IOException; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class SpeechTranslationServiceClientHttpJsonTest { + private static MockHttpService mockService; + private static SpeechTranslationServiceClient client; + + @BeforeClass + public static void startStaticServer() throws IOException { + mockService = + new MockHttpService( + HttpJsonSpeechTranslationServiceStub.getMethodDescriptors(), + SpeechTranslationServiceSettings.getDefaultEndpoint()); + SpeechTranslationServiceSettings settings = + SpeechTranslationServiceSettings.newHttpJsonBuilder() + .setTransportChannelProvider( + SpeechTranslationServiceSettings.defaultHttpJsonTransportProviderBuilder() + .setHttpTransport(mockService) + .build()) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = SpeechTranslationServiceClient.create(settings); + } + + @AfterClass + public static void stopServer() { + client.close(); + } + + @Before + public void setUp() {} + + @After + public void tearDown() throws Exception { + mockService.reset(); + } + + @Test + public void streamingTranslateSpeechUnsupportedMethodTest() throws Exception { + // The streamingTranslateSpeech() method is not supported in REST transport. + // This empty test is generated for technical reasons. + } +} diff --git a/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider.java b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider.java new file mode 100644 index 000000000000..e61cf2857630 --- /dev/null +++ b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider.java @@ -0,0 +1,44 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.samples; + +// [START +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_create_setcredentialsprovider_sync] +import com.google.api.gax.core.FixedCredentialsProvider; +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceClient; +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceSettings; +import com.google.cloud.mediatranslation.v1beta1.myCredentials; + +public class SyncCreateSetCredentialsProvider { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider(); + } + + public static void syncCreateSetCredentialsProvider() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + SpeechTranslationServiceSettings speechTranslationServiceSettings = + SpeechTranslationServiceSettings.newBuilder() + .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) + .build(); + SpeechTranslationServiceClient speechTranslationServiceClient = + SpeechTranslationServiceClient.create(speechTranslationServiceSettings); + } +} +// [END +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_create_setcredentialsprovider_sync] diff --git a/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider1.java b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider1.java new file mode 100644 index 000000000000..062fbaaa9148 --- /dev/null +++ b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetCredentialsProvider1.java @@ -0,0 +1,43 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.samples; + +// [START +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_create_setcredentialsprovider1_sync] +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceClient; +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceSettings; + +public class SyncCreateSetCredentialsProvider1 { + + public static void main(String[] args) throws Exception { + syncCreateSetCredentialsProvider1(); + } + + public static void syncCreateSetCredentialsProvider1() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + SpeechTranslationServiceSettings speechTranslationServiceSettings = + SpeechTranslationServiceSettings.newBuilder() + .setTransportChannelProvider( + SpeechTranslationServiceSettings.defaultHttpJsonTransportProviderBuilder().build()) + .build(); + SpeechTranslationServiceClient speechTranslationServiceClient = + SpeechTranslationServiceClient.create(speechTranslationServiceSettings); + } +} +// [END +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_create_setcredentialsprovider1_sync] diff --git a/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetEndpoint.java b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetEndpoint.java new file mode 100644 index 000000000000..ac22aa1e4aba --- /dev/null +++ b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/create/SyncCreateSetEndpoint.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.samples; + +// [START mediatranslation_v1beta1_generated_speechtranslationserviceclient_create_setendpoint_sync] +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceClient; +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceSettings; +import com.google.cloud.mediatranslation.v1beta1.myEndpoint; + +public class SyncCreateSetEndpoint { + + public static void main(String[] args) throws Exception { + syncCreateSetEndpoint(); + } + + public static void syncCreateSetEndpoint() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + SpeechTranslationServiceSettings speechTranslationServiceSettings = + SpeechTranslationServiceSettings.newBuilder().setEndpoint(myEndpoint).build(); + SpeechTranslationServiceClient speechTranslationServiceClient = + SpeechTranslationServiceClient.create(speechTranslationServiceSettings); + } +} +// [END mediatranslation_v1beta1_generated_speechtranslationserviceclient_create_setendpoint_sync] diff --git a/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/streamingtranslatespeech/AsyncStreamingTranslateSpeech.java b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/streamingtranslatespeech/AsyncStreamingTranslateSpeech.java new file mode 100644 index 000000000000..da6e7618127c --- /dev/null +++ b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationserviceclient/streamingtranslatespeech/AsyncStreamingTranslateSpeech.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.samples; + +// [START +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_streamingtranslatespeech_async] +import com.google.api.gax.rpc.BidiStream; +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceClient; +import com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest; +import com.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse; + +public class AsyncStreamingTranslateSpeech { + + public static void main(String[] args) throws Exception { + asyncStreamingTranslateSpeech(); + } + + public static void asyncStreamingTranslateSpeech() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + try (SpeechTranslationServiceClient speechTranslationServiceClient = + SpeechTranslationServiceClient.create()) { + BidiStream bidiStream = + speechTranslationServiceClient.streamingTranslateSpeechCallable().call(); + StreamingTranslateSpeechRequest request = + StreamingTranslateSpeechRequest.newBuilder().build(); + bidiStream.send(request); + for (StreamingTranslateSpeechResponse response : bidiStream) { + // Do something when a response is received. + } + } + } +} +// [END +// mediatranslation_v1beta1_generated_speechtranslationserviceclient_streamingtranslatespeech_async] diff --git a/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationservicesettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationservicesettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java new file mode 100644 index 000000000000..5bcffe358b92 --- /dev/null +++ b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/speechtranslationservicesettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.samples; + +// [START +// mediatranslation_v1beta1_generated_speechtranslationservicesettings_streamingtranslatespeech_sync] +import com.google.cloud.mediatranslation.v1beta1.SpeechTranslationServiceSettings; +import java.time.Duration; + +public class SyncStreamingTranslateSpeech { + + public static void main(String[] args) throws Exception { + syncStreamingTranslateSpeech(); + } + + public static void syncStreamingTranslateSpeech() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + SpeechTranslationServiceSettings.Builder speechTranslationServiceSettingsBuilder = + SpeechTranslationServiceSettings.newBuilder(); + speechTranslationServiceSettingsBuilder + .streamingTranslateSpeechSettings() + .setRetrySettings( + speechTranslationServiceSettingsBuilder + .streamingTranslateSpeechSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + SpeechTranslationServiceSettings speechTranslationServiceSettings = + speechTranslationServiceSettingsBuilder.build(); + } +} +// [END +// mediatranslation_v1beta1_generated_speechtranslationservicesettings_streamingtranslatespeech_sync] diff --git a/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/stub/speechtranslationservicestubsettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/stub/speechtranslationservicestubsettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java new file mode 100644 index 000000000000..158675ee1377 --- /dev/null +++ b/java-mediatranslation/samples/snippets/generated/com/google/cloud/mediatranslation/v1beta1/stub/speechtranslationservicestubsettings/streamingtranslatespeech/SyncStreamingTranslateSpeech.java @@ -0,0 +1,49 @@ +/* + * Copyright 2022 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.cloud.mediatranslation.v1beta1.stub.samples; + +// [START +// mediatranslation_v1beta1_generated_speechtranslationservicestubsettings_streamingtranslatespeech_sync] +import com.google.cloud.mediatranslation.v1beta1.stub.SpeechTranslationServiceStubSettings; +import java.time.Duration; + +public class SyncStreamingTranslateSpeech { + + public static void main(String[] args) throws Exception { + syncStreamingTranslateSpeech(); + } + + public static void syncStreamingTranslateSpeech() throws Exception { + // This snippet has been automatically generated for illustrative purposes only. + // It may require modifications to work in your environment. + SpeechTranslationServiceStubSettings.Builder speechTranslationServiceSettingsBuilder = + SpeechTranslationServiceStubSettings.newBuilder(); + speechTranslationServiceSettingsBuilder + .streamingTranslateSpeechSettings() + .setRetrySettings( + speechTranslationServiceSettingsBuilder + .streamingTranslateSpeechSettings() + .getRetrySettings() + .toBuilder() + .setTotalTimeout(Duration.ofSeconds(30)) + .build()); + SpeechTranslationServiceStubSettings speechTranslationServiceSettings = + speechTranslationServiceSettingsBuilder.build(); + } +} +// [END +// mediatranslation_v1beta1_generated_speechtranslationservicestubsettings_streamingtranslatespeech_sync]