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,25 @@ 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 = HttpJsonResumableUploadServiceResumableUploadStub .create (settings );
248+ this .backgroundResources =
249+ new BackgroundResourceAggregation (
250+ ImmutableList .<BackgroundResource >builder ()
251+ .addAll (clientContext .getBackgroundResources ())
252+ .add (resumableUploadStub )
253+ .build ());
254+ } else {
255+ this .resumableUploadStub = null ;
256+ this .backgroundResources =
257+ new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
258+ }
259259 }
260260
261261 public GrpcOperationsStub getOperationsStub () {
262262 return operationsStub ;
263263 }
264264
265- @ Override
266- public UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
267- return uploadMediaCallable ;
268- }
269-
270265 @ Override
271266 public UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable () {
272267 return listLocationsCallable ;
@@ -299,6 +294,20 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
299294 return testIamPermissionsCallable ;
300295 }
301296
297+ @ Override
298+ public ResumableUploadCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
299+ if (resumableUploadStub == null ) {
300+ throw new FailedPreconditionException (
301+ "Resumable uploads execute over HTTP/REST and require credentials. The client was"
302+ + " initialized with a pre-constructed gRPC Channel, from which credentials cannot be"
303+ + " extracted. Please configure a CredentialsProvider instead." ,
304+ null ,
305+ GrpcStatusCode .of (Status .Code .FAILED_PRECONDITION ),
306+ false );
307+ }
308+ return resumableUploadStub .uploadMediaCallable ();
309+ }
310+
302311 @ Override
303312 public final void close () {
304313 try {
0 commit comments