@@ -104,6 +104,9 @@ public abstract class ClientContext {
104
104
@ Nullable
105
105
abstract String getServiceName ();
106
106
107
+ @ Nullable
108
+ public abstract String getUniverseDomain ();
109
+
107
110
@ Nullable
108
111
public abstract String getEndpoint ();
109
112
@@ -157,15 +160,28 @@ public static ClientContext create(StubSettings settings) throws IOException {
157
160
final ScheduledExecutorService backgroundExecutor = backgroundExecutorProvider .getExecutor ();
158
161
159
162
Credentials credentials = settings .getCredentialsProvider ().getCredentials ();
163
+ boolean usingGDCH = credentials instanceof GdchCredentials ;
164
+ EndpointContext endpointContext =
165
+ EndpointContext .newBuilder ()
166
+ .setServiceName (settings .getServiceName ())
167
+ .setUniverseDomain (settings .getUniverseDomain ())
168
+ .setClientSettingsEndpoint (settings .getEndpoint ())
169
+ .setTransportChannelProviderEndpoint (
170
+ settings .getTransportChannelProvider ().getEndpoint ())
171
+ .setMtlsEndpoint (settings .getMtlsEndpoint ())
172
+ .setSwitchToMtlsEndpointAllowed (settings .getSwitchToMtlsEndpointAllowed ())
173
+ .setUsingGDCH (usingGDCH )
174
+ .build ();
175
+ String endpoint = endpointContext .resolvedEndpoint ();
160
176
161
177
String settingsGdchApiAudience = settings .getGdchApiAudience ();
162
- if (credentials instanceof GdchCredentials ) {
178
+ if (usingGDCH ) {
163
179
// We recompute the GdchCredentials with the audience
164
180
String audienceString ;
165
181
if (!Strings .isNullOrEmpty (settingsGdchApiAudience )) {
166
182
audienceString = settingsGdchApiAudience ;
167
- } else if (!Strings .isNullOrEmpty (settings . getEndpoint () )) {
168
- audienceString = settings . getEndpoint () ;
183
+ } else if (!Strings .isNullOrEmpty (endpoint )) {
184
+ audienceString = endpoint ;
169
185
} else {
170
186
throw new IllegalArgumentException ("Could not infer GDCH api audience from settings" );
171
187
}
@@ -204,16 +220,6 @@ public static ClientContext create(StubSettings settings) throws IOException {
204
220
if (transportChannelProvider .needsCredentials () && credentials != null ) {
205
221
transportChannelProvider = transportChannelProvider .withCredentials (credentials );
206
222
}
207
- EndpointContext endpointContext =
208
- EndpointContext .newBuilder ()
209
- .setServiceName (settings .getServiceName ())
210
- .setClientSettingsEndpoint (settings .getEndpoint ())
211
- .setTransportChannelProviderEndpoint (
212
- settings .getTransportChannelProvider ().getEndpoint ())
213
- .setMtlsEndpoint (settings .getMtlsEndpoint ())
214
- .setSwitchToMtlsEndpointAllowed (settings .getSwitchToMtlsEndpointAllowed ())
215
- .build ();
216
- String endpoint = endpointContext .getResolvedEndpoint ();
217
223
if (transportChannelProvider .needsEndpoint ()) {
218
224
transportChannelProvider = transportChannelProvider .withEndpoint (endpoint );
219
225
}
@@ -264,6 +270,7 @@ public static ClientContext create(StubSettings settings) throws IOException {
264
270
.setClock (clock )
265
271
.setDefaultCallContext (defaultCallContext )
266
272
.setServiceName (settings .getServiceName ())
273
+ .setUniverseDomain (settings .getUniverseDomain ())
267
274
.setEndpoint (settings .getEndpoint ())
268
275
.setQuotaProjectId (settings .getQuotaProjectId ())
269
276
.setStreamWatchdog (watchdog )
@@ -332,6 +339,8 @@ public abstract static class Builder {
332
339
// Package-Private scope for internal use only. Shared between StubSettings and ClientContext
333
340
abstract Builder setServiceName (String serviceName );
334
341
342
+ public abstract Builder setUniverseDomain (String universeDomain );
343
+
335
344
public abstract Builder setEndpoint (String endpoint );
336
345
337
346
public abstract Builder setQuotaProjectId (String QuotaProjectId );
0 commit comments