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..76770a819870 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,9 @@
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.ResumableUploadCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.location.GetLocationRequest;
import com.google.cloud.location.ListLocationsRequest;
@@ -38,6 +40,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;
@@ -81,7 +84,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 +280,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));
}
// 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..394857733d46 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;
@@ -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/stub/GrpcResumableUploadServiceStub.java b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcResumableUploadServiceStub.java
index c53ba897f216..87773ab6d79d 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,9 +22,13 @@
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.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;
@@ -39,11 +43,13 @@
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.concurrent.TimeUnit;
import javax.annotation.Generated;
import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
@@ -55,17 +61,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 +112,6 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
.setSampledToLocalTracing(true)
.build();
- private final UnaryCallable uploadMediaCallable;
private final UnaryCallable listLocationsCallable;
private final UnaryCallable
listLocationsPagedCallable;
@@ -129,6 +123,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 +166,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 +221,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,6 +242,20 @@ protected GrpcResumableUploadServiceStub(
settings.testIamPermissionsSettings(),
clientContext);
+ if (clientContext.getCredentials() != null) {
+ ClientContext httpJsonClientContext =
+ ClientContext.newBuilder()
+ .setCredentials(clientContext.getCredentials())
+ .setEndpoint(settings.getEndpoint())
+ .setExecutor(clientContext.getExecutor())
+ .setDefaultCallContext(HttpJsonCallContext.createDefault())
+ .build();
+ this.resumableUploadStub =
+ HttpJsonResumableUploadServiceResumableUploadStub.create(httpJsonClientContext, settings);
+ } else {
+ this.resumableUploadStub = null;
+ }
+
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
@@ -262,11 +264,6 @@ public GrpcOperationsStub getOperationsStub() {
return operationsStub;
}
- @Override
- public UnaryCallable uploadMediaCallable() {
- return uploadMediaCallable;
- }
-
@Override
public UnaryCallable listLocationsCallable() {
return listLocationsCallable;
@@ -299,10 +296,27 @@ 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 {
backgroundResources.close();
+ if (resumableUploadStub != null) {
+ resumableUploadStub.close();
+ }
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
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..a70a2d03f507
--- /dev/null
+++ b/java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/HttpJsonResumableUploadServiceResumableUploadStub.java
@@ -0,0 +1,164 @@
+/*
+ * 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;
+
+/**
+ * REST stub transport for the resumable upload methods of ResumableUploadService.
+ *
+ * <p>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..f51cddd89ba3 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,6 +30,7 @@
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;
@@ -64,41 +65,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 +248,6 @@ public class HttpJsonResumableUploadServiceStub extends ResumableUploadServiceSt
.build())
.build();
- private final UnaryCallable uploadMediaCallable;
private final UnaryCallable listLocationsCallable;
private final UnaryCallable
listLocationsPagedCallable;
@@ -293,6 +258,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 +302,6 @@ protected HttpJsonResumableUploadServiceStub(
throws IOException {
this.callableFactory = callableFactory;
- HttpJsonCallSettings uploadMediaTransportSettings =
- HttpJsonCallSettings.newBuilder()
- .setMethodDescriptor(uploadMediaMethodDescriptor)
- .setTypeRegistry(typeRegistry)
- .build();
HttpJsonCallSettings
listLocationsTransportSettings =
HttpJsonCallSettings.newBuilder()
@@ -402,9 +363,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,6 +384,9 @@ protected HttpJsonResumableUploadServiceStub(
settings.testIamPermissionsSettings(),
clientContext);
+ this.resumableUploadStub =
+ HttpJsonResumableUploadServiceResumableUploadStub.create(clientContext, settings);
+
this.backgroundResources =
new BackgroundResourceAggregation(clientContext.getBackgroundResources());
}
@@ -433,7 +394,6 @@ protected HttpJsonResumableUploadServiceStub(
@InternalApi
public static List getMethodDescriptors() {
List methodDescriptors = new ArrayList<>();
- methodDescriptors.add(uploadMediaMethodDescriptor);
methodDescriptors.add(listLocationsMethodDescriptor);
methodDescriptors.add(getLocationMethodDescriptor);
methodDescriptors.add(setIamPolicyMethodDescriptor);
@@ -442,11 +402,6 @@ public static List getMethodDescriptors() {
return methodDescriptors;
}
- @Override
- public UnaryCallable uploadMediaCallable() {
- return uploadMediaCallable;
- }
-
@Override
public UnaryCallable listLocationsCallable() {
return listLocationsCallable;
@@ -479,10 +434,16 @@ public UnaryCallable getIamPolicyCallable() {
return testIamPermissionsCallable;
}
+ @Override
+ public ResumableUploadCallable uploadMediaCallable() {
+ return resumableUploadStub.uploadMediaCallable();
+ }
+
@Override
public final void close() {
try {
backgroundResources.close();
+ resumableUploadStub.close();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
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..c1d1652dc438 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;
@@ -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..08b78e7e2352 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
@@ -94,44 +94,8 @@ public void tearDown() throws Exception {
@Test
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..2f343127bd8e 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
@@ -103,38 +103,8 @@ public void tearDown() throws Exception {
@Test
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/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 efff9219416c..dd7d1689c766 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
@@ -137,7 +137,8 @@ enum SelectiveGapicType {
"google.cloud.bigquery.v2.TableService.ListTables");
private static final ImmutableList RESUMABLE_UPLOAD_ALLOWLIST_PATTERNS =
- ImmutableList.of();
+ ImmutableList.of(
+ Pattern.compile("^google\\.showcase\\.v1beta1\\.ResumableUploadService\\.UploadMedia$"));
// 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 ff34f675aac9..a1a9bdbcdcd3 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,7 +228,7 @@ void parseMethods_resumableUpload() {
assertEquals(1, methods.size());
Method uploadMethod = methods.get(0);
assertEquals("UploadMedia", uploadMethod.name());
- assertFalse(uploadMethod.isResumableUpload());
+ assertTrue(uploadMethod.isResumableUpload());
}
@Test
|