diff --git a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java index 9384e7823d..985fac4804 100644 --- a/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java +++ b/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java @@ -851,17 +851,24 @@ public String getResolvedHost(String serviceName) { } /** - * Temporarily used for BigQuery and Storage Apiary Wrapped Libraries. To be removed in the future - * when Apiary clients can resolve their endpoints. Returns the host to be used as the rootUrl. + * Returns a host value to be used for BigQuery and Storage Apiary Wrapped Libraries. To be + * removed in the future when Apiary clients can resolve their endpoints. Returns the host to be + * used as the rootUrl. * *
The resolved host will be in `https://{serviceName}.{resolvedUniverseDomain}/` format. The * resolvedUniverseDomain will be set to `googleapis.com` if universeDomain is null. * + *
The host value is set to DEFAULT_HOST if the user didn't configure a host. Returns the host + * value the user set, otherwise constructs the host for the user. + * * @see rootUrl */ @InternalApi public String getResolvedApiaryHost(String serviceName) { + if (!DEFAULT_HOST.equals(host)) { + return host; + } String resolvedUniverseDomain = universeDomain != null ? universeDomain : Credentials.GOOGLE_DEFAULT_UNIVERSE; return "https://" + serviceName + "." + resolvedUniverseDomain + "/"; diff --git a/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java b/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java index 3d5ca3eef5..1b79e48ddc 100644 --- a/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java +++ b/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java @@ -566,10 +566,10 @@ public void testGetResolvedApiaryHost_customUniverseDomain_customHost() { TestServiceOptions options = TestServiceOptions.newBuilder() .setUniverseDomain("test.com") - .setHost("https://service.random.com") + .setHost("https://service.random.com/") .setProjectId("project-id") .build(); - assertThat(options.getResolvedApiaryHost("service")).isEqualTo("https://service.test.com/"); + assertThat(options.getResolvedApiaryHost("service")).isEqualTo("https://service.random.com/"); } // No User Configuration = GDU, Default Credentials = GDU