diff --git a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java index 3471796d2846..1e2c2a90ba39 100644 --- a/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java +++ b/pinot-clients/pinot-java-client/src/main/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportFactory.java @@ -85,9 +85,9 @@ public JsonAsyncHttpPinotClientTransportFactory withConnectionProperties(Propert _headers = ConnectionUtils.getHeadersFromProperties(properties); } - String scheme = properties.getProperty("scheme", CommonConstants.HTTP_PROTOCOL); - if (_scheme == null || !_scheme.contentEquals(scheme)) { - _scheme = scheme; + _scheme = properties.getProperty("scheme", _scheme); + if (_scheme == null) { + _scheme = CommonConstants.HTTP_PROTOCOL; } if (_sslContext == null && _scheme.contentEquals(CommonConstants.HTTPS_PROTOCOL)) { diff --git a/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportTest.java b/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportTest.java index a211cdf8b761..bb6058c5a4a4 100644 --- a/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportTest.java +++ b/pinot-clients/pinot-java-client/src/test/java/org/apache/pinot/client/JsonAsyncHttpPinotClientTransportTest.java @@ -30,6 +30,7 @@ import java.util.Properties; import java.util.concurrent.CompletableFuture; import org.apache.commons.lang3.exception.ExceptionUtils; +import org.apache.pinot.spi.utils.CommonConstants; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -140,6 +141,38 @@ public void serverResponseExceedsBrokerReadTimeoutThreshold() { } } + @Test + public void withConnectionPropertiesRetainsConfiguredSchemeWhenSchemePropertyIsAbsent() { + JsonAsyncHttpPinotClientTransportFactory factory = new JsonAsyncHttpPinotClientTransportFactory(); + factory.setScheme(CommonConstants.HTTPS_PROTOCOL); + + factory.withConnectionProperties(new Properties()); + + assertEquals(factory.getScheme(), CommonConstants.HTTPS_PROTOCOL); + } + + @Test + public void withConnectionPropertiesOverridesConfiguredSchemeWhenSchemePropertyIsPresent() { + JsonAsyncHttpPinotClientTransportFactory factory = new JsonAsyncHttpPinotClientTransportFactory(); + factory.setScheme(CommonConstants.HTTP_PROTOCOL); + Properties connectionProps = new Properties(); + connectionProps.setProperty("scheme", CommonConstants.HTTPS_PROTOCOL); + + factory.withConnectionProperties(connectionProps); + + assertEquals(factory.getScheme(), CommonConstants.HTTPS_PROTOCOL); + } + + @Test + public void withConnectionPropertiesFallsBackToHttpWhenConfiguredSchemeIsNull() { + JsonAsyncHttpPinotClientTransportFactory factory = new JsonAsyncHttpPinotClientTransportFactory(); + factory.setScheme(null); + + factory.withConnectionProperties(new Properties()); + + assertEquals(factory.getScheme(), CommonConstants.HTTP_PROTOCOL); + } + // Cursor-related tests @Test public void testExecuteQueryWithCursor() {