GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [PROTOTYPE] add ClientContext.createWithTransport by whowes · Pull Request #14412 · googleapis/google-cloud-java

[PROTOTYPE] add ClientContext.createWithTransport #14412

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.

Sign up for GitHub

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

Closed
whowes wants to merge 1 commit into main from whowes/gax-client-context-create-with-transport

Uh oh!

There was an error while loading. Please reload this page.

Closed

[PROTOTYPE] add ClientContext.createWithTransport #14412

Changes from all commits
Commits
Show all changes
1 commit
Select commit
745269d
gax: add ClientContext.createWithTransport
whowes Sep 16, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

75 changes: 75 additions & 0 deletions 75 sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java
Show comments Show annotations
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.api.client.util.Strings;
import com.google.api.core.ApiClock;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.core.NanoClock;
import com.google.api.core.ObsoleteApi;
import com.google.api.gax.core.BackgroundResource;
Expand Down Expand Up @@ -292,6 +293,80 @@
.build();
}

/**
* Derives a {@link ClientContext} for a second transport from {@code parent}, replacing the
* transport channel, endpoint and internal headers and inheriting everything else.
*/
@InternalApi
public static ClientContext createWithTransport(
ClientContext parent,
String endpoint,
TransportChannelProvider transportChannelProvider,
HeaderProvider internalHeaderProvider)
throws IOException {
Credentials credentials = parent.getCredentials();
EndpointContext endpointContext = parent.getEndpointContext();

Map<String, String> internal = internalHeaderProvider.getHeaders();
Map<String, String> user = parent.getHeaders();
Map<String, String> conflictResolution = new HashMap<>();

for (String key : Sets.intersection(user.keySet(), internal.keySet())) {

Check warning on line 314 in sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Reduce the total number of break and continue statements in this loop to use at most one.

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AaCtQfNhb7eQSQL38fqj&open=AaCtQfNhb7eQSQL38fqj&pullRequest=14412
if ("user-agent".equals(key)) {
conflictResolution.put(key, user.get(key) + " " + internal.get(key));
continue;
}
if (QUOTA_PROJECT_ID_HEADER_KEY.equals(key) && parent.getQuotaProjectId() != null) {
continue;
}
throw new IllegalArgumentException("Header provider can't override the header: " + key);
}
if (parent.getQuotaProjectId() != null) {
conflictResolution.put(QUOTA_PROJECT_ID_HEADER_KEY, parent.getQuotaProjectId());
}

Map<String, String> effective = new HashMap<>();
effective.putAll(internal);
effective.putAll(user);
effective.putAll(conflictResolution);
Map<String, String> headers = appendCredentialTypeToHeaderIfPresent(effective, credentials);

TransportChannelProvider provider = transportChannelProvider;
if (provider.needsHeaders()) {
provider = provider.withHeaders(headers);
}
if (provider.needsCredentials() && credentials != null) {
provider = provider.withCredentials(credentials);
}
if (provider.needsEndpoint()) {
provider = provider.withEndpoint(endpoint);
}
provider = provider.withUseS2A(endpointContext.useS2A());
if (provider.needsMtlsEndpoint() && endpointContext.mtlsEndpoint() != null) {
provider = provider.withMtlsEndpoint(endpointContext.mtlsEndpoint());

Check warning on line 346 in sdk-platform-java/gax-java/gax/src/main/java/com/google/api/gax/rpc/ClientContext.java

View check run for this annotation

SonarQubeCloud / [gapic-generator-java-root] SonarCloud Code Analysis

Annotate the parameter with @javax.annotation.Nullable in method 'withMtlsEndpoint' declaration, or make sure that null can not be passed as argument.

See more on https://sonarcloud.io/project/issues?id=googleapis_google-cloud-java_showcase&issues=AaCtQfNhb7eQSQL38fqi&open=AaCtQfNhb7eQSQL38fqi&pullRequest=14412
}
TransportChannel channel = provider.getTransportChannel();

ApiCallContext defaultCallContext = channel.getEmptyCallContext().withTransportChannel(channel);
if (credentials != null) {
defaultCallContext = defaultCallContext.withCredentials(credentials);
}
defaultCallContext = defaultCallContext.withEndpointContext(endpointContext);
Comment thread
Comment on lines +344 to +354

This comment was marked as off-topic.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.


ImmutableList.Builder<BackgroundResource> backgroundResources = ImmutableList.builder();
if (provider.shouldAutoClose()) {
backgroundResources.add(channel);
}

return parent.toBuilder()
.setEndpoint(endpoint)
.setTransportChannel(channel)
.setInternalHeaders(ImmutableMap.copyOf(internal))
.setDefaultCallContext(defaultCallContext)
.setBackgroundResources(backgroundResources.build())
.build();
}

@VisibleForTesting
static ApiTracerFactory getApiTracerFactory(
StubSettings settings, EndpointContext endpointContext) {
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.