-
Notifications
You must be signed in to change notification settings - Fork 1.2k
POC Option 1B: Specialized REST Upload Stub #13919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
847c892
81f5945
4ae9e0c
b074deb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.showcase.v1beta1.stub; | ||
|
|
||
| import com.google.api.core.BetaApi; | ||
| import com.google.api.gax.core.BackgroundResource; | ||
| import com.google.api.gax.core.BackgroundResourceAggregation; | ||
| import com.google.api.gax.httpjson.ApiMethodDescriptor; | ||
| import com.google.api.gax.httpjson.HttpJsonCallSettings; | ||
| import com.google.api.gax.httpjson.HttpJsonCallableFactory; | ||
| import com.google.api.gax.httpjson.ProtoMessageRequestFormatter; | ||
| import com.google.api.gax.httpjson.ProtoMessageResponseParser; | ||
| import com.google.api.gax.rpc.ClientContext; | ||
| import com.google.api.gax.rpc.ResumableUploadCallable; | ||
| import com.google.showcase.v1beta1.EchoRequest; | ||
| import com.google.showcase.v1beta1.EchoResponse; | ||
| import java.io.IOException; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.concurrent.TimeUnit; | ||
| import javax.annotation.Generated; | ||
|
|
||
| // AUTO-GENERATED DOCUMENTATION AND CLASS. | ||
| /** | ||
| * REST stub implementation for resumable uploads in the Echo service API. | ||
| * | ||
| * <p>This stub contains only the Scotty resumable upload RPCs and is meant to be instantiated | ||
| * inside both the standard gRPC and HTTP/JSON stubs without incurring the overhead of | ||
| * loading all standard RPC callables. | ||
| */ | ||
| @BetaApi | ||
| @Generated("by gapic-generator-java") | ||
| public class HttpJsonEchoResumableUploadStub extends EchoStub { | ||
| private static final ApiMethodDescriptor<EchoRequest, EchoResponse> | ||
| echoResumableUploadMethodDescriptor = | ||
| ApiMethodDescriptor.<EchoRequest, EchoResponse>newBuilder() | ||
| .setFullMethodName("google.showcase.v1beta1.Echo/EchoResumableUpload") | ||
| .setHttpMethod("POST") | ||
| .setType(ApiMethodDescriptor.MethodType.UNARY) | ||
| .setRequestFormatter( | ||
| ProtoMessageRequestFormatter.<EchoRequest>newBuilder() | ||
| .setPath("/v1beta1/echo:resumable", request -> new HashMap<>()) | ||
| .build()) | ||
| .setResponseParser( | ||
| ProtoMessageResponseParser.<EchoResponse>newBuilder() | ||
| .setDefaultInstance(EchoResponse.getDefaultInstance()) | ||
| .build()) | ||
| .build(); | ||
|
|
||
| private final ResumableUploadCallable<EchoRequest, EchoResponse> resumableUploadCallable; | ||
| private final BackgroundResource backgroundResources; | ||
|
|
||
| public static final HttpJsonEchoResumableUploadStub create( | ||
| EchoStubSettings settings, ClientContext clientContext) throws IOException { | ||
| return new HttpJsonEchoResumableUploadStub(settings, clientContext); | ||
| } | ||
|
|
||
| protected HttpJsonEchoResumableUploadStub(EchoStubSettings settings, ClientContext clientContext) | ||
| throws IOException { | ||
| this.backgroundResources = | ||
| new BackgroundResourceAggregation( | ||
| Collections.singletonList(clientContext.getTransportChannel())); | ||
|
|
||
| HttpJsonCallSettings<EchoRequest, EchoResponse> resumableUploadTransportSettings = | ||
| HttpJsonCallSettings.<EchoRequest, EchoResponse>newBuilder() | ||
| .setMethodDescriptor(echoResumableUploadMethodDescriptor) | ||
| .build(); | ||
| this.resumableUploadCallable = | ||
| HttpJsonCallableFactory.createResumableUploadCallable( | ||
| resumableUploadTransportSettings, clientContext); | ||
| } | ||
|
|
||
| @Override | ||
| public ResumableUploadCallable<EchoRequest, EchoResponse> resumableUploadCallable() { | ||
| return resumableUploadCallable; | ||
| } | ||
|
|
||
| @Override | ||
| public final void close() { | ||
| try { | ||
| backgroundResources.close(); | ||
| } catch (RuntimeException e) { | ||
| throw e; | ||
| } catch (Exception e) { | ||
| throw new IllegalStateException("Failed to close resource", e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void shutdown() { | ||
| backgroundResources.shutdown(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isShutdown() { | ||
| return backgroundResources.isShutdown(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isTerminated() { | ||
| return backgroundResources.isTerminated(); | ||
| } | ||
|
|
||
| @Override | ||
| public void shutdownNow() { | ||
| backgroundResources.shutdownNow(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { | ||
| return backgroundResources.awaitTermination(duration, unit); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| import com.google.api.gax.rpc.ClientStreamingCallable; | ||
| import com.google.api.gax.rpc.OperationCallable; | ||
| import com.google.api.gax.rpc.RequestParamsBuilder; | ||
| import com.google.api.gax.rpc.ResumableUploadCallable; | ||
| import com.google.api.gax.rpc.ServerStreamingCallable; | ||
| import com.google.api.gax.rpc.UnaryCallable; | ||
| import com.google.api.pathtemplate.PathTemplate; | ||
|
|
@@ -611,6 +612,7 @@ public class HttpJsonEchoStub extends EchoStub { | |
| private final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable; | ||
| private final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse> | ||
| testIamPermissionsCallable; | ||
| private final HttpJsonEchoResumableUploadStub uploadStub; | ||
|
|
||
| private final BackgroundResource backgroundResources; | ||
| private final HttpJsonOperationsStub httpJsonOperationsStub; | ||
|
|
@@ -886,6 +888,8 @@ protected HttpJsonEchoStub( | |
| settings.testIamPermissionsSettings(), | ||
| clientContext); | ||
|
|
||
| this.uploadStub = HttpJsonEchoResumableUploadStub.create(settings, clientContext); | ||
|
|
||
| this.backgroundResources = | ||
| new BackgroundResourceAggregation(clientContext.getBackgroundResources()); | ||
| } | ||
|
|
@@ -1010,6 +1014,11 @@ public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() { | |
| return testIamPermissionsCallable; | ||
| } | ||
|
|
||
| @Override | ||
| public ResumableUploadCallable<EchoRequest, EchoResponse> resumableUploadCallable() { | ||
| return uploadStub.resumableUploadCallable(); | ||
| } | ||
|
|
||
| @Override | ||
| public ClientStreamingCallable<EchoRequest, EchoResponse> collectCallable() { | ||
| throw new UnsupportedOperationException( | ||
|
|
@@ -1027,6 +1036,9 @@ public BidiStreamingCallable<EchoRequest, EchoResponse> chatCallable() { | |
| public final void close() { | ||
| try { | ||
| backgroundResources.close(); | ||
| if (uploadStub != null) { | ||
| uploadStub.close(); | ||
| } | ||
| } catch (RuntimeException e) { | ||
| throw e; | ||
| } catch (Exception e) { | ||
|
Comment on lines
1036
to
1044
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
public final void close() {
try {
backgroundResources.close();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IllegalStateException("Failed to close resource", e);
} |
||
|
|
@@ -1037,6 +1049,9 @@ public final void close() { | |
| @Override | ||
| public void shutdown() { | ||
| backgroundResources.shutdown(); | ||
| if (uploadStub != null) { | ||
| uploadStub.shutdown(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GrpcEchoStubonly initializesuploadStubifclientContext.getCredentials() != null, whereasHttpJsonEchoStubinitializes it unconditionally. This prevents using resumable uploads in local testing or emulator environments where credentials are null. We should initializeuploadStubunconditionally.