diff --git a/src/main/java/aiyh/utils/httpUtil/HttpManager.java b/src/main/java/aiyh/utils/httpUtil/HttpManager.java
index 41a7222..0d42390 100644
--- a/src/main/java/aiyh/utils/httpUtil/HttpManager.java
+++ b/src/main/java/aiyh/utils/httpUtil/HttpManager.java
@@ -20,6 +20,7 @@ import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
+import java.util.Objects;
/**
@@ -66,6 +67,13 @@ public class HttpManager {
* @return 连接对象
*/
public static CloseableHttpClient getHttpConnection(String url, CredentialsProvider credentialsProvider) {
+ return getHttpConnection(url, credentialsProvider, null);
+ }
+
+ public static CloseableHttpClient getHttpConnection(String url, CredentialsProvider credentialsProvider, RequestConfig cusRequestConfigs) {
+ if(Objects.isNull(cusRequestConfigs)){
+ cusRequestConfigs = requestConfig;
+ }
if (url.trim().toUpperCase().startsWith(HttpArgsType.HTTP_HTTPS.toUpperCase())) {
SSLContext sslContext;
SSLConnectionSocketFactory sslsf = null;
@@ -84,66 +92,74 @@ public class HttpManager {
throw new RuntimeException(e);
}
HttpClientBuilder httpClientBuilder = HttpClients.custom()
- .setSSLSocketFactory(sslsf)
- .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
- .setConnectionManager(manager)
- .setConnectionManagerShared(true)
- .setDefaultRequestConfig(requestConfig);
+ .setSSLSocketFactory(sslsf)
+ .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
+ .setConnectionManager(manager)
+ .setConnectionManagerShared(true)
+ .setDefaultRequestConfig(cusRequestConfigs);
if (credentialsProvider != null) {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
return httpClientBuilder
- .build();
+ .build();
} else {
HttpClientBuilder httpClientBuilder = HttpClients.custom()
- .setConnectionManager(manager)
- .setDefaultRequestConfig(requestConfig)
- .setConnectionManagerShared(true);
+ .setConnectionManager(manager)
+ .setDefaultRequestConfig(cusRequestConfigs)
+ .setConnectionManagerShared(true);
if (credentialsProvider != null) {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
return httpClientBuilder
- .build();
+ .build();
}
}
public static CloseableHttpClient getHttpConnection(String url, CredentialsProvider credentialsProvider, String sslPath, String password) {
+ return getHttpConnection(url, credentialsProvider, sslPath, password, null);
+ }
+
+ public static CloseableHttpClient getHttpConnection(String url, CredentialsProvider credentialsProvider, String sslPath,
+ String password, RequestConfig cusRequestConfigs) {
+ if(Objects.isNull(cusRequestConfigs)){
+ cusRequestConfigs = requestConfig;
+ }
if (url.trim().toUpperCase().startsWith(HttpArgsType.HTTP_HTTPS.toUpperCase())) {
SSLContext sslContext;
SSLConnectionSocketFactory sslsf = null;
try {
sslContext = SSLContexts.custom()
- .loadTrustMaterial(new File(sslPath), password.toCharArray(),
- new TrustSelfSignedStrategy())
- .build();
+ .loadTrustMaterial(new File(sslPath), password.toCharArray(),
+ new TrustSelfSignedStrategy())
+ .build();
sslsf = new SSLConnectionSocketFactory(sslContext,
new String[]{"TLSv1"},
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
} catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException | CertificateException |
- IOException e) {
+ IOException e) {
throw new RuntimeException(e);
}
HttpClientBuilder httpClientBuilder = HttpClients.custom()
- .setSSLSocketFactory(sslsf)
- .setConnectionManager(manager)
- .setConnectionManagerShared(true)
- .setDefaultRequestConfig(requestConfig);
+ .setSSLSocketFactory(sslsf)
+ .setConnectionManager(manager)
+ .setConnectionManagerShared(true)
+ .setDefaultRequestConfig(cusRequestConfigs);
if (credentialsProvider != null) {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
return httpClientBuilder
- .build();
+ .build();
} else {
HttpClientBuilder httpClientBuilder = HttpClients.custom()
- .setConnectionManager(manager)
- .setDefaultRequestConfig(requestConfig)
- .setConnectionManagerShared(true);
+ .setConnectionManager(manager)
+ .setDefaultRequestConfig(cusRequestConfigs)
+ .setConnectionManagerShared(true);
if (credentialsProvider != null) {
httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
return httpClientBuilder
- .build();
+ .build();
}
}
}
diff --git a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java
index 3f76b9f..87fe154 100644
--- a/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java
+++ b/src/main/java/aiyh/utils/httpUtil/util/HttpUtils.java
@@ -63,6 +63,8 @@ public class HttpUtils {
private String sslKeyPath = "";
@Setter
private String password = "";
+ @Setter
+ private RequestConfig requestConfig;
/**
@@ -185,12 +187,12 @@ public class HttpUtils {
*/
private CloseableHttpClient getHttpClient(String url) {
if (Strings.isNullOrEmpty(this.sslKeyPath)) {
- return HttpManager.getHttpConnection(url, this.credentialsProvider);
+ return HttpManager.getHttpConnection(url, this.credentialsProvider, requestConfig);
} else {
- return HttpManager.getHttpConnection(url, this.credentialsProvider, sslKeyPath, password);
+ return HttpManager.getHttpConnection(url, this.credentialsProvider, sslKeyPath, password, requestConfig);
}
}
-
+
/**
* get请求
*
diff --git a/src/main/java/weaver/xuanran/wang/ajx/work_flow_split/action/ChildWorkFlowSplitAction.java b/src/main/java/weaver/xuanran/wang/ajx/work_flow_split/action/ChildWorkFlowSplitAction.java
index f8588b6..707d166 100644
--- a/src/main/java/weaver/xuanran/wang/ajx/work_flow_split/action/ChildWorkFlowSplitAction.java
+++ b/src/main/java/weaver/xuanran/wang/ajx/work_flow_split/action/ChildWorkFlowSplitAction.java
@@ -76,6 +76,9 @@ public class ChildWorkFlowSplitAction extends SafeCusBaseAction {
if (!mapper.updateMainTable(billTable, hasMoreAccountField, null, requestId)) {
throw new CustomerException("更新主表是否包含多账套字段失败!");
}
+ if(!mapper.selectAccountNumber(id, billTable + "_dt" + insertDetailNo)){
+ throw new CustomerException("删除明细表数据失败!");
+ }
return;
}
if (!mapper.updateMainTable(billTable, hasMoreAccountField, hasMoreAccountFieldValue, requestId)) {
diff --git a/src/main/java/weaver/xuanran/wang/common/entity/CusResponseSuccess.java b/src/main/java/weaver/xuanran/wang/common/entity/CusResponseSuccess.java
deleted file mode 100644
index 304d682..0000000
--- a/src/main/java/weaver/xuanran/wang/common/entity/CusResponseSuccess.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package weaver.xuanran.wang.common.entity;
-
-import aiyh.utils.httpUtil.ResponeVo;
-import lombok.AllArgsConstructor;
-import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-import weaver.xuanran.wang.common.service.CusDataDecipher;
-
-import java.util.Map;
-import java.util.function.Consumer;
-import java.util.function.Function;
-
-
-/**
- *
自定义请求条件
- *
- * @author xuanran.wang
- * @date 2023/4/6 19:34
- */
-@Data
-@Builder
-@AllArgsConstructor
-@NoArgsConstructor
-public class CusResponseSuccess {
- private ResponeVo vo;
- private Object requestParam;
- private String successField;
- private Object successValue;
- private String errorMsg;
- private String dataKey;
- private Map response;
- private CusDataDecipher cusDataDecipher;
- private String url;
- private Exception e;
- private boolean checkResponse = true;
- private Consumer call;
-}
diff --git a/src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java b/src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java
index 973dc84..8a6480e 100644
--- a/src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java
+++ b/src/main/java/weaver/xuanran/wang/common/util/TokenUtil.java
@@ -10,6 +10,8 @@ import weaver.xuanran.wang.common.interfaces.CusAbstractTokenConf;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
/**
* 全局缓存token 超时自动请求处理
@@ -21,6 +23,7 @@ public class TokenUtil {
private static final Map TOKEN_MAP = new HashMap<>(8);
private static Util_Redis instance = null;
private static boolean redis = false;
+ private static final Lock lock = new ReentrantLock();
{
try {
@@ -41,25 +44,22 @@ public class TokenUtil {
if(Objects.isNull(conf)){
throw new CustomerException("conf cant not be null!");
}
- CusAbstractTokenConf token = TOKEN_MAP.get(key);
- if(token == null){
- synchronized (TokenUtil.class){
- token = TOKEN_MAP.get(key);
- if(token == null){
- return getTokenByHttp(key, conf);
- }
+ lock.lock();
+ try {
+ CusAbstractTokenConf token = TOKEN_MAP.get(key);
+ if(token == null){
+ return getTokenByHttp(key, conf);
}
- }
- long expiryTime = token.getExpiryTime();
- if(System.currentTimeMillis() >= expiryTime){
- synchronized (TokenUtil.class){
- expiryTime = token.getExpiryTime();
- if(System.currentTimeMillis() >= expiryTime){
- return getTokenByHttp(key, conf);
- }
+ long expiryTime = token.getExpiryTime();
+ if(System.currentTimeMillis() >= expiryTime){
+ return getTokenByHttp(key, conf);
}
+ return token.getToken();
+ }catch (Exception e){
+ throw new CustomerException("get token error : current key is [ " + key + " ]",e);
+ }finally {
+ lock.unlock();
}
- return token.getToken();
}
/**
@@ -70,7 +70,7 @@ public class TokenUtil {
* @param obj token配置对象
* @return token
**/
- private static synchronized String getTokenByHttp(String key, CusAbstractTokenConf obj){
+ private static String getTokenByHttp(String key, CusAbstractTokenConf obj){
Map response = obj.tokenByHttp();
obj.buildTokenObj(response);
TOKEN_MAP.put(key, obj);
diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java
index beb3b3c..66865bc 100644
--- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java
+++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/RequestMasterPlate.java
@@ -6,6 +6,7 @@ import aiyh.utils.httpUtil.ResponeVo;
import aiyh.utils.httpUtil.util.HttpUtils;
import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.config.RequestConfig;
import org.apache.log4j.Logger;
import weaver.xuanran.wang.sh_bigdata.common.entity.CusSuccess;
@@ -23,6 +24,23 @@ public class RequestMasterPlate{
private final HttpUtils httpUtils = new HttpUtils();
private static final int HTTP_SUCCESS_CODE = 200;
+ private static final int CONNECT_TIMEOUT = 1000 * 60 * 3;
+ private static final int CONNECTION_REQUEST_TIMEOUT = 1000 * 60 * 3;
+ private static final int SOCKET_TIMEOUT = 1000 * 60 * 3;
+
+ static RequestConfig requestConfig = RequestConfig.custom()
+ // 网络请求的超时时间
+ .setConnectTimeout(CONNECT_TIMEOUT)
+ // 连接池去获取连接的超时时间
+ .setConnectionRequestTimeout(CONNECTION_REQUEST_TIMEOUT)
+ // 设置socket超时时间
+ .setSocketTimeout(SOCKET_TIMEOUT)
+ .build();
+
+ {
+ httpUtils.setRequestConfig(requestConfig);
+ }
+
public T apiGet(String url, Map params, Map headers, CusSuccess cusSuccess){
ResponeVo responeVo;
try {
diff --git a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java
index f9ae238..c468873 100644
--- a/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java
+++ b/src/main/java/weaver/xuanran/wang/sh_bigdata/common/util/TokenUtil.java
@@ -1,6 +1,7 @@
package weaver.xuanran.wang.sh_bigdata.common.util;
import aiyh.utils.Util;
+import aiyh.utils.excention.CustomerException;
import com.alibaba.fastjson.JSONObject;
import org.apache.dubbo.common.serialize.fastjson.FastJsonObjectOutput;
import org.apache.log4j.Logger;
@@ -11,6 +12,8 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
/**
* token 工具类
@@ -38,25 +41,19 @@ public class TokenUtil {
* @param secret 密钥
**/
public static String getToken(String secret) {
- CusToken token = TOKEN_MAP.get(secret);
- if(token == null){
- synchronized (TokenUtil.class){
- token = TOKEN_MAP.get(secret);
- if(token == null){
- return getTokenByHTTP(secret);
- }
+ try {
+ CusToken token = TOKEN_MAP.get(secret);
+ if(token == null){
+ return getTokenByHTTP(secret);
}
- }
- long expiryTime = token.getExpiryTime();
- if(new Date().getTime() >= expiryTime){
- synchronized (TokenUtil.class){
- expiryTime = token.getExpiryTime();
- if(new Date().getTime() >= expiryTime){
- return getTokenByHTTP(secret);
- }
+ long expiryTime = token.getExpiryTime();
+ if(new Date().getTime() >= expiryTime){
+ return getTokenByHTTP(secret);
}
+ return token.getAccess_token();
+ }catch (Exception e){
+ throw new CustomerException("get token error : current secret is [ " + secret + " ]",e);
}
- return token.getAccess_token();
}
/**
diff --git a/src/test/java/xuanran/wang/ajx/TestA.java b/src/test/java/xuanran/wang/ajx/TestA.java
index c60c564..65dd5c5 100644
--- a/src/test/java/xuanran/wang/ajx/TestA.java
+++ b/src/test/java/xuanran/wang/ajx/TestA.java
@@ -203,4 +203,8 @@ public class TestA extends BaseTest {
}
return dataObject;
}
+ @Test
+ public void testC(){
+ System.out.println(new Date().getTime());
+ }
}
diff --git a/src/test/java/xuanran/wang/http_test/test/TestMain.java b/src/test/java/xuanran/wang/http_test/test/TestMain.java
index c2ee34c..2a17f12 100644
--- a/src/test/java/xuanran/wang/http_test/test/TestMain.java
+++ b/src/test/java/xuanran/wang/http_test/test/TestMain.java
@@ -3,19 +3,11 @@ package xuanran.wang.http_test.test;
import aiyh.utils.httpUtil.ResponeVo;
import basetest.BaseTest;
import com.alibaba.fastjson.JSONObject;
-import com.cloudstore.api.util.Util_Redis;
-import com.fapiao.neon.client.base.impl.RedisClientImpl;
-import com.weaver.base.cache.redis.RedisCache;
-import org.docx4j.wml.R;
import org.junit.Test;
-import weaver.session.util.RedisClient;
-import weaver.session.util.RedisTemplate;
-import weaver.xuanran.wang.common.entity.CusResponseSuccess;
-import xuanran.wang.http_test.rest_test.CusRestTemplate;
-import xuanran.wang.http_test.rest_test.Stu;
+import xuanran.wang.common.entity.CusResponseSuccess;
+import xuanran.wang.rest_test.CusRestTemplate;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
/**
diff --git a/src/test/java/xuanran/wang/http_test/rest_test/CusRestTemplate.java b/src/test/java/xuanran/wang/rest_test/CusRestTemplate.java
similarity index 98%
rename from src/test/java/xuanran/wang/http_test/rest_test/CusRestTemplate.java
rename to src/test/java/xuanran/wang/rest_test/CusRestTemplate.java
index 86ce1ef..5eb6838 100644
--- a/src/test/java/xuanran/wang/http_test/rest_test/CusRestTemplate.java
+++ b/src/test/java/xuanran/wang/rest_test/CusRestTemplate.java
@@ -1,4 +1,4 @@
-package xuanran.wang.http_test.rest_test;
+package xuanran.wang.rest_test;
import aiyh.utils.Util;
import aiyh.utils.excention.CustomerException;
@@ -13,7 +13,7 @@ import com.fasterxml.jackson.databind.type.TypeFactory;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
-import weaver.xuanran.wang.common.entity.CusResponseSuccess;
+import xuanran.wang.common.entity.CusResponseSuccess;
import java.util.List;
import java.util.Map;
diff --git a/src/test/java/xuanran/wang/http_test/rest_test/Stu.java b/src/test/java/xuanran/wang/rest_test/Stu.java
similarity index 88%
rename from src/test/java/xuanran/wang/http_test/rest_test/Stu.java
rename to src/test/java/xuanran/wang/rest_test/Stu.java
index 493b7f4..8a0f5a6 100644
--- a/src/test/java/xuanran/wang/http_test/rest_test/Stu.java
+++ b/src/test/java/xuanran/wang/rest_test/Stu.java
@@ -1,4 +1,4 @@
-package xuanran.wang.http_test.rest_test;
+package xuanran.wang.rest_test;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;