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 ;
3945import com .google .showcase .v1beta1 .UploadMediaRequest ;
4046import com .google .showcase .v1beta1 .UploadMediaResponse ;
4147import io .grpc .MethodDescriptor ;
48+ import io .grpc .Status ;
4249import io .grpc .protobuf .ProtoUtils ;
4350import java .io .IOException ;
51+ import java .util .Arrays ;
4452import java .util .concurrent .TimeUnit ;
4553import javax .annotation .Generated ;
4654import org .jspecify .annotations .NullMarked ;
55+ import org .jspecify .annotations .Nullable ;
4756
4857// AUTO-GENERATED DOCUMENTATION AND CLASS.
4958/**
5564@ BetaApi
5665@ Generated ("by gapic-generator-java" )
5766public 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-
6967 private static final MethodDescriptor <ListLocationsRequest , ListLocationsResponse >
7068 listLocationsMethodDescriptor =
7169 MethodDescriptor .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
@@ -117,7 +115,6 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
117115 .setSampledToLocalTracing (true )
118116 .build ();
119117
120- private final UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable ;
121118 private final UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable ;
122119 private final UnaryCallable <ListLocationsRequest , ListLocationsPagedResponse >
123120 listLocationsPagedCallable ;
@@ -129,6 +126,7 @@ public class GrpcResumableUploadServiceStub extends ResumableUploadServiceStub {
129126
130127 private final BackgroundResource backgroundResources ;
131128 private final GrpcOperationsStub operationsStub ;
129+ private final @ Nullable HttpJsonResumableUploadServiceResumableUploadStub resumableUploadStub ;
132130 private final GrpcStubCallableFactory callableFactory ;
133131
134132 public static final GrpcResumableUploadServiceStub create (
@@ -171,10 +169,6 @@ protected GrpcResumableUploadServiceStub(
171169 this .callableFactory = callableFactory ;
172170 this .operationsStub = GrpcOperationsStub .create (clientContext , callableFactory );
173171
174- GrpcCallSettings <UploadMediaRequest , UploadMediaResponse > uploadMediaTransportSettings =
175- GrpcCallSettings .<UploadMediaRequest , UploadMediaResponse >newBuilder ()
176- .setMethodDescriptor (uploadMediaMethodDescriptor )
177- .build ();
178172 GrpcCallSettings <ListLocationsRequest , ListLocationsResponse > listLocationsTransportSettings =
179173 GrpcCallSettings .<ListLocationsRequest , ListLocationsResponse >newBuilder ()
180174 .setMethodDescriptor (listLocationsMethodDescriptor )
@@ -230,9 +224,6 @@ protected GrpcResumableUploadServiceStub(
230224 .setResourceNameExtractor (request -> request .getResource ())
231225 .build ();
232226
233- this .uploadMediaCallable =
234- callableFactory .createUnaryCallable (
235- uploadMediaTransportSettings , settings .uploadMediaSettings (), clientContext );
236227 this .listLocationsCallable =
237228 callableFactory .createUnaryCallable (
238229 listLocationsTransportSettings , settings .listLocationsSettings (), clientContext );
@@ -254,6 +245,31 @@ protected GrpcResumableUploadServiceStub(
254245 settings .testIamPermissionsSettings (),
255246 clientContext );
256247
248+ if (clientContext .getCredentials () != null ) {
249+ ManagedHttpJsonChannel httpJsonManagedChannel =
250+ ManagedHttpJsonChannel .newBuilder ()
251+ .setEndpoint (settings .getEndpoint ())
252+ .setExecutor (clientContext .getExecutor ())
253+ .build ();
254+ HttpJsonTransportChannel httpJsonTransportChannel =
255+ HttpJsonTransportChannel .create (httpJsonManagedChannel );
256+ ClientContext httpJsonClientContext =
257+ ClientContext .newBuilder ()
258+ .setCredentials (clientContext .getCredentials ())
259+ .setEndpoint (settings .getEndpoint ())
260+ .setExecutor (clientContext .getExecutor ())
261+ .setTransportChannel (httpJsonTransportChannel )
262+ .setDefaultCallContext (
263+ HttpJsonCallContext .createDefault ()
264+ .withTransportChannel (httpJsonTransportChannel ))
265+ .setBackgroundResources (Arrays .asList (httpJsonTransportChannel ))
266+ .build ();
267+ this .resumableUploadStub =
268+ HttpJsonResumableUploadServiceResumableUploadStub .create (httpJsonClientContext , settings );
269+ } else {
270+ this .resumableUploadStub = null ;
271+ }
272+
257273 this .backgroundResources =
258274 new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
259275 }
@@ -262,11 +278,6 @@ public GrpcOperationsStub getOperationsStub() {
262278 return operationsStub ;
263279 }
264280
265- @ Override
266- public UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
267- return uploadMediaCallable ;
268- }
269-
270281 @ Override
271282 public UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable () {
272283 return listLocationsCallable ;
@@ -299,10 +310,27 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
299310 return testIamPermissionsCallable ;
300311 }
301312
313+ @ Override
314+ public ResumableUploadCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
315+ if (resumableUploadStub == null ) {
316+ throw new FailedPreconditionException (
317+ "Resumable uploads execute over HTTP/REST and require credentials. The client was"
318+ + " initialized with a pre-constructed gRPC Channel, from which credentials cannot be"
319+ + " extracted. Please configure a CredentialsProvider instead." ,
320+ null ,
321+ GrpcStatusCode .of (Status .Code .FAILED_PRECONDITION ),
322+ false );
323+ }
324+ return resumableUploadStub .uploadMediaCallable ();
325+ }
326+
302327 @ Override
303328 public final void close () {
304329 try {
305330 backgroundResources .close ();
331+ if (resumableUploadStub != null ) {
332+ resumableUploadStub .close ();
333+ }
306334 } catch (RuntimeException e ) {
307335 throw e ;
308336 } catch (Exception e ) {
0 commit comments