diff --git a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceClient.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceClient.java
index 1968ffbf77e1..2b679f6bf317 100644
--- a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceClient.java
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceClient.java
@@ -23,7 +23,10 @@
import com.google.api.gax.paging.AbstractFixedSizeCollection;
import com.google.api.gax.paging.AbstractPage;
import com.google.api.gax.paging.AbstractPagedListResponse;
+import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.PageContext;
+import com.google.api.gax.rpc.ResumableUploadCallSettings;
+import com.google.api.gax.rpc.ResumableUploadCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.location.GetLocationRequest;
import com.google.cloud.location.ListLocationsRequest;
@@ -38,6 +41,7 @@
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStub;
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStubSettings;
import java.io.IOException;
+import java.io.InputStream;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
@@ -59,8 +63,8 @@
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (ResumableUploadServiceClient resumableUploadServiceClient =
* ResumableUploadServiceClient.create()) {
- * UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- * UploadMediaResponse response = resumableUploadServiceClient.uploadMedia(request);
+ * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
+ * Location response = resumableUploadServiceClient.getLocation(request);
* }
* }
*
@@ -81,7 +85,7 @@
*
* Request object method variants only take one parameter, a request object, which must be constructed before the call.
*
- * uploadMedia(UploadMediaRequest request)
+ * uploadMedia(UploadMediaRequest request, InputStream payload)
*
* Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
*
@@ -277,51 +281,29 @@ public ResumableUploadServiceStub getStub() {
/**
* A method with media_upload annotation enabled.
*
- * Sample code:
- *
- * {@code
- * // This snippet has been automatically generated and should be regarded as a code template only.
- * // It will require modifications to work:
- * // - It may require correct/in-range values for request initialization.
- * // - It may require specifying regional endpoints when creating the service client as shown in
- * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
- * try (ResumableUploadServiceClient resumableUploadServiceClient =
- * ResumableUploadServiceClient.create()) {
- * UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- * UploadMediaResponse response = resumableUploadServiceClient.uploadMedia(request);
- * }
- * }
+ * Call context overrides (such as withTimeout, withRetrySettings, or credentials) apply
+ * strictly to the start request (session initiation). Per-chunk PUT calls rely on the configured
+ * timeout and retry settings from ResumableUploadCallSettings.
*
* @param request The request object containing all of the parameters for the API call.
+ * @param payload The payload data stream to upload.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
- public final UploadMediaResponse uploadMedia(UploadMediaRequest request) {
- return uploadMediaCallable().call(request);
+ public final UploadMediaResponse uploadMedia(UploadMediaRequest request, InputStream payload) {
+ return ApiExceptions.callAndTranslateApiException(
+ uploadMediaCallable().futureCall(request, payload, ((ResumableUploadCallSettings) null)));
}
// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* A method with media_upload annotation enabled.
*
- * Sample code:
- *
- * {@code
- * // This snippet has been automatically generated and should be regarded as a code template only.
- * // It will require modifications to work:
- * // - It may require correct/in-range values for request initialization.
- * // - It may require specifying regional endpoints when creating the service client as shown in
- * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
- * try (ResumableUploadServiceClient resumableUploadServiceClient =
- * ResumableUploadServiceClient.create()) {
- * UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- * ApiFuture future =
- * resumableUploadServiceClient.uploadMediaCallable().futureCall(request);
- * // Do something.
- * UploadMediaResponse response = future.get();
- * }
- * }
+ * Call context overrides (such as withTimeout, withRetrySettings, or credentials) apply
+ * strictly to the start request (session initiation). Per-chunk PUT calls rely on the configured
+ * timeout and retry settings from ResumableUploadCallSettings.
*/
- public final UnaryCallable uploadMediaCallable() {
+ public final ResumableUploadCallable
+ uploadMediaCallable() {
return stub.uploadMediaCallable();
}
diff --git a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceSettings.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceSettings.java
index 170f7d46c1b1..a22cd0473405 100644
--- a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceSettings.java
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceSettings.java
@@ -28,6 +28,7 @@
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
import com.google.api.gax.rpc.PagedCallSettings;
+import com.google.api.gax.rpc.ResumableUploadCallSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.cloud.location.GetLocationRequest;
@@ -63,7 +64,7 @@
*
* For example, to set the
* [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings)
- * of uploadMedia:
+ * of getLocation:
*
* {@code
* // This snippet has been automatically generated and should be regarded as a code template only.
@@ -74,10 +75,10 @@
* ResumableUploadServiceSettings.Builder resumableUploadServiceSettingsBuilder =
* ResumableUploadServiceSettings.newBuilder();
* resumableUploadServiceSettingsBuilder
- * .uploadMediaSettings()
+ * .getLocationSettings()
* .setRetrySettings(
* resumableUploadServiceSettingsBuilder
- * .uploadMediaSettings()
+ * .getLocationSettings()
* .getRetrySettings()
* .toBuilder()
* .setInitialRetryDelayDuration(Duration.ofSeconds(1))
@@ -102,8 +103,13 @@
@Generated("by gapic-generator-java")
public class ResumableUploadServiceSettings extends ClientSettings {
- /** Returns the object with the settings used for calls to uploadMedia. */
- public UnaryCallSettings uploadMediaSettings() {
+ /**
+ * Returns the object with the settings used for calls to uploadMedia.
+ *
+ * Note that custom retry settings and headers configured via ApiCallContext apply strictly to
+ * the initial session initiation request.
+ */
+ public ResumableUploadCallSettings uploadMediaSettings() {
return ((ResumableUploadServiceStubSettings) getStubSettings()).uploadMediaSettings();
}
@@ -247,9 +253,13 @@ public Builder applyToAllUnaryMethods(
return this;
}
- /** Returns the builder for the settings used for calls to uploadMedia. */
- public UnaryCallSettings.Builder
- uploadMediaSettings() {
+ /**
+ * Returns the builder for the settings used for calls to uploadMedia.
+ *
+ * Note that custom retry settings and headers configured via ApiCallContext apply strictly
+ * to the initial session initiation request.
+ */
+ public ResumableUploadCallSettings.Builder uploadMediaSettings() {
return getStubSettingsBuilder().uploadMediaSettings();
}
diff --git a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java
index 50bdad9ad900..ef1d91b82d88 100644
--- a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java
@@ -137,8 +137,8 @@
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
* try (ResumableUploadServiceClient resumableUploadServiceClient =
* ResumableUploadServiceClient.create()) {
- * UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- * UploadMediaResponse response = resumableUploadServiceClient.uploadMedia(request);
+ * GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
+ * Location response = resumableUploadServiceClient.getLocation(request);
* }
* }
*
diff --git a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcResumableUploadServiceStub.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcResumableUploadServiceStub.java
index c53ba897f216..5772084d5fdd 100644
--- a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcResumableUploadServiceStub.java
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcResumableUploadServiceStub.java
@@ -22,14 +22,21 @@
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.grpc.GrpcCallSettings;
+import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.grpc.GrpcStubCallableFactory;
+import com.google.api.gax.httpjson.HttpJsonCallContext;
+import com.google.api.gax.httpjson.HttpJsonTransportChannel;
+import com.google.api.gax.httpjson.ManagedHttpJsonChannel;
import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.FailedPreconditionException;
import com.google.api.gax.rpc.RequestParamsBuilder;
+import com.google.api.gax.rpc.ResumableUploadCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.location.GetLocationRequest;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.ListLocationsResponse;
import com.google.cloud.location.Location;
+import com.google.common.collect.ImmutableList;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
import com.google.iam.v1.SetIamPolicyRequest;
@@ -39,11 +46,14 @@
import com.google.showcase.v1beta1.UploadMediaRequest;
import com.google.showcase.v1beta1.UploadMediaResponse;
import io.grpc.MethodDescriptor;
+import io.grpc.Status;
import io.grpc.protobuf.ProtoUtils;
import java.io.IOException;
+import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;
import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
@@ -55,17 +65,6 @@
@BetaApi
@Generated("by gapic-generator-java")
public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
- private static final MethodDescriptor
- uploadMediaMethodDescriptor =
- MethodDescriptor.newBuilder()
- .setType(MethodDescriptor.MethodType.UNARY)
- .setFullMethodName("google.showcase.v1beta1.ResumableUploadService/UploadMedia")
- .setRequestMarshaller(ProtoUtils.marshaller(UploadMediaRequest.getDefaultInstance()))
- .setResponseMarshaller(
- ProtoUtils.marshaller(UploadMediaResponse.getDefaultInstance()))
- .setSampledToLocalTracing(true)
- .build();
-
private static final MethodDescriptor
listLocationsMethodDescriptor =
MethodDescriptor.newBuilder()
@@ -117,7 +116,6 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
.setSampledToLocalTracing(true)
.build();
- private final UnaryCallable uploadMediaCallable;
private final UnaryCallable listLocationsCallable;
private final UnaryCallable
listLocationsPagedCallable;
@@ -129,6 +127,7 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
private final BackgroundResource backgroundResources;
private final GrpcOperationsStub operationsStub;
+ private final @Nullable HttpJsonResumableUploadServiceResumableUploadStub resumableUploadStub;
private final GrpcStubCallableFactory callableFactory;
public static final GrpcResumableUploadServiceStub create(
@@ -171,10 +170,6 @@ protected GrpcResumableUploadServiceStub(
this.callableFactory = callableFactory;
this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
- GrpcCallSettings uploadMediaTransportSettings =
- GrpcCallSettings.newBuilder()
- .setMethodDescriptor(uploadMediaMethodDescriptor)
- .build();
GrpcCallSettings listLocationsTransportSettings =
GrpcCallSettings.newBuilder()
.setMethodDescriptor(listLocationsMethodDescriptor)
@@ -230,9 +225,6 @@ protected GrpcResumableUploadServiceStub(
.setResourceNameExtractor(request -> request.getResource())
.build();
- this.uploadMediaCallable =
- callableFactory.createUnaryCallable(
- uploadMediaTransportSettings, settings.uploadMediaSettings(), clientContext);
this.listLocationsCallable =
callableFactory.createUnaryCallable(
listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
@@ -254,19 +246,51 @@ protected GrpcResumableUploadServiceStub(
settings.testIamPermissionsSettings(),
clientContext);
- this.backgroundResources =
- new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ if (clientContext.getCredentials() != null) {
+ ManagedHttpJsonChannel httpJsonManagedChannel =
+ ManagedHttpJsonChannel.newBuilder()
+ .setEndpoint(settings.getEndpoint())
+ .setExecutor(clientContext.getExecutor())
+ .build();
+ HttpJsonTransportChannel httpJsonTransportChannel =
+ HttpJsonTransportChannel.create(httpJsonManagedChannel);
+ ClientContext httpJsonClientContext =
+ ClientContext.newBuilder()
+ .setCredentials(clientContext.getCredentials())
+ .setEndpoint(settings.getEndpoint())
+ .setExecutor(clientContext.getExecutor())
+ .setHeaders(clientContext.getHeaders())
+ .setInternalHeaders(clientContext.getInternalHeaders())
+ .setClock(clientContext.getClock())
+ .setTransportChannel(httpJsonTransportChannel)
+ .setDefaultCallContext(
+ HttpJsonCallContext.createDefault()
+ .withTransportChannel(httpJsonTransportChannel))
+ .setBackgroundResources(Arrays.asList(httpJsonTransportChannel))
+ .build();
+ this.resumableUploadStub =
+ HttpJsonResumableUploadServiceResumableUploadStub.create(httpJsonClientContext, settings);
+ } else {
+ this.resumableUploadStub = null;
+ }
+
+ if (resumableUploadStub != null) {
+ this.backgroundResources =
+ new BackgroundResourceAggregation(
+ ImmutableList.builder()
+ .addAll(clientContext.getBackgroundResources())
+ .add(resumableUploadStub)
+ .build());
+ } else {
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
}
public GrpcOperationsStub getOperationsStub() {
return operationsStub;
}
- @Override
- public UnaryCallable uploadMediaCallable() {
- return uploadMediaCallable;
- }
-
@Override
public UnaryCallable listLocationsCallable() {
return listLocationsCallable;
@@ -299,6 +323,20 @@ public UnaryCallable getIamPolicyCallable() {
return testIamPermissionsCallable;
}
+ @Override
+ public ResumableUploadCallable uploadMediaCallable() {
+ if (resumableUploadStub == null) {
+ throw new FailedPreconditionException(
+ "Resumable uploads execute over HTTP/REST and require credentials. The client was"
+ + " initialized with a pre-constructed gRPC Channel, from which credentials cannot be"
+ + " extracted. Please configure a CredentialsProvider instead.",
+ null,
+ GrpcStatusCode.of(Status.Code.FAILED_PRECONDITION),
+ false);
+ }
+ return resumableUploadStub.uploadMediaCallable();
+ }
+
@Override
public final void close() {
try {
diff --git a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceResumableUploadStub.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceResumableUploadStub.java
new file mode 100644
index 000000000000..d4383591c6f0
--- /dev/null
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceResumableUploadStub.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2026 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.showcase.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.HttpJsonCallSettings;
+import com.google.api.gax.httpjson.HttpJsonCallableFactory;
+import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
+import com.google.api.gax.httpjson.ProtoMessageResponseParser;
+import com.google.api.gax.httpjson.ProtoRestSerializer;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.ResumableUploadCallable;
+import com.google.protobuf.TypeRegistry;
+import com.google.showcase.v1beta1.UploadMediaRequest;
+import com.google.showcase.v1beta1.UploadMediaResponse;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.Generated;
+import org.jspecify.annotations.NullMarked;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * REST stub transport for the resumable upload methods of ResumableUploadService.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+@InternalApi
+@NullMarked
+@BetaApi
+public class HttpJsonResumableUploadServiceResumableUploadStub implements BackgroundResource {
+ private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
+
+ private static final ApiMethodDescriptor
+ uploadMediaMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.showcase.v1beta1.ResumableUploadService/UploadMedia")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/resumable/upload/v1beta1/files:upload",
+ request -> {
+ Map fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setQueryParamsExtractor(
+ request -> {
+ Map> fields = new HashMap<>();
+ ProtoRestSerializer serializer =
+ ProtoRestSerializer.create();
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("*", request.toBuilder().build(), false))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(UploadMediaResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private final BackgroundResource backgroundResources;
+ private final ResumableUploadCallable
+ uploadMediaCallable;
+
+ public static HttpJsonResumableUploadServiceResumableUploadStub create(
+ ClientContext clientContext, ResumableUploadServiceStubSettings settings) {
+ return new HttpJsonResumableUploadServiceResumableUploadStub(clientContext, settings);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonResumableUploadServiceResumableUploadStub, 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 HttpJsonResumableUploadServiceResumableUploadStub(
+ ClientContext clientContext, ResumableUploadServiceStubSettings settings) {
+ HttpJsonCallSettings uploadMediaTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(uploadMediaMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ this.uploadMediaCallable =
+ HttpJsonCallableFactory.createResumableUploadCallable(
+ uploadMediaTransportSettings, settings.uploadMediaSettings(), clientContext);
+
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
+
+ @InternalApi
+ public static List getMethodDescriptors() {
+ List methodDescriptors = new ArrayList<>();
+ methodDescriptors.add(uploadMediaMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ public ResumableUploadCallable uploadMediaCallable() {
+ return uploadMediaCallable;
+ }
+
+ @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-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceStub.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceStub.java
index 9ff80141d227..1aa16cfe1742 100644
--- a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceStub.java
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceStub.java
@@ -30,11 +30,13 @@
import com.google.api.gax.httpjson.ProtoRestSerializer;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.RequestParamsBuilder;
+import com.google.api.gax.rpc.ResumableUploadCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.location.GetLocationRequest;
import com.google.cloud.location.ListLocationsRequest;
import com.google.cloud.location.ListLocationsResponse;
import com.google.cloud.location.Location;
+import com.google.common.collect.ImmutableList;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
import com.google.iam.v1.SetIamPolicyRequest;
@@ -64,41 +66,6 @@
public class HttpJsonResumableUploadServiceStub extends ResumableUploadServiceStub {
private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
- private static final ApiMethodDescriptor
- uploadMediaMethodDescriptor =
- ApiMethodDescriptor.newBuilder()
- .setFullMethodName("google.showcase.v1beta1.ResumableUploadService/UploadMedia")
- .setHttpMethod("POST")
- .setType(ApiMethodDescriptor.MethodType.UNARY)
- .setRequestFormatter(
- ProtoMessageRequestFormatter.newBuilder()
- .setPath(
- "/v1beta1/files:upload",
- request -> {
- Map fields = new HashMap<>();
- ProtoRestSerializer serializer =
- ProtoRestSerializer.create();
- return fields;
- })
- .setQueryParamsExtractor(
- request -> {
- Map> fields = new HashMap<>();
- ProtoRestSerializer serializer =
- ProtoRestSerializer.create();
- return fields;
- })
- .setRequestBodyExtractor(
- request ->
- ProtoRestSerializer.create()
- .toBody("*", request.toBuilder().build(), false))
- .build())
- .setResponseParser(
- ProtoMessageResponseParser.newBuilder()
- .setDefaultInstance(UploadMediaResponse.getDefaultInstance())
- .setDefaultTypeRegistry(typeRegistry)
- .build())
- .build();
-
private static final ApiMethodDescriptor
listLocationsMethodDescriptor =
ApiMethodDescriptor.newBuilder()
@@ -282,7 +249,6 @@ public class HttpJsonResumableUploadServiceStub extends ResumableUploadServiceSt
.build())
.build();
- private final UnaryCallable uploadMediaCallable;
private final UnaryCallable listLocationsCallable;
private final UnaryCallable
listLocationsPagedCallable;
@@ -293,6 +259,7 @@ public class HttpJsonResumableUploadServiceStub extends ResumableUploadServiceSt
testIamPermissionsCallable;
private final BackgroundResource backgroundResources;
+ private final HttpJsonResumableUploadServiceResumableUploadStub resumableUploadStub;
private final HttpJsonStubCallableFactory callableFactory;
public static final HttpJsonResumableUploadServiceStub create(
@@ -336,11 +303,6 @@ protected HttpJsonResumableUploadServiceStub(
throws IOException {
this.callableFactory = callableFactory;
- HttpJsonCallSettings uploadMediaTransportSettings =
- HttpJsonCallSettings.newBuilder()
- .setMethodDescriptor(uploadMediaMethodDescriptor)
- .setTypeRegistry(typeRegistry)
- .build();
HttpJsonCallSettings
listLocationsTransportSettings =
HttpJsonCallSettings.newBuilder()
@@ -402,9 +364,6 @@ protected HttpJsonResumableUploadServiceStub(
.setResourceNameExtractor(request -> request.getResource())
.build();
- this.uploadMediaCallable =
- callableFactory.createUnaryCallable(
- uploadMediaTransportSettings, settings.uploadMediaSettings(), clientContext);
this.listLocationsCallable =
callableFactory.createUnaryCallable(
listLocationsTransportSettings, settings.listLocationsSettings(), clientContext);
@@ -426,14 +385,20 @@ protected HttpJsonResumableUploadServiceStub(
settings.testIamPermissionsSettings(),
clientContext);
+ this.resumableUploadStub =
+ HttpJsonResumableUploadServiceResumableUploadStub.create(clientContext, settings);
+
this.backgroundResources =
- new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ new BackgroundResourceAggregation(
+ ImmutableList.builder()
+ .addAll(clientContext.getBackgroundResources())
+ .add(resumableUploadStub)
+ .build());
}
@InternalApi
public static List getMethodDescriptors() {
List methodDescriptors = new ArrayList<>();
- methodDescriptors.add(uploadMediaMethodDescriptor);
methodDescriptors.add(listLocationsMethodDescriptor);
methodDescriptors.add(getLocationMethodDescriptor);
methodDescriptors.add(setIamPolicyMethodDescriptor);
@@ -442,11 +407,6 @@ public static List getMethodDescriptors() {
return methodDescriptors;
}
- @Override
- public UnaryCallable uploadMediaCallable() {
- return uploadMediaCallable;
- }
-
@Override
public UnaryCallable listLocationsCallable() {
return listLocationsCallable;
@@ -479,6 +439,11 @@ public UnaryCallable getIamPolicyCallable() {
return testIamPermissionsCallable;
}
+ @Override
+ public ResumableUploadCallable uploadMediaCallable() {
+ return resumableUploadStub.uploadMediaCallable();
+ }
+
@Override
public final void close() {
try {
diff --git a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStub.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStub.java
index a1d2f4d08d5d..b1a388819a01 100644
--- a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStub.java
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStub.java
@@ -20,6 +20,7 @@
import com.google.api.core.BetaApi;
import com.google.api.gax.core.BackgroundResource;
+import com.google.api.gax.rpc.ResumableUploadCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.location.GetLocationRequest;
import com.google.cloud.location.ListLocationsRequest;
@@ -46,7 +47,7 @@
@Generated("by gapic-generator-java")
public abstract class ResumableUploadServiceStub implements BackgroundResource {
- public UnaryCallable uploadMediaCallable() {
+ public ResumableUploadCallable uploadMediaCallable() {
throw new UnsupportedOperationException("Not implemented: uploadMediaCallable()");
}
diff --git a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStubSettings.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStubSettings.java
index 869085d6cdeb..5b1299136440 100644
--- a/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStubSettings.java
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/ResumableUploadServiceStubSettings.java
@@ -40,6 +40,7 @@
import com.google.api.gax.rpc.PagedCallSettings;
import com.google.api.gax.rpc.PagedListDescriptor;
import com.google.api.gax.rpc.PagedListResponseFactory;
+import com.google.api.gax.rpc.ResumableUploadCallSettings;
import com.google.api.gax.rpc.StatusCode;
import com.google.api.gax.rpc.StubSettings;
import com.google.api.gax.rpc.TransportChannelProvider;
@@ -58,8 +59,6 @@
import com.google.iam.v1.SetIamPolicyRequest;
import com.google.iam.v1.TestIamPermissionsRequest;
import com.google.iam.v1.TestIamPermissionsResponse;
-import com.google.showcase.v1beta1.UploadMediaRequest;
-import com.google.showcase.v1beta1.UploadMediaResponse;
import java.io.IOException;
import java.time.Duration;
import java.util.List;
@@ -84,7 +83,7 @@
*
* For example, to set the
* [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings)
- * of uploadMedia:
+ * of getLocation:
*
* {@code
* // This snippet has been automatically generated and should be regarded as a code template only.
@@ -95,10 +94,10 @@
* ResumableUploadServiceStubSettings.Builder resumableUploadServiceSettingsBuilder =
* ResumableUploadServiceStubSettings.newBuilder();
* resumableUploadServiceSettingsBuilder
- * .uploadMediaSettings()
+ * .getLocationSettings()
* .setRetrySettings(
* resumableUploadServiceSettingsBuilder
- * .uploadMediaSettings()
+ * .getLocationSettings()
* .getRetrySettings()
* .toBuilder()
* .setInitialRetryDelayDuration(Duration.ofSeconds(1))
@@ -128,7 +127,7 @@ public class ResumableUploadServiceStubSettings
private static final ImmutableList DEFAULT_SERVICE_SCOPES =
ImmutableList.builder().build();
- private final UnaryCallSettings uploadMediaSettings;
+ private final ResumableUploadCallSettings uploadMediaSettings;
private final PagedCallSettings<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings;
@@ -189,8 +188,13 @@ public ApiFuture getFuturePagedResponse(
}
};
- /** Returns the object with the settings used for calls to uploadMedia. */
- public UnaryCallSettings uploadMediaSettings() {
+ /**
+ * Returns the object with the settings used for calls to uploadMedia.
+ *
+ * Note that custom retry settings and headers configured via ApiCallContext apply strictly to
+ * the initial session initiation request.
+ */
+ public ResumableUploadCallSettings uploadMediaSettings() {
return uploadMediaSettings;
}
@@ -347,8 +351,7 @@ protected LibraryMetadata getLibraryMetadata() {
public static class Builder
extends StubSettings.Builder {
private final ImmutableList> unaryMethodSettingsBuilders;
- private final UnaryCallSettings.Builder
- uploadMediaSettings;
+ private final ResumableUploadCallSettings.Builder uploadMediaSettings;
private final PagedCallSettings.Builder<
ListLocationsRequest, ListLocationsResponse, ListLocationsPagedResponse>
listLocationsSettings;
@@ -391,7 +394,7 @@ protected Builder() {
protected Builder(@Nullable ClientContext clientContext) {
super(clientContext);
- uploadMediaSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
+ uploadMediaSettings = ResumableUploadCallSettings.newBuilder();
listLocationsSettings = PagedCallSettings.newBuilder(LIST_LOCATIONS_PAGE_STR_FACT);
getLocationSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
setIamPolicySettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
@@ -400,7 +403,6 @@ protected Builder(@Nullable ClientContext clientContext) {
unaryMethodSettingsBuilders =
ImmutableList.>of(
- uploadMediaSettings,
listLocationsSettings,
getLocationSettings,
setIamPolicySettings,
@@ -421,7 +423,6 @@ protected Builder(ResumableUploadServiceStubSettings settings) {
unaryMethodSettingsBuilders =
ImmutableList.>of(
- uploadMediaSettings,
listLocationsSettings,
getLocationSettings,
setIamPolicySettings,
@@ -454,10 +455,7 @@ private static Builder createHttpJsonDefault() {
}
private static Builder initDefaults(Builder builder) {
- builder
- .uploadMediaSettings()
- .setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_0_codes"))
- .setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_0_params"));
+ builder.uploadMediaSettings().setGlobalTimeout(Duration.ofMillis(5000L));
builder
.listLocationsSettings()
@@ -502,9 +500,13 @@ public Builder applyToAllUnaryMethods(
return unaryMethodSettingsBuilders;
}
- /** Returns the builder for the settings used for calls to uploadMedia. */
- public UnaryCallSettings.Builder
- uploadMediaSettings() {
+ /**
+ * Returns the builder for the settings used for calls to uploadMedia.
+ *
+ * Note that custom retry settings and headers configured via ApiCallContext apply strictly
+ * to the initial session initiation request.
+ */
+ public ResumableUploadCallSettings.Builder uploadMediaSettings() {
return uploadMediaSettings;
}
diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientHttpJsonTest.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientHttpJsonTest.java
index 801abd04ab19..02c6f4ee058b 100644
--- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientHttpJsonTest.java
+++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientHttpJsonTest.java
@@ -55,6 +55,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
@Generated("by gapic-generator-java")
@@ -93,45 +94,12 @@ public void tearDown() throws Exception {
}
@Test
+ @Ignore(
+ "Requires live HTTP/REST server supporting resumable upload protocol; tested in integration"
+ + " tests.")
public void uploadMediaTest() throws Exception {
- UploadMediaResponse expectedResponse =
- UploadMediaResponse.newBuilder().setName("name3373707").setSize(3530753).build();
- mockService.addResponse(expectedResponse);
-
- UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
-
- UploadMediaResponse actualResponse = client.uploadMedia(request);
- Assert.assertEquals(expectedResponse, actualResponse);
-
- List actualRequests = mockService.getRequestPaths();
- Assert.assertEquals(1, actualRequests.size());
-
- String apiClientHeaderKey =
- mockService
- .getRequestHeaders()
- .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
- .iterator()
- .next();
- Assert.assertTrue(
- GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
- .matcher(apiClientHeaderKey)
- .matches());
- }
-
- @Test
- public void uploadMediaExceptionTest() throws Exception {
- ApiException exception =
- ApiExceptionFactory.createException(
- new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
- mockService.addException(exception);
-
- try {
- UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- client.uploadMedia(request);
- Assert.fail("No exception raised");
- } catch (InvalidArgumentException e) {
- // Expected exception.
- }
+ // The uploadMedia() method requires a live HTTP/REST server supporting the resumable upload
+ // protocol and is tested in integration tests.
}
@Test
diff --git a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientTest.java b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientTest.java
index 97bf0fc6b6ba..f18d8fde5fc0 100644
--- a/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientTest.java
+++ b/java-showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/ResumableUploadServiceClientTest.java
@@ -55,6 +55,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
@Generated("by gapic-generator-java")
@@ -102,39 +103,12 @@ public void tearDown() throws Exception {
}
@Test
+ @Ignore(
+ "Requires live HTTP/REST server supporting resumable upload protocol; tested in integration"
+ + " tests.")
public void uploadMediaTest() throws Exception {
- UploadMediaResponse expectedResponse =
- UploadMediaResponse.newBuilder().setName("name3373707").setSize(3530753).build();
- mockResumableUploadService.addResponse(expectedResponse);
-
- UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
-
- UploadMediaResponse actualResponse = client.uploadMedia(request);
- Assert.assertEquals(expectedResponse, actualResponse);
-
- List actualRequests = mockResumableUploadService.getRequests();
- Assert.assertEquals(1, actualRequests.size());
- UploadMediaRequest actualRequest = ((UploadMediaRequest) actualRequests.get(0));
-
- Assert.assertEquals(request.getName(), actualRequest.getName());
- Assert.assertTrue(
- channelProvider.isHeaderSent(
- ApiClientHeaderProvider.getDefaultApiClientHeaderKey(),
- GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
- }
-
- @Test
- public void uploadMediaExceptionTest() throws Exception {
- StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
- mockResumableUploadService.addException(exception);
-
- try {
- UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- client.uploadMedia(request);
- Assert.fail("No exception raised");
- } catch (InvalidArgumentException e) {
- // Expected exception.
- }
+ // The uploadMedia() method requires a live HTTP/REST server supporting the resumable upload
+ // protocol and is tested in integration tests.
}
@Test
diff --git a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservice/uploadmedia/AsyncUploadMedia.java b/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservice/uploadmedia/AsyncUploadMedia.java
deleted file mode 100644
index bbad94d58645..000000000000
--- a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservice/uploadmedia/AsyncUploadMedia.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2026 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.showcase.v1beta1.samples;
-
-// [START localhost7469_v1beta1_generated_ResumableUploadService_UploadMedia_async]
-import com.google.api.core.ApiFuture;
-import com.google.showcase.v1beta1.ResumableUploadServiceClient;
-import com.google.showcase.v1beta1.UploadMediaRequest;
-import com.google.showcase.v1beta1.UploadMediaResponse;
-
-public class AsyncUploadMedia {
-
- public static void main(String[] args) throws Exception {
- asyncUploadMedia();
- }
-
- public static void asyncUploadMedia() throws Exception {
- // This snippet has been automatically generated and should be regarded as a code template only.
- // It will require modifications to work:
- // - It may require correct/in-range values for request initialization.
- // - It may require specifying regional endpoints when creating the service client as shown in
- // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
- try (ResumableUploadServiceClient resumableUploadServiceClient =
- ResumableUploadServiceClient.create()) {
- UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- ApiFuture future =
- resumableUploadServiceClient.uploadMediaCallable().futureCall(request);
- // Do something.
- UploadMediaResponse response = future.get();
- }
- }
-}
-// [END localhost7469_v1beta1_generated_ResumableUploadService_UploadMedia_async]
diff --git a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservice/uploadmedia/SyncUploadMedia.java b/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservice/uploadmedia/SyncUploadMedia.java
deleted file mode 100644
index 2e9f35be9eed..000000000000
--- a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservice/uploadmedia/SyncUploadMedia.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright 2026 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.showcase.v1beta1.samples;
-
-// [START localhost7469_v1beta1_generated_ResumableUploadService_UploadMedia_sync]
-import com.google.showcase.v1beta1.ResumableUploadServiceClient;
-import com.google.showcase.v1beta1.UploadMediaRequest;
-import com.google.showcase.v1beta1.UploadMediaResponse;
-
-public class SyncUploadMedia {
-
- public static void main(String[] args) throws Exception {
- syncUploadMedia();
- }
-
- public static void syncUploadMedia() throws Exception {
- // This snippet has been automatically generated and should be regarded as a code template only.
- // It will require modifications to work:
- // - It may require correct/in-range values for request initialization.
- // - It may require specifying regional endpoints when creating the service client as shown in
- // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
- try (ResumableUploadServiceClient resumableUploadServiceClient =
- ResumableUploadServiceClient.create()) {
- UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
- UploadMediaResponse response = resumableUploadServiceClient.uploadMedia(request);
- }
- }
-}
-// [END localhost7469_v1beta1_generated_ResumableUploadService_UploadMedia_sync]
diff --git a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservicesettings/uploadmedia/SyncUploadMedia.java b/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservicesettings/getlocation/SyncGetLocation.java
similarity index 90%
rename from java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservicesettings/uploadmedia/SyncUploadMedia.java
rename to java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservicesettings/getlocation/SyncGetLocation.java
index f4212736f15b..e256e7d37504 100644
--- a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservicesettings/uploadmedia/SyncUploadMedia.java
+++ b/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/resumableuploadservicesettings/getlocation/SyncGetLocation.java
@@ -16,17 +16,17 @@
package com.google.showcase.v1beta1.samples;
-// [START localhost7469_v1beta1_generated_ResumableUploadServiceSettings_UploadMedia_sync]
+// [START localhost7469_v1beta1_generated_ResumableUploadServiceSettings_GetLocation_sync]
import com.google.showcase.v1beta1.ResumableUploadServiceSettings;
import java.time.Duration;
-public class SyncUploadMedia {
+public class SyncGetLocation {
public static void main(String[] args) throws Exception {
- syncUploadMedia();
+ syncGetLocation();
}
- public static void syncUploadMedia() throws Exception {
+ public static void syncGetLocation() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
@@ -35,10 +35,10 @@ public static void syncUploadMedia() throws Exception {
ResumableUploadServiceSettings.Builder resumableUploadServiceSettingsBuilder =
ResumableUploadServiceSettings.newBuilder();
resumableUploadServiceSettingsBuilder
- .uploadMediaSettings()
+ .getLocationSettings()
.setRetrySettings(
resumableUploadServiceSettingsBuilder
- .uploadMediaSettings()
+ .getLocationSettings()
.getRetrySettings()
.toBuilder()
.setInitialRetryDelayDuration(Duration.ofSeconds(1))
@@ -54,4 +54,4 @@ public static void syncUploadMedia() throws Exception {
resumableUploadServiceSettingsBuilder.build();
}
}
-// [END localhost7469_v1beta1_generated_ResumableUploadServiceSettings_UploadMedia_sync]
+// [END localhost7469_v1beta1_generated_ResumableUploadServiceSettings_GetLocation_sync]
diff --git a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/stub/resumableuploadservicestubsettings/uploadmedia/SyncUploadMedia.java b/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/stub/resumableuploadservicestubsettings/getlocation/SyncGetLocation.java
similarity index 90%
rename from java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/stub/resumableuploadservicestubsettings/uploadmedia/SyncUploadMedia.java
rename to java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/stub/resumableuploadservicestubsettings/getlocation/SyncGetLocation.java
index 1b76094e5f4e..18481a57773a 100644
--- a/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/stub/resumableuploadservicestubsettings/uploadmedia/SyncUploadMedia.java
+++ b/java-showcase/samples/snippets/generated/com/google/showcase/v1beta1/stub/resumableuploadservicestubsettings/getlocation/SyncGetLocation.java
@@ -16,17 +16,17 @@
package com.google.showcase.v1beta1.stub.samples;
-// [START localhost7469_v1beta1_generated_ResumableUploadServiceStubSettings_UploadMedia_sync]
+// [START localhost7469_v1beta1_generated_ResumableUploadServiceStubSettings_GetLocation_sync]
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStubSettings;
import java.time.Duration;
-public class SyncUploadMedia {
+public class SyncGetLocation {
public static void main(String[] args) throws Exception {
- syncUploadMedia();
+ syncGetLocation();
}
- public static void syncUploadMedia() throws Exception {
+ public static void syncGetLocation() throws Exception {
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
@@ -35,10 +35,10 @@ public static void syncUploadMedia() throws Exception {
ResumableUploadServiceStubSettings.Builder resumableUploadServiceSettingsBuilder =
ResumableUploadServiceStubSettings.newBuilder();
resumableUploadServiceSettingsBuilder
- .uploadMediaSettings()
+ .getLocationSettings()
.setRetrySettings(
resumableUploadServiceSettingsBuilder
- .uploadMediaSettings()
+ .getLocationSettings()
.getRetrySettings()
.toBuilder()
.setInitialRetryDelayDuration(Duration.ofSeconds(1))
@@ -54,4 +54,4 @@ public static void syncUploadMedia() throws Exception {
resumableUploadServiceSettingsBuilder.build();
}
}
-// [END localhost7469_v1beta1_generated_ResumableUploadServiceStubSettings_UploadMedia_sync]
+// [END localhost7469_v1beta1_generated_ResumableUploadServiceStubSettings_GetLocation_sync]
diff --git a/sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java b/sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
index 6b3ed6de6ba8..24059b7d54a5 100644
--- a/sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
+++ b/sdk-platform-java/gapic-generator-java/src/main/java/com/google/api/generator/gapic/protoparser/Parser.java
@@ -135,8 +135,12 @@ enum SelectiveGapicType {
"google.cloud.bigquery.v2.ModelService.ListModels",
"google.cloud.bigquery.v2.TableService.ListTables");
- private static final ImmutableList RESUMABLE_UPLOAD_ALLOWLIST_PATTERNS =
- ImmutableList.of();
+ @VisibleForTesting
+ static final ImmutableList RESUMABLE_UPLOAD_ALLOWLIST_PATTERNS =
+ ImmutableList.of(
+ Pattern.compile("^google\\.showcase\\.v1beta1\\.ResumableUploadService\\.UploadMedia$"),
+ Pattern.compile(
+ "^google\\.ads\\.googleads\\.v\\d+\\.services\\.YouTubeVideoUploadService\\.CreateYouTubeVideoUpload$"));
// Allow other parsers to access this.
protected static final SourceCodeInfoParser SOURCE_CODE_INFO_PARSER = new SourceCodeInfoParser();
diff --git a/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java b/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java
index f611fa79a8f5..0bf293c11aa8 100644
--- a/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java
+++ b/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/gapic/protoparser/ParserTest.java
@@ -228,43 +228,20 @@ void parseMethods_resumableUpload() {
outputResourceNames,
Transport.GRPC);
- assertEquals(1, methods.size());
+ assertThat(methods).hasSize(1);
Method uploadMethod = methods.get(0);
- assertEquals("UploadMedia", uploadMethod.name());
- assertFalse(uploadMethod.isResumableUpload());
+ assertThat(uploadMethod.name()).isEqualTo("UploadMedia");
+ assertThat(uploadMethod.isResumableUpload()).isTrue();
}
@Test
- void parseMethods_resumableUpload_withConfiguredAllowlist() {
- FileDescriptor resumableUploadFileDescriptor = ResumableUpload.getDescriptor();
- ServiceDescriptor resumableUploadService = resumableUploadFileDescriptor.getServices().get(0);
- Map messageTypes = Parser.parseMessages(resumableUploadFileDescriptor);
- Map resourceNames =
- Parser.parseResourceNames(resumableUploadFileDescriptor);
- Set outputResourceNames = new HashSet<>();
- String protoPackage = resumableUploadFileDescriptor.getPackage();
- String servicePackage = TypeParser.getPackage(resumableUploadFileDescriptor);
- List allowlist =
- Arrays.asList(
- Pattern.compile(
- "^google\\.showcase\\.v1beta1\\.ResumableUploadService\\.UploadMedia$"));
- List methods =
- Parser.parseMethods(
- resumableUploadService,
- protoPackage,
- servicePackage,
- messageTypes,
- resourceNames,
- Optional.empty(),
- Optional.empty(),
- outputResourceNames,
- Transport.GRPC,
- allowlist);
-
- assertEquals(1, methods.size());
- Method uploadMethod = methods.get(0);
- assertEquals("UploadMedia", uploadMethod.name());
- assertTrue(uploadMethod.isResumableUpload());
+ void parseMethods_resumableUploadAllowlist_matchesGoogleAds() {
+ String googleAdsMethod =
+ "google.ads.googleads.v19.services.YouTubeVideoUploadService.CreateYouTubeVideoUpload";
+ assertThat(
+ Parser.RESUMABLE_UPLOAD_ALLOWLIST_PATTERNS.stream()
+ .anyMatch(p -> p.matcher(googleAdsMethod).matches()))
+ .isTrue();
}
@Test
diff --git a/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java b/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java
index c87c1fc6df2e..a8b7830949cd 100644
--- a/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java
+++ b/sdk-platform-java/gapic-generator-java/src/test/java/com/google/api/generator/test/protoloader/TestProtoLoader.java
@@ -294,31 +294,13 @@ public GapicContext parseShowcaseResumableUpload() {
return GapicContext.builder()
.setMessages(messageTypes)
.setResourceNames(resourceNames)
- .setServices(adaptShowcaseResumableUploadForTest(services))
+ .setServices(services)
.setHelperResourceNames(outputResourceNames)
.setTransport(transport)
.setServiceConfig(GapicServiceConfig.create(Optional.empty()))
.build();
}
- // Temporary test scaffolding; removed in PR #14325 once allowlist patterns are activated.
- private static List adaptShowcaseResumableUploadForTest(List services) {
- return services.stream()
- .map(
- s ->
- s.toBuilder()
- .setMethods(
- s.methods().stream()
- .map(
- m ->
- m.name().equals("UploadMedia")
- ? m.toBuilder().setIsResumableUpload(true).build()
- : m)
- .collect(Collectors.toList()))
- .build())
- .collect(Collectors.toList());
- }
-
public GapicContext parseExplicitDynamicRoutingHeaderTesting() {
FileDescriptor testingFileDescriptor =
ExplicitDynamicRoutingHeaderTestingOuterClass.getDescriptor();
|