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,33 @@ 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+ .setHeaders (clientContext .getHeaders ())
262+ .setClock (clientContext .getClock ())
263+ .setTransportChannel (httpJsonTransportChannel )
264+ .setDefaultCallContext (
265+ HttpJsonCallContext .createDefault ()
266+ .withTransportChannel (httpJsonTransportChannel ))
267+ .setBackgroundResources (Arrays .asList (httpJsonTransportChannel ))
268+ .build ();
269+ this .resumableUploadStub =
270+ HttpJsonResumableUploadServiceResumableUploadStub .create (httpJsonClientContext , settings );
271+ } else {
272+ this .resumableUploadStub = null ;
273+ }
274+
257275 this .backgroundResources =
258276 new BackgroundResourceAggregation (clientContext .getBackgroundResources ());
259277 }
@@ -262,11 +280,6 @@ public GrpcOperationsStub getOperationsStub() {
262280 return operationsStub ;
263281 }
264282
265- @ Override
266- public UnaryCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
267- return uploadMediaCallable ;
268- }
269-
270283 @ Override
271284 public UnaryCallable <ListLocationsRequest , ListLocationsResponse > listLocationsCallable () {
272285 return listLocationsCallable ;
@@ -299,10 +312,27 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
299312 return testIamPermissionsCallable ;
300313 }
301314
315+ @ Override
316+ public ResumableUploadCallable <UploadMediaRequest , UploadMediaResponse > uploadMediaCallable () {
317+ if (resumableUploadStub == null ) {
318+ throw new FailedPreconditionException (
319+ "Resumable uploads execute over HTTP/REST and require credentials. The client was"
320+ + " initialized with a pre-constructed gRPC Channel, from which credentials cannot be"
321+ + " extracted. Please configure a CredentialsProvider instead." ,
322+ null ,
323+ GrpcStatusCode .of (Status .Code .FAILED_PRECONDITION ),
324+ false );
325+ }
326+ return resumableUploadStub .uploadMediaCallable ();
327+ }
328+
302329 @ Override
303330 public final void close () {
304331 try {
305332 backgroundResources .close ();
333+ if (resumableUploadStub != null ) {
334+ resumableUploadStub .close ();
335+ }
306336 } catch (RuntimeException e ) {
307337 throw e ;
308338 } catch (Exception e ) {
0 commit comments