33import com .clickhouse .client .ClickHouseNode ;
44import com .clickhouse .client .api .Client ;
55import com .clickhouse .client .api .ClientConfigProperties ;
6+ import com .clickhouse .client .api .enums .Protocol ;
67import com .clickhouse .client .api .http .ClickHouseHttpProto ;
78import com .clickhouse .data .ClickHouseUtils ;
89import com .clickhouse .jdbc .Driver ;
910
1011import java .net .MalformedURLException ;
12+ import java .net .URI ;
1113import java .net .URL ;
1214import java .sql .DriverPropertyInfo ;
15+ import java .sql .SQLException ;
1316import java .util .ArrayList ;
1417import java .util .Collections ;
1518import java .util .Comparator ;
@@ -23,6 +26,8 @@ public class JdbcConfiguration {
2326 public static final String PREFIX_CLICKHOUSE = "jdbc:clickhouse:" ;
2427 public static final String PREFIX_CLICKHOUSE_SHORT = "jdbc:ch:" ;
2528
29+ public static final String USE_SSL_PROP = "ssl" ;
30+
2631 final boolean disableFrameworkDetection ;
2732
2833 private final Map <String , String > clientProperties ;
@@ -41,12 +46,14 @@ public boolean isDisableFrameworkDetection() {
4146 * @param url - JDBC url
4247 * @param info - Driver and Client properties.
4348 */
44- public JdbcConfiguration (String url , Properties info ) {
45- this .connectionUrl = cleanUrl (url );
49+ public JdbcConfiguration (String url , Properties info ) throws SQLException {
4650 this .disableFrameworkDetection = Boolean .parseBoolean (info .getProperty ("disable_frameworks_detection" , "false" ));
4751 this .clientProperties = new HashMap <>();
4852 this .driverProperties = new HashMap <>();
49- initProperties (this .connectionUrl , info );
53+ initProperties (url , info );
54+
55+ boolean useSSL = Boolean .parseBoolean (info .getProperty ("ssl" , "false" ));
56+ this .connectionUrl = createConnectionURL (url , useSSL );
5057 }
5158
5259 public static boolean acceptsURL (String url ) {
@@ -59,20 +66,30 @@ public String getConnectionUrl() {
5966 }
6067
6168 /**
62- * Transforms JDBC URL to WEB network. Method doesn't do guessing .
63- * If protocol is not set - then {@code https} used by default .
64- * User can always pass any protocol explicitly what is always should be encouraged.
69+ * Returns normalized URL that can be passed as parameter to Client#addEndpoint() .
70+ * Returned url has only schema and authority and doesn't have query parameters .
71+ * Note: Some BI tools do not let pass
6572 * @param url - JDBC url
73+ * @param ssl - if SSL protocol should be used when protocol is not specified
6674 * @return URL without JDBC prefix
6775 */
68- protected String cleanUrl (String url ) {
76+ static String createConnectionURL (String url , boolean ssl ) throws SQLException {
6977 url = stripUrlPrefix (url );
7078 if (url .startsWith ("//" )) {
71- url = "https:" + url ;
79+ url = (ssl ? "https:" : "http:" ) + url ;
80+ }
81+
82+ try {
83+ System .out .println (url );
84+ URI tmp = URI .create (url );
85+ System .out .println (tmp );
86+ return tmp .getScheme () + "://" + tmp .getAuthority () + tmp .getPath ();
87+ } catch (Exception e ) {
88+ throw new SQLException ("Failed to parse url" , e );
7289 }
73- return url ;
7490 }
75- private String stripUrlPrefix (String url ) {
91+
92+ private static String stripUrlPrefix (String url ) {
7693 if (url .startsWith (PREFIX_CLICKHOUSE )) {
7794 return url .substring (PREFIX_CLICKHOUSE .length ());
7895 } else if (url .startsWith (PREFIX_CLICKHOUSE_SHORT )) {
0 commit comments