Skip to content

Commit 920e237

Browse files
committed
chore(showcase): synchronize showcase definitions and generate client
1 parent 8002f29 commit 920e237

12 files changed

Lines changed: 300 additions & 223 deletions

File tree

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

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
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.ResumableUploadCallable;
2729
import com.google.api.gax.rpc.UnaryCallable;
2830
import com.google.cloud.location.GetLocationRequest;
2931
import com.google.cloud.location.ListLocationsRequest;
@@ -38,6 +40,7 @@
3840
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStub;
3941
import com.google.showcase.v1beta1.stub.ResumableUploadServiceStubSettings;
4042
import java.io.IOException;
43+
import java.io.InputStream;
4144
import java.util.List;
4245
import java.util.concurrent.TimeUnit;
4346
import javax.annotation.Generated;
@@ -81,7 +84,7 @@
8184
* <td>
8285
* <p>Request object method variants only take one parameter, a request object, which must be constructed before the call.</p>
8386
* <ul>
84-
* <li><p> uploadMedia(UploadMediaRequest request)
87+
* <li><p> uploadMedia(UploadMediaRequest request, InputStream payload)
8588
* </ul>
8689
* <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>
8790
* <ul>
@@ -277,51 +280,29 @@ public ResumableUploadServiceStub getStub() {
277280
/**
278281
* A method with media_upload annotation enabled.
279282
*
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>
283+
* <p>Call context overrides (such as withTimeout, withRetrySettings, or credentials) apply
284+
* strictly to the start request (session initiation). Per-chunk PUT calls rely on the configured
285+
* timeout and retry settings from ResumableUploadCallSettings.
294286
*
295287
* @param request The request object containing all of the parameters for the API call.
288+
* @param payload The payload data stream to upload.
296289
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
297290
*/
298-
public final UploadMediaResponse uploadMedia(UploadMediaRequest request) {
299-
return uploadMediaCallable().call(request);
291+
public final UploadMediaResponse uploadMedia(UploadMediaRequest request, InputStream payload) {
292+
return ApiExceptions.callAndTranslateApiException(
293+
uploadMediaCallable().futureCall(request, payload));
300294
}
301295

302296
// AUTO-GENERATED DOCUMENTATION AND METHOD.
303297
/**
304298
* A method with media_upload annotation enabled.
305299
*
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>
300+
* <p>Call context overrides (such as withTimeout, withRetrySettings, or credentials) apply
301+
* strictly to the start request (session initiation). Per-chunk PUT calls rely on the configured
302+
* timeout and retry settings from ResumableUploadCallSettings.
323303
*/
324-
public final UnaryCallable<UploadMediaRequest, UploadMediaResponse> uploadMediaCallable() {
304+
public final ResumableUploadCallable<UploadMediaRequest, UploadMediaResponse>
305+
uploadMediaCallable() {
325306
return stub.uploadMediaCallable();
326307
}
327308

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

Lines changed: 15 additions & 5 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;
@@ -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 custom retry settings and headers configured via ApiCallContext apply strictly to
110+
* the initial session initiation request.
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 custom retry settings and headers configured via ApiCallContext apply strictly
260+
* to the initial session initiation request.
261+
*/
262+
public ResumableUploadCallSettings.Builder uploadMediaSettings() {
253263
return getStubSettingsBuilder().uploadMediaSettings();
254264
}
255265

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

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
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;
27+
import com.google.api.gax.httpjson.HttpJsonCallContext;
28+
import com.google.api.gax.httpjson.HttpJsonTransportChannel;
29+
import com.google.api.gax.httpjson.ManagedHttpJsonChannel;
2630
import com.google.api.gax.rpc.ClientContext;
31+
import com.google.api.gax.rpc.FailedPreconditionException;
2732
import com.google.api.gax.rpc.RequestParamsBuilder;
33+
import com.google.api.gax.rpc.ResumableUploadCallable;
2834
import com.google.api.gax.rpc.UnaryCallable;
2935
import com.google.cloud.location.GetLocationRequest;
3036
import com.google.cloud.location.ListLocationsRequest;
@@ -39,11 +45,14 @@
3945
import com.google.showcase.v1beta1.UploadMediaRequest;
4046
import com.google.showcase.v1beta1.UploadMediaResponse;
4147
import io.grpc.MethodDescriptor;
48+
import io.grpc.Status;
4249
import io.grpc.protobuf.ProtoUtils;
4350
import java.io.IOException;
51+
import java.util.Arrays;
4452
import java.util.concurrent.TimeUnit;
4553
import javax.annotation.Generated;
4654
import org.jspecify.annotations.NullMarked;
55+
import org.jspecify.annotations.Nullable;
4756

4857
// AUTO-GENERATED DOCUMENTATION AND CLASS.
4958
/**
@@ -55,17 +64,6 @@
5564
@BetaApi
5665
@Generated("by gapic-generator-java")
5766
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-
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

Comments
 (0)