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

@@ -81,8 +81,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,12 +12,17 @@ import com.openhis.web.externalintegration.appservice.IFoodborneAcquisitionAppSe
import com.openhis.web.externalintegration.dto.FaSimplediseaseAddNopwParam;
import com.openhis.web.externalintegration.mapper.FoodborneAcquisitionAppMapper;
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.HttpGet;
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.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -83,12 +88,24 @@ public class FoodborneAcquisitionAppServiceImpl implements IFoodborneAcquisition
return R.fail("【食源性判断接口】未找到有效诊断");
}
// 设置超时时间
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 {
// 对参数值进行URL编码

View File

@@ -32,13 +32,13 @@ import com.openhis.web.nenu.dto.GfStudentListImportDto;
import com.openhis.web.nenu.dto.GfStudentPeisDto;
import com.openhis.web.nenu.dto.PeisStudentPatientDto;
import com.openhis.web.nenu.mapper.GfStudentListAppMapper;
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.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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@@ -576,10 +576,9 @@ public class GfStudentListAppServiceImpl implements IGfStudentListAppService {
*/
private boolean sendSingleBatchHttpRequest(PeisStudentPatientDto peisStudentPatientDto) {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000).setConnectionRequestTimeout(90000)
.setSocketTimeout(90000).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionRequestTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setResponseTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).build();
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
CloseableHttpResponse response = null;
ClassicHttpResponse response = null;
// 发送请求
try {
HttpPost httpPost = new HttpPost(TenantOptionUtil.getOptionContent(TenantOptionDict.PEIS_SERVER_URL) + "/wx/auth/syncHisInfo");

View File

@@ -44,15 +44,15 @@ import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
import org.apache.http.HttpResponse;
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.core5.http.ClassicHttpResponse;
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;

View File

@@ -26,15 +26,15 @@ import com.openhis.web.paymentmanage.mapper.PaymentMapper;
import com.openhis.yb.dto.PaymentDetailDto;
import com.openhis.yb.dto.ThreePartPayDto;
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.HttpGet;
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.HttpGet;
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;
@@ -548,10 +548,9 @@ public class ThreePartPayServiceImpl implements ThreePartPayService {
private String httpGet(String url) {
String resultString = "";
// 创建Http请求2025/10/13 师大会超时故此由30000-》60000
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000).setConnectionRequestTimeout(90000)
.setSocketTimeout(90000).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionRequestTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setResponseTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).build();
CloseableHttpClient httpClient = HttpClients.custom().setDefaultRequestConfig(requestConfig).build();
CloseableHttpResponse response = null;
ClassicHttpResponse response = null;
// 发送请求
try {
HttpGet httpGet = new HttpGet(url);
@@ -583,10 +582,9 @@ public class ThreePartPayServiceImpl implements ThreePartPayService {
String resultString = "";
// 创建Http请求2025/10/13 师大会超时故此由30000-》60000
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000).setConnectionRequestTimeout(90000)
.setSocketTimeout(90000).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionRequestTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setResponseTimeout(90000, 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);

View File

@@ -3,13 +3,12 @@
*/
package com.openhis.web.tencentJH.utils.httpUtil;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import java.io.IOException;
import java.util.HashMap;
@@ -17,28 +16,22 @@ import java.util.Map;
public abstract class HttpReques {
// 创建HttpClientBuilder
private HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// HttpClient
private CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
private CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
protected HttpUriRequestBase httpReques;
protected HttpUriRequest httpReques;
// HttpUriRequest httpReques;
@SuppressWarnings("finally")
public Map<String, String> executeResponse() {
Map<String, String> context = new HashMap<>();
try {
// closeableHttpClient= WebClientDevWrapper.wrapClient(closeableHttpClient);
// 设置请求头
// 设置请求
HttpResponse httpResponse = closeableHttpClient.execute(httpReques);
// 执行请求
ClassicHttpResponse httpResponse = closeableHttpClient.executeOpen(null, httpReques, null);
HttpEntity entity = httpResponse.getEntity();
// 响应状态
int status = httpResponse.getStatusLine().getStatusCode();
int status = httpResponse.getCode();
context.put("msg", EntityUtils.toString(entity,"utf-8"));
context.put("status", status+"");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {

View File

@@ -3,10 +3,11 @@
*/
package com.openhis.web.tencentJH.utils.httpUtil;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.config.RequestConfig;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class HttpRequesGet extends HttpReques {
@@ -29,9 +30,11 @@ public class HttpRequesGet extends HttpReques {
}
}
HttpGet httpGet = new HttpGet(sb.toString());
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(20000).setConnectionRequestTimeout(15000)
.setSocketTimeout(20000).build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(20, TimeUnit.SECONDS)
.setConnectionRequestTimeout(15, TimeUnit.SECONDS)
.setResponseTimeout(20, TimeUnit.SECONDS)
.build();
httpGet.setConfig(requestConfig);
if (headers != null) {

View File

@@ -7,17 +7,18 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.alibaba.fastjson2.JSON;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicNameValuePair;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.client5.http.entity.UrlEncodedFormEntity;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@@ -27,11 +28,14 @@ public class HttpRequesPost extends HttpReques {
public HttpRequesPost(String path, Map<String, Object> param, Map<String, String> headers) {
HttpPost httpPost = new HttpPost(path);
try {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(20000)
.setConnectionRequestTimeout(20000).setSocketTimeout(20000).build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(20, TimeUnit.SECONDS)
.setConnectionRequestTimeout(20, TimeUnit.SECONDS)
.setResponseTimeout(20, TimeUnit.SECONDS)
.build();
httpPost.setConfig(requestConfig);
// 创建参数队列
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
List<BasicNameValuePair> formparams = new ArrayList<>();
if (param != null) {
for (String key : param.keySet()) {
if (param.get(key) != null) {
@@ -39,14 +43,14 @@ public class HttpRequesPost extends HttpReques {
}
}
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8");
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, StandardCharsets.UTF_8);
httpPost.setEntity(entity);
if (headers != null) {
for (String key : headers.keySet()) {
httpPost.addHeader(key, headers.get(key));
}
}
} catch (UnsupportedEncodingException e) {
} catch (Exception e) {
log.error("Exception occurred", e);
}
this.httpReques = httpPost;
@@ -55,15 +59,16 @@ public class HttpRequesPost extends HttpReques {
public HttpRequesPost(String path, Map<String, Object> param, Map<String, Object> headers, String requestType) {
HttpPost httpPost = new HttpPost(path);
try {
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(5000)
.setConnectionRequestTimeout(5000).setSocketTimeout(5000).build();
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5, TimeUnit.SECONDS)
.setConnectionRequestTimeout(5, TimeUnit.SECONDS)
.setResponseTimeout(5, TimeUnit.SECONDS)
.build();
httpPost.setConfig(requestConfig);
// 创建参数队列
if ("json".equals(requestType.toLowerCase())) {
// 解决中文乱码问题
StringEntity entity = new StringEntity(JSON.toJSONString(param), "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
StringEntity entity = new StringEntity(JSON.toJSONString(param), ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
} else if("xml".equals(requestType.toLowerCase())){
StringBuffer xml=new StringBuffer();
@@ -75,14 +80,12 @@ public class HttpRequesPost extends HttpReques {
}
xml.append("</xml>");
// 解决中文乱码问题
StringEntity entity = new StringEntity(xml.toString(), "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("text/xml");
StringEntity entity = new StringEntity(xml.toString(), ContentType.TEXT_XML.withCharset(StandardCharsets.UTF_8));
log.info("----------xml:"+xml.toString());
httpPost.setEntity(entity);
} else if ("".equals(requestType) || requestType == null) {
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
List<BasicNameValuePair> formParams = new ArrayList<>();
if (param != null) {
for (String key : param.keySet()) {
if (param.get(key) != null) {
@@ -90,7 +93,7 @@ public class HttpRequesPost extends HttpReques {
}
}
}
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, "UTF-8");
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formParams, StandardCharsets.UTF_8);
httpPost.setEntity(entity);
}
if (headers != null) {
@@ -98,7 +101,7 @@ public class HttpRequesPost extends HttpReques {
httpPost.addHeader(key, headers.get(key).toString());
}
}
} catch (UnsupportedEncodingException e) {
} catch (Exception e) {
log.error("Exception occurred", e);
}
this.httpReques = httpPost;

View File

@@ -1,13 +1,13 @@
package com.openhis.web.tencentJH.utils.httpUtil;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
/**
* @ClassName HttpsClientUtil
@@ -18,27 +18,33 @@ import org.apache.http.util.EntityUtils;
**/
public class HttpsClientUtil {
public static String doPost(String url,String jsonData){
HttpClient httpClient = null;
HttpPost httpPost = null;
public static String doPost(String url, String jsonData) {
CloseableHttpClient httpClient = null;
String result = null;
try{
httpClient = new SSLClient();
httpPost = new HttpPost(url);
try {
httpClient = SSLClient.create();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json");
StringEntity se = new StringEntity(jsonData);
se.setContentType("text/json");
se.setContentEncoding(new BasicHeader("Content-Type", "application/json"));
StringEntity se = new StringEntity(jsonData, ContentType.APPLICATION_JSON);
httpPost.setEntity(se);
HttpResponse response = httpClient.execute(httpPost);
if(response != null){
ClassicHttpResponse response = httpClient.executeOpen(null, httpPost, null);
if (response != null) {
HttpEntity resEntity = response.getEntity();
if(resEntity != null){
result = EntityUtils.toString(resEntity,"utf-8");
if (resEntity != null) {
result = EntityUtils.toString(resEntity, "utf-8");
}
response.close();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (httpClient != null) {
try {
httpClient.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}catch (Exception e){
e.printStackTrace();
}
return result;
}

View File

@@ -1,10 +1,12 @@
package com.openhis.web.tencentJH.utils.httpUtil;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
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 javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
@@ -14,38 +16,27 @@ import java.security.cert.X509Certificate;
/**
* @ClassName SSLClient
* @Description TODO
* @Description SSL Client for HTTPS connections (trust all)
* @Author raymond
* @Date 2024/1/9 08:28
* @Version 1.0
**/
@SuppressWarnings("deprecation")
public class SSLClient extends DefaultHttpClient {
public class SSLClient {
public SSLClient() throws Exception {
super();
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null,new TrustManager[]{tm},null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx,SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
ClientConnectionManager ccm = this.getConnectionManager();
SchemeRegistry registry = ccm.getSchemeRegistry();
registry.register(new Scheme("https",443,ssf));
public static CloseableHttpClient create() throws Exception {
SSLContext ctx = SSLContexts.custom()
.loadTrustMaterial(null, (chain, authType) -> true)
.build();
HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
.setSslContext(ctx)
.setHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.build())
.build();
return HttpClients.custom()
.setConnectionManager(connectionManager)
.build();
}
}

View File

@@ -1,49 +0,0 @@
/**
* @Title: WebClientDevWrapper.java
* @Package com.hmc.core.util.http_client
* @Description: TODO(用一句话描述该文件做什么)
* @author daniel
* @date 2016年9月26日 下午5:28:13
* @version V1.0
*/
package com.openhis.web.tencentJH.utils.httpUtil;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class WebClientDevWrapper {
public static DefaultHttpClient wrapClient(org.apache.http.client.HttpClient base) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
@Override
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {}
};
ctx.init(null, new TrustManager[] { tm }, null);
SSLSocketFactory ssf = new SSLSocketFactory(ctx, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", 443, ssf));
ThreadSafeClientConnManager mgr = new ThreadSafeClientConnManager(registry);
return new DefaultHttpClient(mgr, base.getParams());
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}

View File

@@ -15,14 +15,14 @@ import com.openhis.yb.dto.BaseInfo;
import com.openhis.yb.dto.BaseParam;
import com.openhis.yb.util.YbParamBuilderUtil;
import com.openhis.ybelep.domain.*;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -232,10 +232,9 @@ public class YbEleHttpServiceImpl implements IYbEleHttpService {
BaseParam baseParam = new BaseParam();
baseParam.setBaseInfo(baseInfo).setData(o);
// 创建Http请求2025/10/13 师大会超时故此由30000-》60000
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000).setConnectionRequestTimeout(90000)
.setSocketTimeout(90000).build();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setConnectionRequestTimeout(90000, java.util.concurrent.TimeUnit.MILLISECONDS).setResponseTimeout(90000, 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);

View File

@@ -17,8 +17,8 @@
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
</dependency>
<dependency>

View File

@@ -2,8 +2,8 @@ package com.openhis.common.utils;
import com.core.common.core.domain.R;
import com.core.common.utils.poi.ExcelUtil;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.springframework.web.multipart.MultipartFile;
import javax.net.ssl.SSLContext;

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);

View File

@@ -42,7 +42,7 @@
<flowable.version>7.1.0</flowable.version>
<postgresql.version>42.7.10</postgresql.version>
<aviator.version>5.3.3</aviator.version>
<httpclient.version>4.5.14</httpclient.version>
<httpclient5.version>5.6.1</httpclient5.version>
<fastjson2.version>2.0.61</fastjson2.version>
<pinyin4j.version>2.5.1</pinyin4j.version>
<liteflow-spring-boot-starter.version>2.12.4.1</liteflow-spring-boot-starter.version>
@@ -351,9 +351,9 @@
</dependency>
<!-- JSQlParser - MyBatis Plus 3.5.9+ 需要 4.6+ -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>${httpclient5.version}</version>
</dependency>
</dependencies>
</dependencyManagement>