2222import com .google .api .gax .core .BackgroundResource ;
2323import com .google .api .gax .core .BackgroundResourceAggregation ;
2424import com .google .api .gax .grpc .GrpcCallSettings ;
25+ import com .google .api .gax .grpc .GrpcStatusCode ;
2526import com .google .api .gax .grpc .GrpcStubCallableFactory ;
27+ import com .google .api .gax .grpc .InstantiatingGrpcChannelProvider ;
2628import com .google .api .gax .rpc .ClientContext ;
29+ import com .google .api .gax .rpc .FailedPreconditionException ;
2730import com .google .api .gax .rpc .RequestParamsBuilder ;
31+ import com .google .api .gax .rpc .ResumableUploadCallable ;
2832import com .google .api .gax .rpc .UnaryCallable ;
2933import com .google .cloud .location .GetLocationRequest ;
3034import com .google .cloud .location .ListLocationsRequest ;
3135import com .google .cloud .location .ListLocationsResponse ;
3236import com .google .cloud .location .Location ;
37+ import com .google .common .collect .ImmutableList ;
3338import com .google .iam .v1 .GetIamPolicyRequest ;
3439import com .google .iam .v1 .Policy ;
3540import com .google .iam .v1 .SetIamPolicyRequest ;
3944import com .google .showcase .v1beta1 .UploadMediaRequest ;
4045import com .google .showcase .v1beta1 .UploadMediaResponse ;
4146import io .grpc .MethodDescriptor ;
47+ import io .grpc .Status ;
4248import io .grpc .protobuf .ProtoUtils ;
4349import java .io .IOException ;
4450import java .util .concurrent .TimeUnit ;
4551import javax .annotation .Generated ;
4652import org .jspecify .annotations .NullMarked ;
53+ import org .jspecify .annotations .Nullable ;
4754
4855// AUTO-GENERATED DOCUMENTATION AND CLASS.
4956/**
5562@ BetaApi
5663@ Generated ("by gapic-generator-java" )
5764public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
58- private static final MethodDescriptor <UploadMediaRequest , UploadMediaResponse >
59- uploadMediaMethodDescriptor =
60- MethodDescriptor .<UploadMediaRequest , UploadMediaResponse >newBuilder ()
61- .setType (MethodDescriptor .MethodType .UNARY )
62- .setFullMethodName ("google.showcase.v1beta1.ResumableUploadService/UploadMedia" )
63- .setRequestMarshaller (ProtoUtils .marshaller (UploadMediaRequest .getDefaultInstance ()))
64- .setResponseMarshaller (
65- ProtoUtils .marshaller (UploadMediaResponse .getDefaultInstance ()))
66- .setSampledToLocalTracing (true )
67- .build ();
68-
6965 private static final MethodDescriptor <ListLocationsRequest , ListLocationsResponse >
7066 listLocationsMethodDescriptor =
7167 MethodDescriptor .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
@@ -117,7 +113,6 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
117113 .setSampledToLocalTracing (true )
118114 .build ();
119115
120- private final UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable ;
121116 private final UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable ;
122117 private final UnaryCallable <ListLocationsRequest , ListLocationsPagedResponse >
123118 listLocationsPagedCallable ;
@@ -129,6 +124,7 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
129124
130125 private final BackgroundResource backgroundResources ;
131126 private final GrpcOperationsStub operationsStub ;
127+ private final @ Nullable HttpJsonResumableUploadServiceResumableUploadStub resumableUploadStub ;
132128 private final GrpcStubCallableFactory callableFactory ;
133129
134130 public static final GrpcResumableUploadServiceStub create (
@@ -171,10 +167,6 @@ protected GrpcResumableUploadServiceStub(
171167 this .callableFactory = callableFactory ;
172168 this .operationsStub = GrpcOperationsStub .create (clientContext , callableFactory );
173169
174- GrpcCallSettings <UploadMediaRequest , UploadMediaResponse > uploadMediaTransportSettings =
175- GrpcCallSettings .<UploadMediaRequest , UploadMediaResponse >newBuilder ()
176- .setMethodDescriptor (uploadMediaMethodDescriptor )
177- .build ();
178170 GrpcCallSettings <ListLocationsRequest , ListLocationsResponse > listLocationsTransportSettings =
179171 GrpcCallSettings .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
180172 .setMethodDescriptor (listLocationsMethodDescriptor )
@@ -230,9 +222,6 @@ protected GrpcResumableUploadServiceStub(
230222 .setResourceNameExtractor (request -> request .getResource ())
231223 .build ();
232224
233- this .uploadMediaCallable =
234- callableFactory .createUnaryCallable (
235- uploadMediaTransportSettings , settings .uploadMediaSettings (), clientContext );
236225 this .listLocationsCallable =
237226 callableFactory .createUnaryCallable (
238227 listLocationsTransportSettings , settings .listLocationsSettings (), clientContext );
@@ -254,19 +243,26 @@ protected GrpcResumableUploadServiceStub(
254243 settings .testIamPermissionsSettings (),
255244 clientContext );
256245
257- this .backgroundResources =
258- new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
246+ if (settings .getTransportChannelProvider () instanceof InstantiatingGrpcChannelProvider ) {
247+ this .resumableUploadStub =
248+ HttpJsonResumableUploadServiceResumableUploadStub .create (clientContext , settings );
249+ this .backgroundResources =
250+ new BackgroundResourceAggregation (
251+ ImmutableList .<BackgroundResource >builder ()
252+ .addAll (clientContext .getBackgroundResources ())
253+ .add (resumableUploadStub )
254+ .build ());
255+ } else {
256+ this .resumableUploadStub = null ;
257+ this .backgroundResources =
258+ new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
259+ }
259260 }
260261
261262 public GrpcOperationsStub getOperationsStub () {
262263 return operationsStub ;
263264 }
264265
265- @ Override
266- public UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
267- return uploadMediaCallable ;
268- }
269-
270266 @ Override
271267 public UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable () {
272268 return listLocationsCallable ;
@@ -299,6 +295,20 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
299295 return testIamPermissionsCallable ;
300296 }
301297
298+ @ Override
299+ public ResumableUploadCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
300+ if (resumableUploadStub == null ) {
301+ throw new FailedPreconditionException (
302+ "Resumable uploads execute over HTTP/REST and require credentials. The client was"
303+ + " initialized with a pre-constructed gRPC Channel, from which credentials cannot be"
304+ + " extracted. Please configure a CredentialsProvider instead." ,
305+ null ,
306+ GrpcStatusCode .of (Status .Code .FAILED_PRECONDITION ),
307+ false );
308+ }
309+ return resumableUploadStub .uploadMediaCallable ();
310+ }
311+
302312 @ Override
303313 public final void close () {
304314 try {
0 commit comments