feat:新增重试
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package com.xiang.xservice.basic.utils;
|
package com.xiang.xservice.basic.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.MapUtils;
|
import org.apache.commons.collections4.MapUtils;
|
||||||
import org.apache.http.client.config.RequestConfig;
|
import org.apache.http.client.config.RequestConfig;
|
||||||
@@ -56,7 +58,7 @@ public class HttpUtils {
|
|||||||
.build();
|
.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()
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
// 设置连接超时时间
|
// 设置连接超时时间
|
||||||
.setConnectTimeout(connectTimeout)
|
.setConnectTimeout(connectTimeout)
|
||||||
@@ -82,7 +84,7 @@ public class HttpUtils {
|
|||||||
return result;
|
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;
|
CloseableHttpResponse response = null;
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
@@ -99,7 +101,20 @@ public class HttpUtils {
|
|||||||
return result;
|
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;
|
CloseableHttpResponse response = null;
|
||||||
String result = "";
|
String result = "";
|
||||||
try {
|
try {
|
||||||
@@ -148,7 +163,7 @@ public class HttpUtils {
|
|||||||
return httpPost;
|
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()
|
RequestConfig requestConfig = RequestConfig.custom()
|
||||||
// 设置连接超时时间
|
// 设置连接超时时间
|
||||||
.setConnectTimeout(connectTimeout)
|
.setConnectTimeout(connectTimeout)
|
||||||
|
|||||||
Reference in New Issue
Block a user