feat:新增重试
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.xiang.xservice.basic.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.http.client.config.RequestConfig;
|
||||
@@ -56,7 +58,7 @@ public class HttpUtils {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static String doPost(String url, Map<String, String> header, String jsonParams) {
|
||||
public static String doPostV1(String url, Map<String, String> header, String jsonParams) {
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
// 设置连接超时时间
|
||||
.setConnectTimeout(connectTimeout)
|
||||
@@ -82,7 +84,7 @@ public class HttpUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String doPostV2(String url, Map<String, String> header, String jsonParams) {
|
||||
public static String doPost(String url, Map<String, String> header, String jsonParams) {
|
||||
CloseableHttpResponse response = null;
|
||||
String result = "";
|
||||
try {
|
||||
@@ -99,7 +101,20 @@ public class HttpUtils {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String doGetV2(String url, Map<String, String> header, Map<String, String> param) {
|
||||
public static String doPostWithRetry(String url, Map<String, String> header, String jsonParams, Integer successCode, int retryCounts) {
|
||||
int i = 0;
|
||||
while (i++ < retryCounts) {
|
||||
String respStr = doPost(url, header, jsonParams);
|
||||
JSONObject resp = JSON.parseObject(respStr);
|
||||
Integer code = (Integer) resp.get("code");
|
||||
if (successCode.equals(code)) {
|
||||
return respStr;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String doGet(String url, Map<String, String> header, Map<String, String> param) {
|
||||
CloseableHttpResponse response = null;
|
||||
String result = "";
|
||||
try {
|
||||
@@ -148,7 +163,7 @@ public class HttpUtils {
|
||||
return httpPost;
|
||||
}
|
||||
|
||||
public static String doGet(String url, Map<String, String> header, Map<String, String> param) {
|
||||
public static String doGetV1(String url, Map<String, String> header, Map<String, String> param) {
|
||||
RequestConfig requestConfig = RequestConfig.custom()
|
||||
// 设置连接超时时间
|
||||
.setConnectTimeout(connectTimeout)
|
||||
|
||||
Reference in New Issue
Block a user