@@ -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
@@ -1608,6 +1612,22 @@ public Builder useClientCert(String clientCertificate, String clientCertificateK
16081612 return this ;
16091613 }
16101614
1615+ /**
1616+ * {@code usePlainText} is only supported for experimental spanner hosts. This will configure
1617+ * the transport to use plaintext (no TLS) and will set credentials to {@link
1618+ * com.google.cloud.NoCredentials} to avoid sending authentication over an unsecured channel.
1619+ */
1620+ @ ExperimentalApi ("https://github.com/googleapis/java-spanner/pull/3574" )
1621+ public Builder usePlainText () {
1622+ this .setChannelConfigurator (ManagedChannelBuilder ::usePlaintext )
1623+ .setCredentials (NoCredentials .getInstance ());
1624+ if (this .experimentalHost != null && !this .experimentalHost .startsWith ("http" )) {
1625+ this .experimentalHost = "http://" + this .experimentalHost ;
1626+ super .setHost (this .experimentalHost );
1627+ }
1628+ return this ;
1629+ }
1630+
16111631 /**
16121632 * Sets OpenTelemetry object to be used for Spanner Metrics and Traces. GlobalOpenTelemetry will
16131633 * be used as fallback if this options is not set.
@@ -1783,7 +1803,7 @@ public SpannerOptions build() {
17831803 this .setChannelConfigurator (ManagedChannelBuilder ::usePlaintext );
17841804 // As we are using plain text, we should never send any credentials.
17851805 this .setCredentials (NoCredentials .getInstance ());
1786- } else if (isExperimentalHost && credentials == null ) {
1806+ } else if (experimentalHost != null && credentials == null ) {
17871807 credentials = environment .getDefaultExperimentalHostCredentials ();
17881808 }
17891809 if (this .numChannels == null ) {
0 commit comments