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 .httpjson .HttpJsonCallContext ;
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 ;
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,6 +242,20 @@ protected GrpcResumableUploadServiceStub(
254242 settings .testIamPermissionsSettings (),
255243 clientContext );
256244
245+ if (clientContext .getCredentials () != null ) {
246+ ClientContext httpJsonClientContext =
247+ ClientContext .newBuilder ()
248+ .setCredentials (clientContext .getCredentials ())
249+ .setEndpoint (settings .getEndpoint ())
250+ .setExecutor (clientContext .getExecutor ())
251+ .setDefaultCallContext (HttpJsonCallContext .createDefault ())
252+ .build ();
253+ this .resumableUploadStub =
254+ HttpJsonResumableUploadServiceResumableUploadStub .create (httpJsonClientContext , settings );
255+ } else {
256+ this .resumableUploadStub = null ;
257+ }
258+
257259 this .backgroundResources =
258260 new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
259261 }
@@ -262,11 +264,6 @@ public GrpcOperationsStub getOperationsStub() {
262264 return operationsStub ;
263265 }
264266
265- @ Override
266- public UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
267- return uploadMediaCallable ;
268- }
269-
270267 @ Override
271268 public UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable () {
272269 return listLocationsCallable ;
@@ -299,10 +296,27 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
299296 return testIamPermissionsCallable ;
300297 }
301298
299+ @ Override
300+ public ResumableUploadCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
301+ if (resumableUploadStub == null ) {
302+ throw new FailedPreconditionException (
303+ "Resumable uploads execute over HTTP/REST and require credentials. The client was"
304+ + " initialized with a pre-constructed gRPC Channel, from which credentials cannot be"
305+ + " extracted. Please configure a CredentialsProvider instead." ,
306+ null ,
307+ GrpcStatusCode .of (Status .Code .FAILED_PRECONDITION ),
308+ false );
309+ }
310+ return resumableUploadStub .uploadMediaCallable ();
311+ }
312+
302313 @ Override
303314 public final void close () {
304315 try {
305316 backgroundResources .close ();
317+ if (resumableUploadStub != null ) {
318+ resumableUploadStub .close ();
319+ }
306320 } catch (RuntimeException e ) {
307321 throw e ;
308322 } catch (Exception e ) {
0 commit comments