@@ -50,30 +50,44 @@ public boolean isDisableFrameworkDetection() {
5050 }
5151
5252 public JdbcConfiguration (String url , Properties info ) {
53+ this .allProperties = new ConcurrentHashMap <>();
54+ info .forEach ((k , v ) -> allProperties .put (k .toString (), v .toString ()));
55+
5356 this .jdbcUrl = url ;//Raw URL
5457 this .url = cleanUrl (url );
5558 this .user = info .getProperty ("user" , "default" );
5659 this .password = info .getProperty ("password" , "" );
5760 this .disableFrameworkDetection = Boolean .parseBoolean (info .getProperty ("disable_frameworks_detection" , "false" ));
58- this .allProperties = new ConcurrentHashMap <>();
59- info .forEach ((k , v ) -> allProperties .put (k .toString (), v .toString ()));
6061 }
6162
6263 public static boolean acceptsURL (String url ) {
6364 return url .startsWith (PREFIX_CLICKHOUSE ) || url .startsWith (PREFIX_CLICKHOUSE_SHORT );
6465 }
6566
66- private String cleanUrl (String url ) {
67+ protected String cleanUrl (String url ) {
6768 url = stripUrlPrefix (url );
69+ boolean setSSL = false ;
70+ boolean ssl = false ;
71+ try {
72+ ssl = Boolean .parseBoolean (allProperties .get ("ssl" ));
73+ setSSL = true ;
74+ } catch (Exception e ) {
75+ log .trace ("Failed to parse SSL property." , e );
76+ }
77+
6878 if (url .startsWith ("//" )) {
69- url = "http:" + url ;//Default to HTTP
70- try {
71- URL parsedUrl = new URL (url );
72- if (parsedUrl .getPort () == ClickHouseHttpProto .DEFAULT_HTTPS_PORT ) {//If port is 8443, switch to HTTPS
73- url = "https:" + url ;
79+ if (setSSL ) {
80+ url = (ssl ? "https:" : "http:" ) + url ;
81+ } else {
82+ url = "http:" + url ;//Default to HTTP
83+ try {
84+ URL parsedUrl = new URL (url );
85+ if (parsedUrl .getPort () == ClickHouseHttpProto .DEFAULT_HTTPS_PORT ) {//If port is 8443, switch to HTTPS
86+ url = "https:" + url .substring (5 );
87+ }
88+ } catch (MalformedURLException e ) {
89+ throw new IllegalArgumentException ("URL is not valid." , e );
7490 }
75- } catch (MalformedURLException e ) {
76- throw new IllegalArgumentException ("URL is not valid." , e );
7791 }
7892 }
7993
0 commit comments