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 ;
2627import com .google .api .gax .rpc .ClientContext ;
28+ import com .google .api .gax .rpc .FailedPreconditionException ;
2729import com .google .api .gax .rpc .RequestParamsBuilder ;
30+ import com .google .api .gax .rpc .ResumableUploadCallable ;
2831import com .google .api .gax .rpc .UnaryCallable ;
2932import com .google .cloud .location .GetLocationRequest ;
3033import com .google .cloud .location .ListLocationsRequest ;
3134import com .google .cloud .location .ListLocationsResponse ;
3235import com .google .cloud .location .Location ;
36+ import com .google .common .collect .ImmutableList ;
3337import com .google .iam .v1 .GetIamPolicyRequest ;
3438import com .google .iam .v1 .Policy ;
3539import com .google .iam .v1 .SetIamPolicyRequest ;
3943import com .google .showcase .v1beta1 .UploadMediaRequest ;
4044import com .google .showcase .v1beta1 .UploadMediaResponse ;
4145import io .grpc .MethodDescriptor ;
46+ import io .grpc .Status ;
4247import io .grpc .protobuf .ProtoUtils ;
4348import java .io .IOException ;
4449import java .util .concurrent .TimeUnit ;
4550import javax .annotation .Generated ;
4651import org .jspecify .annotations .NullMarked ;
52+ import org .jspecify .annotations .Nullable ;
4753
4854// AUTO-GENERATED DOCUMENTATION AND CLASS.
4955/**
5561@ BetaApi
5662@ Generated ("by gapic-generator-java" )
5763public 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-
6964 private static final MethodDescriptor <ListLocationsRequest , ListLocationsResponse >
7065 listLocationsMethodDescriptor =
7166 MethodDescriptor .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
@@ -117,7 +112,6 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
117112 .setSampledToLocalTracing (true )
118113 .build ();
119114
120- private final UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable ;
121115 private final UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable ;
122116 private final UnaryCallable <ListLocationsRequest , ListLocationsPagedResponse >
123117 listLocationsPagedCallable ;
@@ -129,6 +123,7 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
129123
130124 private final BackgroundResource backgroundResources ;
131125 private final GrpcOperationsStub operationsStub ;
126+ private final @ Nullable HttpJsonResumableUploadServiceResumableUploadStub resumableUploadStub ;
132127 private final GrpcStubCallableFactory callableFactory ;
133128
134129 public static final GrpcResumableUploadServiceStub create (
@@ -171,10 +166,6 @@ protected GrpcResumableUploadServiceStub(
171166 this .callableFactory = callableFactory ;
172167 this .operationsStub = GrpcOperationsStub .create (clientContext , callableFactory );
173168
174- GrpcCallSettings <UploadMediaRequest , UploadMediaResponse > uploadMediaTransportSettings =
175- GrpcCallSettings .<UploadMediaRequest , UploadMediaResponse >newBuilder ()
176- .setMethodDescriptor (uploadMediaMethodDescriptor )
177- .build ();
178169 GrpcCallSettings <ListLocationsRequest , ListLocationsResponse > listLocationsTransportSettings =
179170 GrpcCallSettings .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
180171 .setMethodDescriptor (listLocationsMethodDescriptor )
@@ -230,9 +221,6 @@ protected GrpcResumableUploadServiceStub(
230221 .setResourceNameExtractor (request -> request .getResource ())
231222 .build ();
232223
233- this .uploadMediaCallable =
234- callableFactory .createUnaryCallable (
235- uploadMediaTransportSettings , settings .uploadMediaSettings (), clientContext );
236224 this .listLocationsCallable =
237225 callableFactory .createUnaryCallable (
238226 listLocationsTransportSettings , settings .listLocationsSettings (), clientContext );
@@ -254,19 +242,26 @@ protected GrpcResumableUploadServiceStub(
254242 settings .testIamPermissionsSettings (),
255243 clientContext );
256244
257- this .backgroundResources =
258- new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
245+ if (clientContext .getCredentials () != null ) {
246+ this .resumableUploadStub =
247+ HttpJsonResumableUploadServiceResumableUploadStub .create (clientContext , 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