Skip to content

Commit 4ca74ac

Browse files
committed
feat(generator): activate resumable upload allowlist and regenerate showcase client
1 parent f9779ce commit 4ca74ac

18 files changed

Lines changed: 369 additions & 374 deletions

File tree

java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceClient.java

Lines changed: 19 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
import com.google.api.gax.paging.AbstractFixedSizeCollection;
2424
import com.google.api.gax.paging.AbstractPage;
2525
import com.google.api.gax.paging.AbstractPagedListResponse;
26+
import com.google.api.gax.rpc.ApiExceptions;
2627
import com.google.api.gax.rpc.PageContext;
28+
import com.google.api.gax.rpc.ResumableUploadCallSettings;
29+
import com.google.api.gax.rpc.ResumableUploadCallable;
2730
import com.google.api.gax.rpc.UnaryCallable;
2831
import com.google.cloud.location.GetLocationRequest;
2932
import com.google.cloud.location.ListLocationsRequest;
@@ -38,6 +41,7 @@
3841
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStub;
3942
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStubSettings;
4043
import java.io.IOException;
44+
import java.io.InputStream;
4145
import java.util.List;
4246
import java.util.concurrent.TimeUnit;
4347
import javax.annotation.Generated;
@@ -59,8 +63,8 @@
5963
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
6064
* try (ResumableUploadServiceClient resumableUploadServiceClient =
6165
* ResumableUploadServiceClient.create()) {
62-
* UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
63-
* UploadMediaResponse response = resumableUploadServiceClient.uploadMedia(request);
66+
* GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
67+
* Location response = resumableUploadServiceClient.getLocation(request);
6468
* }
6569
* }</pre>
6670
*
@@ -81,7 +85,7 @@
8185
* <td>
8286
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
8387
* <ul>
84-
* <li><p> uploadMedia(UploadMediaRequest request)
88+
* <li><p> uploadMedia(UploadMediaRequest request, InputStream payload)
8589
* </ul>
8690
* <p>Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.</p>
8791
* <ul>
@@ -277,51 +281,29 @@ public ResumableUploadServiceStub getStub() {
277281
/**
278282
* A method with media_upload annotation enabled.
279283
*
280-
* <p>Sample code:
281-
*
282-
* <pre>{@code
283-
* // This snippet has been automatically generated and should be regarded as a code template only.
284-
* // It will require modifications to work:
285-
* // - It may require correct/in-range values for request initialization.
286-
* // - It may require specifying regional endpoints when creating the service client as shown in
287-
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
288-
* try (ResumableUploadServiceClient resumableUploadServiceClient =
289-
* ResumableUploadServiceClient.create()) {
290-
* UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
291-
* UploadMediaResponse response = resumableUploadServiceClient.uploadMedia(request);
292-
* }
293-
* }</pre>
284+
* <p>Call context overrides (such as withTimeout, withRetrySettings, or credentials) apply
285+
* strictly to the start request (session initiation). Per-chunk PUT calls rely on the configured
286+
* timeout and retry settings from ResumableUploadCallSettings.
294287
*
295288
* @param request The request object containing all of the parameters for the API call.
289+
* @param payload The payload data stream to upload.
296290
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
297291
*/
298-
public final UploadMediaResponse uploadMedia(UploadMediaRequest request) {
299-
return uploadMediaCallable().call(request);
292+
public final UploadMediaResponse uploadMedia(UploadMediaRequest request, InputStream payload) {
293+
return ApiExceptions.callAndTranslateApiException(
294+
uploadMediaCallable().futureCall(request, payload, ((ResumableUploadCallSettings) null)));
300295
}
301296

302297
// AUTO-GENERATED DOCUMENTATION AND METHOD.
303298
/**
304299
* A method with media_upload annotation enabled.
305300
*
306-
* <p>Sample code:
307-
*
308-
* <pre>{@code
309-
* // This snippet has been automatically generated and should be regarded as a code template only.
310-
* // It will require modifications to work:
311-
* // - It may require correct/in-range values for request initialization.
312-
* // - It may require specifying regional endpoints when creating the service client as shown in
313-
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
314-
* try (ResumableUploadServiceClient resumableUploadServiceClient =
315-
* ResumableUploadServiceClient.create()) {
316-
* UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
317-
* ApiFuture<UploadMediaResponse> future =
318-
* resumableUploadServiceClient.uploadMediaCallable().futureCall(request);
319-
* // Do something.
320-
* UploadMediaResponse response = future.get();
321-
* }
322-
* }</pre>
301+
* <p>Call context overrides (such as withTimeout, withRetrySettings, or credentials) apply
302+
* strictly to the start request (session initiation). Per-chunk PUT calls rely on the configured
303+
* timeout and retry settings from ResumableUploadCallSettings.
323304
*/
324-
public final UnaryCallable<UploadMediaRequest, UploadMediaResponse> uploadMediaCallable() {
305+
public final ResumableUploadCallable<UploadMediaRequest, UploadMediaResponse>
306+
uploadMediaCallable() {
325307
return stub.uploadMediaCallable();
326308
}
327309

java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/ResumableUploadServiceSettings.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.google.api.gax.rpc.ClientContext;
2929
import com.google.api.gax.rpc.ClientSettings;
3030
import com.google.api.gax.rpc.PagedCallSettings;
31+
import com.google.api.gax.rpc.ResumableUploadCallSettings;
3132
import com.google.api.gax.rpc.TransportChannelProvider;
3233
import com.google.api.gax.rpc.UnaryCallSettings;
3334
import com.google.cloud.location.GetLocationRequest;
@@ -63,7 +64,7 @@
6364
*
6465
* <p>For example, to set the
6566
* [RetrySettings](https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.retrying.RetrySettings)
66-
* of uploadMedia:
67+
* of getLocation:
6768
*
6869
* <pre>{@code
6970
* // This snippet has been automatically generated and should be regarded as a code template only.
@@ -74,10 +75,10 @@
7475
* ResumableUploadServiceSettings.Builder resumableUploadServiceSettingsBuilder =
7576
* ResumableUploadServiceSettings.newBuilder();
7677
* resumableUploadServiceSettingsBuilder
77-
* .uploadMediaSettings()
78+
* .getLocationSettings()
7879
* .setRetrySettings(
7980
* resumableUploadServiceSettingsBuilder
80-
* .uploadMediaSettings()
81+
* .getLocationSettings()
8182
* .getRetrySettings()
8283
* .toBuilder()
8384
* .setInitialRetryDelayDuration(Duration.ofSeconds(1))
@@ -102,8 +103,13 @@
102103
@Generated("by gapic-generator-java")
103104
public class ResumableUploadServiceSettings extends ClientSettings<ResumableUploadServiceSettings> {
104105

105-
/** Returns the object with the settings used for calls to uploadMedia. */
106-
public UnaryCallSettings<UploadMediaRequest, UploadMediaResponse> uploadMediaSettings() {
106+
/**
107+
* Returns the object with the settings used for calls to uploadMedia.
108+
*
109+
* <p>Note that the settings configured here apply strictly to the initial session initiation
110+
* request, and not to the subsequent data transfer requests.
111+
*/
112+
public ResumableUploadCallSettings uploadMediaSettings() {
107113
return ((ResumableUploadServiceStubSettings) getStubSettings()).uploadMediaSettings();
108114
}
109115

@@ -247,9 +253,13 @@ public Builder applyToAllUnaryMethods(
247253
return this;
248254
}
249255

250-
/** Returns the builder for the settings used for calls to uploadMedia. */
251-
public UnaryCallSettings.Builder<UploadMediaRequest, UploadMediaResponse>
252-
uploadMediaSettings() {
256+
/**
257+
* Returns the builder for the settings used for calls to uploadMedia.
258+
*
259+
* <p>Note that the settings configured here apply strictly to the initial session initiation
260+
* request, and not to the subsequent data transfer requests.
261+
*/
262+
public ResumableUploadCallSettings.Builder uploadMediaSettings() {
253263
return getStubSettingsBuilder().uploadMediaSettings();
254264
}
255265

java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/package-info.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@
137137
* // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
138138
* try (ResumableUploadServiceClient resumableUploadServiceClient =
139139
* ResumableUploadServiceClient.create()) {
140-
* UploadMediaRequest request = UploadMediaRequest.newBuilder().setName("name3373707").build();
141-
* UploadMediaResponse response = resumableUploadServiceClient.uploadMedia(request);
140+
* GetLocationRequest request = GetLocationRequest.newBuilder().setName("name3373707").build();
141+
* Location response = resumableUploadServiceClient.getLocation(request);
142142
* }
143143
* }</pre>
144144
*

java-showcase/gapic-showcase/src/main/java/com/google/showcase/v1beta1/stub/GrpcResumableUploadServiceStub.java

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@
2222
import com.google.api.gax.core.BackgroundResource;
2323
import com.google.api.gax.core.BackgroundResourceAggregation;
2424
import com.google.api.gax.grpc.GrpcCallSettings;
25+
import com.google.api.gax.grpc.GrpcStatusCode;
2526
import com.google.api.gax.grpc.GrpcStubCallableFactory;
2627
import com.google.api.gax.rpc.ClientContext;
28+
import com.google.api.gax.rpc.FailedPreconditionException;
2729
import com.google.api.gax.rpc.RequestParamsBuilder;
30+
import com.google.api.gax.rpc.ResumableUploadCallable;
2831
import com.google.api.gax.rpc.UnaryCallable;
2932
import com.google.cloud.location.GetLocationRequest;
3033
import com.google.cloud.location.ListLocationsRequest;
3134
import com.google.cloud.location.ListLocationsResponse;
3235
import com.google.cloud.location.Location;
36+
import com.google.common.collect.ImmutableList;
3337
import com.google.iam.v1.GetIamPolicyRequest;
3438
import com.google.iam.v1.Policy;
3539
import com.google.iam.v1.SetIamPolicyRequest;
@@ -39,11 +43,13 @@
3943
import com.google.showcase.v1beta1.UploadMediaRequest;
4044
import com.google.showcase.v1beta1.UploadMediaResponse;
4145
import io.grpc.MethodDescriptor;
46+
import io.grpc.Status;
4247
import io.grpc.protobuf.ProtoUtils;
4348
import java.io.IOException;
4449
import java.util.concurrent.TimeUnit;
4550
import javax.annotation.Generated;
4651
import org.jspecify.annotations.NullMarked;
52+
import org.jspecify.annotations.Nullable;
4753

4854
// AUTO-GENERATED DOCUMENTATION AND CLASS.
4955
/**
@@ -55,17 +61,6 @@
5561
@BetaApi
5662
@Generated("by gapic-generator-java")
5763
public 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

Comments
 (0)