refactor: httpclient 4.x → 5.x 完整迁移

Maven 依赖:
- org.apache.httpcomponents:httpclient:4.5.14
- → org.apache.httpcomponents.client5:httpclient5:5.6.1

API 迁移 (14 文件):
- org.apache.http.* → org.apache.hc.client5.http.* / org.apache.hc.core5.http.*
- CloseableHttpResponse → ClassicHttpResponse
- RequestConfig timeout API: 毫秒值 → TimeUnit
- SSL: SSLSocketFactory → SSLConnectionSocketFactoryBuilder
- DefaultHttpClient (已废弃) → HttpClients.custom()

工具类迁移:
- HttpReques.java (基类)
- HttpRequesPost.java (POST)
- HttpRequesGet.java (GET)
- HttpsClientUtil.java (HTTPS)
- SSLClient.java (SSL)
- CommonUtil.java (SSL 工具)

业务 Service 迁移:
- YbHttpUtils.java (医保)
- CrossSystemSendApplyUtil.java (跨系统)
- YbEleHttpServiceImpl.java (医保电子)
- EleInvoiceServiceImpl.java (电子票据)
- ThreePartPayServiceImpl.java (三方支付)
- GfStudentListAppServiceImpl.java (学生体检)
- FoodborneAcquisitionAppServiceImpl.java (食品安全)

删除: WebClientDevWrapper.java (未使用)

验证: BUILD SUCCESS
This commit is contained in:
2026-06-05 11:39:50 +08:00
parent 0e69a01120
commit e0d4c203e4
18 changed files with 236 additions and 248 deletions

View File

@@ -45,8 +45,8 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<!-- 共通-->
<dependency>

View File

@@ -12,14 +12,19 @@ import com.openhis.crosssystem.dto.*;
import com.openhis.crosssystem.enums.LisAgeUnit;
import com.openhis.crosssystem.enums.PacsAgeUnit;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.springframework.stereotype.Component;
import java.io.IOException;
@@ -104,12 +109,24 @@ public class CrossSystemSendApplyUtil {
.setGroupName(lisApplyDto.getGroupList().stream().map(LisApplyGroupDto::getGroupName)
.collect(Collectors.joining("+")));
// 设置超时时间
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(3000)
.setSocketTimeout(30000).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionRequestTimeout(3000, java.util.concurrent.TimeUnit.MILLISECONDS).setResponseTimeout(30000, java.util.concurrent.TimeUnit.MILLISECONDS).build();
// 创建无视SSL验证的HttpClient
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig)
.setSSLSocketFactory(CommonUtil.createIgnoreSslSocketFactory()).build();
CloseableHttpResponse response = null;
HttpClientConnectionManager connectionManager;
try {
connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
.setSslContext(SSLContexts.custom().loadTrustMaterial(null, (chain, authType) -> true).build())
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build())
.build();
} catch (Exception e) {
throw new RuntimeException("Failed to create SSL connection manager", e);
}
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(connectionManager)
.build();
ClassicHttpResponse response = null;
// 发起HTTP请求
try {
HttpPost httpPost = new HttpPost(apiUrl);
@@ -207,12 +224,24 @@ public class CrossSystemSendApplyUtil {
// 必填 【检查项目名称】
.setGroupName(pacsApplyDto.getGroupName());
// 设置超时时间
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(3000)
.setSocketTimeout(30000).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionRequestTimeout(3000, java.util.concurrent.TimeUnit.MILLISECONDS).setResponseTimeout(30000, java.util.concurrent.TimeUnit.MILLISECONDS).build();
// 创建无视SSL验证的HttpClient
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig)
.setSSLSocketFactory(CommonUtil.createIgnoreSslSocketFactory()).build();
CloseableHttpResponse response = null;
HttpClientConnectionManager connectionManager;
try {
connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
.setSslContext(SSLContexts.custom().loadTrustMaterial(null, (chain, authType) -> true).build())
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build())
.build();
} catch (Exception e) {
throw new RuntimeException("Failed to create SSL connection manager", e);
}
CloseableHttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(requestConfig)
.setConnectionManager(connectionManager)
.build();
ClassicHttpResponse response = null;
// 发起HTTP请求
try {
HttpPost httpPost = new HttpPost(apiUrl);

View File

@@ -23,14 +23,14 @@ import com.openhis.yb.dto.*;
import com.openhis.yb.model.Clinic2207OrderModel;
import com.openhis.yb.model.Clinic2207OrderParam;
import com.openhis.yb.util.YbParamBuilderUtil;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -756,10 +756,9 @@ public class YbHttpUtils {
baseParam.setBaseInfo(ybParamBuilderUtil.getBaseInfo(parseObject(JSON.toJSONString(o)), contract)).setData(o);
logger.info("【请求路径】:" + url + ";【入参】: " + JSON.toJSONString(baseParam));
// 创建Http请求
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(300000)
.setConnectionRequestTimeout(300000).setSocketTimeout(300000).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(300000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionRequestTimeout(300000, java.util.concurrent.TimeUnit.MILLISECONDS).setResponseTimeout(300000, java.util.concurrent.TimeUnit.MILLISECONDS).build();
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
CloseableHttpResponse response = null;
ClassicHttpResponse response = null;
// 发送请求
try {
HttpPost httpPost = new HttpPost(url);