@@ -825,7 +825,7 @@ protected SpannerOptions(Builder builder) {
825825 openTelemetry = builder .openTelemetry ;
826826 enableApiTracing = builder .enableApiTracing ;
827827 enableExtendedTracing = builder .enableExtendedTracing ;
828- if (builder .isExperimentalHost ) {
828+ if (builder .experimentalHost != null ) {
829829 enableBuiltInMetrics = false ;
830830 } else {
831831 enableBuiltInMetrics = builder .enableBuiltInMetrics ;
@@ -1047,7 +1047,8 @@ public static class Builder
10471047 private boolean enableBuiltInMetrics = SpannerOptions .environment .isEnableBuiltInMetrics ();
10481048 private String monitoringHost = SpannerOptions .environment .getMonitoringHost ();
10491049 private SslContext mTLSContext = null ;
1050- private boolean isExperimentalHost = false ;
1050+ private String experimentalHost = null ;
1051+ private boolean usePlainText = false ;
10511052 private TransactionOptions defaultTransactionOptions = TransactionOptions .getDefaultInstance ();
10521053
10531054 private static String createCustomClientLibToken (String token ) {
@@ -1550,10 +1551,13 @@ public Builder setHost(String host) {
15501551
15511552 @ ExperimentalApi ("https://github.com/googleapis/java-spanner/pull/3676" )
15521553 public Builder setExperimentalHost (String host ) {
1554+ if (usePlainText && !host .startsWith ("http" )) {
1555+ host = "http://" + host ;
1556+ }
15531557 super .setHost (host );
15541558 super .setProjectId (EXPERIMENTAL_HOST_PROJECT_ID );
15551559 setSessionPoolOption (SessionPoolOptions .newBuilder ().setExperimentalHost ().build ());
1556- this . isExperimentalHost = true ;
1560+ experimentalHost = host ;
15571561 return this ;
15581562 }
15591563
@@ -1614,6 +1618,22 @@ public Builder useClientCert(String clientCertificate, String clientCertificateK
16141618 return this ;
16151619 }
16161620
1621+ /**
1622+ * {@code usePlainText} is only supported for experimental spanner hosts. This will configure
1623+ * the transport to use plaintext (no TLS) and will set credentials to {@link
1624+ * com.google.cloud.NoCredentials} to avoid sending authentication over an unsecured channel.
1625+ */
1626+ @ ExperimentalApi ("https://github.com/googleapis/java-spanner/pull/3574" )
1627+ public Builder usePlainText () {
1628+ this .setChannelConfigurator (ManagedChannelBuilder ::usePlaintext )
1629+ .setCredentials (NoCredentials .getInstance ());
1630+ if (this .experimentalHost != null && !this .experimentalHost .startsWith ("http" )) {
1631+ this .experimentalHost = "http://" + this .experimentalHost ;
1632+ super .setHost (this .experimentalHost );
1633+ }
1634+ return this ;
1635+ }
1636+
16171637 /**
16181638 * Sets OpenTelemetry object to be used for Spanner Metrics and Traces. GlobalOpenTelemetry will
16191639 * be used as fallback if this options is not set.
@@ -1789,7 +1809,7 @@ public SpannerOptions build() {
17891809 this .setChannelConfigurator (ManagedChannelBuilder ::usePlaintext );
17901810 // As we are using plain text, we should never send any credentials.
17911811 this .setCredentials (NoCredentials .getInstance ());
1792- } else if (isExperimentalHost && credentials == null ) {
1812+ } else if (experimentalHost != null && credentials == null ) {
17931813 credentials = environment .getDefaultExperimentalHostCredentials ();
17941814 }
17951815 if (this .numChannels == null ) {
0 commit comments