Skip to content

Commit

Permalink
Merge pull request #1330 from zhicwu/main
Browse files Browse the repository at this point in the history
Extensible SSL context provider
  • Loading branch information
zhicwu authored Apr 25, 2023
2 parents 1fe1b66 + 380ab67 commit e369681
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,6 +8,12 @@
### New Features
* 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)

## 0.4.4, 2023-04-17
### Bug Fixes
* flatten plugin 1.4.1 generated non-sense dependencies.
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand All @@ -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());
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit e369681

Please sign in to comment.