From db965ed3136e0d3ccc24f15d09352c19d76747ab Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Tue, 25 Apr 2023 07:55:28 +0800 Subject: [PATCH 1/3] Extensible SSL context provider --- .../client/ClickHouseSslContextProvider.java | 23 +++++++++++++++---- .../ClickHouseSslContextProviderTest.java | 13 +++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseSslContextProviderTest.java diff --git a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseSslContextProvider.java b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseSslContextProvider.java index 544e09e27..7fe2cb96e 100644 --- a/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseSslContextProvider.java +++ b/clickhouse-client/src/main/java/com/clickhouse/client/ClickHouseSslContextProvider.java @@ -1,13 +1,15 @@ package com.clickhouse.client; import java.util.Optional; +import java.util.ServiceLoader; + import javax.net.ssl.SSLException; -import com.clickhouse.data.ClickHouseUtils; +import com.clickhouse.data.ClickHouseChecker; /** - * This interface defines how to build Netty SSL context based on given - * configuration and target server. + * This interface defines how to build SSL context based on given configuration + * and target server. */ public interface ClickHouseSslContextProvider { /** @@ -16,7 +18,20 @@ public interface ClickHouseSslContextProvider { * @return non-null SSL context provider */ static ClickHouseSslContextProvider getProvider() { - return ClickHouseUtils.getService(ClickHouseSslContextProvider.class); + String packageName = ClickHouseSslContextProvider.class.getName(); + packageName = packageName.substring(0, packageName.lastIndexOf('.') + 1); + ClickHouseSslContextProvider defaultProvider = null; + for (ClickHouseSslContextProvider s : ServiceLoader.load(ClickHouseSslContextProvider.class, + ClickHouseSslContextProvider.class.getClassLoader())) { + if (s == null) { + // impossible + } else if (s.getClass().getName().startsWith(packageName)) { + defaultProvider = s; + } else { + return s; + } + } + return ClickHouseChecker.nonNull(defaultProvider, ClickHouseSslContextProvider.class.getSimpleName()); } /** diff --git a/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseSslContextProviderTest.java b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseSslContextProviderTest.java new file mode 100644 index 000000000..a853400ca --- /dev/null +++ b/clickhouse-client/src/test/java/com/clickhouse/client/ClickHouseSslContextProviderTest.java @@ -0,0 +1,13 @@ +package com.clickhouse.client; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class ClickHouseSslContextProviderTest { + @Test(groups = { "unit" }) + public void testGetProvider() { + Assert.assertNotNull(ClickHouseSslContextProvider.getProvider()); + Assert.assertEquals(ClickHouseSslContextProvider.getProvider().getClass(), + ClickHouseSslContextProvider.getProvider().getClass()); + } +} \ No newline at end of file From 47d2f8088a1e98f1b0c2054d2ec1920d3adb1d5b Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Tue, 25 Apr 2023 08:01:23 +0800 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c3c513b9..25f723146 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.5.0 +## 0.4.5 ### Breaking Changes * refactor data processors and response classes to ensure input stream remain intact before first read: - move ClickHouseSimpleRecord to com.clickhouse.data @@ -8,6 +8,11 @@ ### New Features * disable SQL rewrite for DELETE statement in ClickHouse 23.3+ +### Bug Fixes +* ClickHouseResponse.getInputStream may return closed input stream. +* ConcurrentModificationException may occure during deserialization. [#1327](https://github.com/ClickHouse/clickhouse-java/pull/1327) +* ClickHouseSslContextProvider is not customizable. [#1329](https://github.com/ClickHouse/clickhouse-java/issues/1329) + ## 0.4.4, 2023-04-17 ### Bug Fixes * flatten plugin 1.4.1 generated non-sense dependencies. From 380ab676712e315089651bbdd7c4aa269a8ba7d7 Mon Sep 17 00:00:00 2001 From: Zhichun Wu Date: Tue, 25 Apr 2023 08:04:01 +0800 Subject: [PATCH 3/3] add missing entry in changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25f723146..4303362ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ * disable SQL rewrite for DELETE statement in ClickHouse 23.3+ ### Bug Fixes +* Slow when using Apache Http Client. [#1320](https://github.com/ClickHouse/clickhouse-java/issues/1320) * ClickHouseResponse.getInputStream may return closed input stream. * ConcurrentModificationException may occure during deserialization. [#1327](https://github.com/ClickHouse/clickhouse-java/pull/1327) * ClickHouseSslContextProvider is not customizable. [#1329](https://github.com/ClickHouse/clickhouse-java/issues/1329)