Skip to content

Commit 20fc1f5

Browse files
author
Paultagoras
committed
Tweaks to add example and allow port setting without protocol
1 parent 72aa103 commit 20fc1f5

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public Builder() {
235235

236236
/**
237237
* Builds a client object with the provided configuration through URL parameters.
238-
*
238+
* (e.g. http://localhost:8123/someDatabase?user=default)
239239
* @param urlString - URL formatted string with protocol, host, port, and client configuration settings.
240240
* @return Client - a client object
241241
*/
@@ -253,10 +253,9 @@ public Builder fromUrl(String urlString) {
253253
this.addEndpoint(Protocol.HTTP, url.getHost(), port, secure);
254254

255255
for (ClientConfigProperties properties: ClientConfigProperties.values()) {
256-
String key = properties.getKey().replace(ClientConfigProperties.SERVER_SETTING_PREFIX, "");//People wouldn't pass with prefix
257-
String value = urlProperties.get(key);
256+
String value = urlProperties.get(properties.getKey());
258257
if (value != null) {
259-
this.configuration.put(properties.getKey(), value);//We need to keep the original key
258+
this.configuration.put(properties.getKey(), value);
260259
}
261260
}
262261

jdbc-v2/src/main/java/com/clickhouse/jdbc/internal/JdbcConfiguration.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.clickhouse.jdbc.internal;
22

3+
import com.clickhouse.client.api.http.ClickHouseHttpProto;
4+
35
import java.net.MalformedURLException;
46
import java.net.URL;
57
import java.sql.DriverPropertyInfo;
@@ -58,7 +60,15 @@ public static boolean acceptsURL(String url) {
5860
private String cleanUrl(String url) {
5961
url = stripUrlPrefix(url);
6062
if (url.startsWith("//")) {
61-
url = "http:" + url;
63+
url = "http:" + url;//Default to HTTP
64+
try {
65+
URL parsedUrl = new URL(url);
66+
if (parsedUrl.getPort() == ClickHouseHttpProto.DEFAULT_HTTPS_PORT) {//If port is 8443, switch to HTTPS
67+
url = "https:" + url;
68+
}
69+
} catch (MalformedURLException e) {
70+
throw new IllegalArgumentException("URL is not valid.", e);
71+
}
6272
}
6373

6474
return url;

0 commit comments

Comments
 (0)