feat: 优化rest client

This commit is contained in:
wangyu 2023-01-11 16:19:14 +08:00
parent 4dabcf6ed1
commit 8c8be418c9
2 changed files with 5 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package group.flyfish.rest.core.client;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JavaType;
import group.flyfish.rest.core.exception.RestClientException;
import group.flyfish.rest.core.factory.HttpClientFactoryBean;
import group.flyfish.rest.core.factory.HttpClientProvider;
import group.flyfish.rest.enums.ResponseType;
import group.flyfish.rest.utils.JacksonUtil;
@ -67,6 +68,7 @@ final class DefaultRestClient implements RestClient {
*/
DefaultRestClient(HttpRequestBase request) {
this.request = request;
this.clientProvider = HttpClientFactoryBean::createSSLClient;
}
/**
@ -273,7 +275,6 @@ final class DefaultRestClient implements RestClient {
return innerExecute();
}
/**
* 内部执行方法预处理结果
*

View File

@ -28,7 +28,7 @@ public final class HttpClientFactoryBean implements FactoryBean<CloseableHttpCli
// 使用非公平锁
private final ReentrantLock lock = new ReentrantLock();
// 客户端实例单例
private static volatile CloseableHttpClient client;
private volatile CloseableHttpClient client;
// 配置配置没进来就不初始化
private final RestClientProperties properties;
@ -42,11 +42,11 @@ public final class HttpClientFactoryBean implements FactoryBean<CloseableHttpCli
}
/**
* 不信任的证书请求客户端
* 不信任的证书请求客户端默认客户端
*
* @return 结果
*/
private static CloseableHttpClient createSSLClient() {
public static CloseableHttpClient createSSLClient() {
//信任所有
try {
SSLContext context = SSLContextBuilder.create().loadTrustMaterial(null, (arg0, arg1) -> true).build();