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 ;
28+ import com .google .api .gax .httpjson .HttpJsonTransportChannel ;
29+ import com .google .api .gax .httpjson .ManagedHttpJsonChannel ;
2630import com .google .api .gax .rpc .ClientContext ;
31+ import com .google .api .gax .rpc .FailedPreconditionException ;
2732import com .google .api .gax .rpc .RequestParamsBuilder ;
33+ import com .google .api .gax .rpc .ResumableUploadCallable ;
2834import com .google .api .gax .rpc .UnaryCallable ;
2935import com .google .cloud .location .GetLocationRequest ;
3036import com .google .cloud .location .ListLocationsRequest ;
3137import com .google .cloud .location .ListLocationsResponse ;
3238import com .google .cloud .location .Location ;
39+ import com .google .common .collect .ImmutableList ;
3340import com .google .iam .v1 .GetIamPolicyRequest ;
3441import com .google .iam .v1 .Policy ;
3542import com .google .iam .v1 .SetIamPolicyRequest ;
3946import com .google .showcase .v1beta1 .UploadMediaRequest ;
4047import com .google .showcase .v1beta1 .UploadMediaResponse ;
4148import io .grpc .MethodDescriptor ;
49+ import io .grpc .Status ;
4250import io .grpc .protobuf .ProtoUtils ;
4351import java .io .IOException ;
52+ import java .util .Arrays ;
4453import java .util .concurrent .TimeUnit ;
4554import javax .annotation .Generated ;
4655import org .jspecify .annotations .NullMarked ;
56+ import org .jspecify .annotations .Nullable ;
4757
4858// AUTO-GENERATED DOCUMENTATION AND CLASS.
4959/**
5565@ BetaApi
5666@ Generated ("by gapic-generator-java" )
5767public 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-
6968 private static final MethodDescriptor <ListLocationsRequest , ListLocationsResponse >
7069 listLocationsMethodDescriptor =
7170 MethodDescriptor .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
@@ -117,7 +116,6 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
117116 .setSampledToLocalTracing (true )
118117 .build ();
119118
120- private final UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable ;
121119 private final UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable ;
122120 private final UnaryCallable <ListLocationsRequest , ListLocationsPagedResponse >
123121 listLocationsPagedCallable ;
@@ -129,6 +127,7 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
129127
130128 private final BackgroundResource backgroundResources ;
131129 private final GrpcOperationsStub operationsStub ;
130+ private final @ Nullable HttpJsonResumableUploadServiceResumableUploadStub resumableUploadStub ;
132131 private final GrpcStubCallableFactory callableFactory ;
133132
134133 public static final GrpcResumableUploadServiceStub create (
@@ -171,10 +170,6 @@ protected GrpcResumableUploadServiceStub(
171170 this .callableFactory = callableFactory ;
172171 this .operationsStub = GrpcOperationsStub .create (clientContext , callableFactory );
173172
174- GrpcCallSettings <UploadMediaRequest , UploadMediaResponse > uploadMediaTransportSettings =
175- GrpcCallSettings .<UploadMediaRequest , UploadMediaResponse >newBuilder ()
176- .setMethodDescriptor (uploadMediaMethodDescriptor )
177- .build ();
178173 GrpcCallSettings <ListLocationsRequest , ListLocationsResponse > listLocationsTransportSettings =
179174 GrpcCallSettings .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
180175 .setMethodDescriptor (listLocationsMethodDescriptor )
@@ -230,9 +225,6 @@ protected GrpcResumableUploadServiceStub(
230225 .setResourceNameExtractor (request -> request .getResource ())
231226 .build ();
232227
233- this .uploadMediaCallable =
234- callableFactory .createUnaryCallable (
235- uploadMediaTransportSettings , settings .uploadMediaSettings (), clientContext );
236228 this .listLocationsCallable =
237229 callableFactory .createUnaryCallable (
238230 listLocationsTransportSettings , settings .listLocationsSettings (), clientContext );
@@ -254,19 +246,51 @@ protected GrpcResumableUploadServiceStub(
254246 settings .testIamPermissionsSettings (),
255247 clientContext );
256248
257- this .backgroundResources =
258- new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
249+ if (clientContext .getCredentials () != null ) {
250+ ManagedHttpJsonChannel httpJsonManagedChannel =
251+ ManagedHttpJsonChannel .newBuilder ()
252+ .setEndpoint (settings .getEndpoint ())
253+ .setExecutor (clientContext .getExecutor ())
254+ .build ();
255+ HttpJsonTransportChannel httpJsonTransportChannel =
256+ HttpJsonTransportChannel .create (httpJsonManagedChannel );
257+ ClientContext httpJsonClientContext =
258+ ClientContext .newBuilder ()
259+ .setCredentials (clientContext .getCredentials ())
260+ .setEndpoint (settings .getEndpoint ())
261+ .setExecutor (clientContext .getExecutor ())
262+ .setHeaders (clientContext .getHeaders ())
263+ .setInternalHeaders (clientContext .getInternalHeaders ())
264+ .setClock (clientContext .getClock ())
265+ .setTransportChannel (httpJsonTransportChannel )
266+ .setDefaultCallContext (
267+ HttpJsonCallContext .createDefault ()
268+ .withTransportChannel (httpJsonTransportChannel ))
269+ .setBackgroundResources (Arrays .asList (httpJsonTransportChannel ))
270+ .build ();
271+ this .resumableUploadStub =
272+ HttpJsonResumableUploadServiceResumableUploadStub .create (httpJsonClientContext , settings );
273+ } else {
274+ this .resumableUploadStub = null ;
275+ }
276+
277+ if (resumableUploadStub != null ) {
278+ this .backgroundResources =
279+ new BackgroundResourceAggregation (
280+ ImmutableList .<BackgroundResource >builder ()
281+ .addAll (clientContext .getBackgroundResources ())
282+ .add (resumableUploadStub )
283+ .build ());
284+ } else {
285+ this .backgroundResources =
286+ new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
287+ }
259288 }
260289
261290 public GrpcOperationsStub getOperationsStub () {
262291 return operationsStub ;
263292 }
264293
265- @ Override
266- public UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
267- return uploadMediaCallable ;
268- }
269-
270294 @ Override
271295 public UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable () {
272296 return listLocationsCallable ;
@@ -299,6 +323,20 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
299323 return testIamPermissionsCallable ;
300324 }
301325
326+ @ Override
327+ public ResumableUploadCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
328+ if (resumableUploadStub == null ) {
329+ throw new FailedPreconditionException (
330+ "Resumable uploads execute over HTTP/REST and require credentials. The client was"
331+ + " initialized with a pre-constructed gRPC Channel, from which credentials cannot be"
332+ + " extracted. Please configure a CredentialsProvider instead." ,
333+ null ,
334+ GrpcStatusCode .of (Status .Code .FAILED_PRECONDITION ),
335+ false );
336+ }
337+ return resumableUploadStub .uploadMediaCallable ();
338+ }
339+
302340 @ Override
303341 public final void close () {
304342 try {
0 commit comments