diff --git a/CHANGELOG.md b/CHANGELOG.md index 085cf89b9..10ee917f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.9.7 + +### Breaking changes +- [jdbc] Default port is not added anymore - now port should be explicitly set. Previously `http://localhost` was transformed to `http://localhost:8123`. +Parsing URL with standard tools is not stable because `URI.create()` doesn't guarantee correct port number parsing. +Implementing more complex logic for minor case would add even more complexity. (https://github.com/ClickHouse/clickhouse-java/issues/2753) + ## 0.9.6 Release is aimed to address potential security risk in one of the dependencies (see below). We strongly recommend to upgrade. diff --git a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java index 21d05a552..922931248 100644 --- a/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java +++ b/jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java @@ -2,7 +2,6 @@ import com.clickhouse.client.api.Client; import com.clickhouse.client.api.ClientConfigProperties; -import com.clickhouse.client.api.http.ClickHouseHttpProto; import com.clickhouse.data.ClickHouseDataType; import com.clickhouse.jdbc.Driver; import com.clickhouse.jdbc.DriverProperties; @@ -148,20 +147,14 @@ public String getConnectionUrl() { * @param ssl - if SSL protocol should be used * @return URL without JDBC prefix */ - private static String createConnectionURL(String url, boolean ssl) throws SQLException { + static String createConnectionURL(String url, boolean ssl) throws SQLException { String adjustedURL = ssl && url.startsWith("http://") ? "https://" + url.substring(7) : url; try { URI tmp = URI.create(adjustedURL); - String asciiString = tmp.toASCIIString(); - if (tmp.getPort() < 0) { - String port = ssl || adjustedURL.startsWith("https") - ? ":" + ClickHouseHttpProto.DEFAULT_HTTPS_PORT - : ":" + ClickHouseHttpProto.DEFAULT_HTTP_PORT; - asciiString += port; - } - return asciiString; + // URI may incorrectly parse port and logic based on port number is unstable. + return tmp.toASCIIString(); } catch (IllegalArgumentException iae) { throw new SQLException("Failed to parse URL '" + url + "'", iae); } diff --git a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java index a5a3e972f..bd4c5a0ce 100644 --- a/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java +++ b/jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcConfigurationTest.java @@ -2,7 +2,6 @@ import com.clickhouse.client.api.Client; import com.clickhouse.client.api.ClientConfigProperties; - import com.clickhouse.jdbc.DriverProperties; import org.testng.Assert; import org.testng.annotations.DataProvider; @@ -23,61 +22,59 @@ public class JdbcConfigurationTest { private static final JdbcConfigurationTestData[] VALID_URLs = new JdbcConfigurationTestData[] { - new JdbcConfigurationTestData("jdbc:ch://localhost"), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost"), - new JdbcConfigurationTestData("jdbc:clickhouse:http://localhost"), - new JdbcConfigurationTestData("jdbc:clickhouse:https://localhost") - .withExpectedConnectionURL("https://localhost:8443"), + new JdbcConfigurationTestData("jdbc:ch://localhost:8123") + .withExpectedConnectionURL("http://localhost:8123"), + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123") + .withExpectedConnectionURL("http://localhost:8123"), + new JdbcConfigurationTestData("jdbc:clickhouse:http://unknown-host.local:8443") + .withExpectedConnectionURL("http://unknown-host.local:8443"), + new JdbcConfigurationTestData("jdbc:clickhouse:http://localhost:8443") + .withExpectedConnectionURL("http://localhost:8443"), new JdbcConfigurationTestData("jdbc:clickhouse:https://localhost:8123") .withExpectedConnectionURL("https://localhost:8123"), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8443") .withAdditionalConnectionParameters( Map.of(JdbcConfiguration.USE_SSL_PROP, "true")) .withExpectedConnectionURL("https://localhost:8443"), // ssl should not be passed to client - new JdbcConfigurationTestData("jdbc:clickhouse://[::1]") + new JdbcConfigurationTestData("jdbc:clickhouse://[::1]:8123") .withExpectedConnectionURL("http://[::1]:8123"), new JdbcConfigurationTestData("jdbc:clickhouse://[::1]:8123") .withExpectedConnectionURL("http://[::1]:8123"), new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8443") .withExpectedConnectionURL("http://localhost:8443"), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/database") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/database") .withAdditionalExpectedClientProperties( Map.of("database", "database")), new JdbcConfigurationTestData("jdbc:clickhouse://localhost:42/database") .withExpectedConnectionURL("http://localhost:42") .withAdditionalExpectedClientProperties( Map.of("database", "database")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/data-base") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/data-base") .withAdditionalExpectedClientProperties( Map.of("database", "data-base")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/data%20base") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/data%20base") .withAdditionalExpectedClientProperties( Map.of("database", "data base")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/data%2Fbase") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/data%2Fbase") .withAdditionalExpectedClientProperties( Map.of("database", "data/base")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/☺") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/☺") .withAdditionalExpectedClientProperties( Map.of("database", "☺")), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?custom_key1=val1&custom_key2=val2") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/db?custom_key1=val1&custom_key2=val2") .withAdditionalExpectedClientProperties( Map.of( "database", "db", "custom_key1", "val1", "custom_key2", "val2" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/db?custom_key1=val%201") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/db?custom_key1=val%201") .withAdditionalExpectedClientProperties( Map.of( "database", "db", "custom_key1", "val 1" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost/?custom_key1=val1") - .withAdditionalExpectedClientProperties( - Map.of( - "custom_key1", "val1" - )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=val1") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123/?custom_key1=val1") .withAdditionalExpectedClientProperties( Map.of( "custom_key1", "val1" @@ -94,12 +91,12 @@ public class JdbcConfigurationTest { Map.of( "custom_key1", "val1" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=☺") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123?custom_key1=☺") .withAdditionalExpectedClientProperties( Map.of( "custom_key1", "☺" )), - new JdbcConfigurationTestData("jdbc:clickhouse://localhost?custom_key1=val1,val2") + new JdbcConfigurationTestData("jdbc:clickhouse://localhost:8123?custom_key1=val1,val2") .withAdditionalExpectedClientProperties( Map.of( "custom_key1", "val1,val2"