Commit 236443ad authored by matianhao's avatar matianhao

[鸿程接口] <feat> 增加请求失败重试机制

parent e628134a
......@@ -437,7 +437,7 @@ public class RestTemplateService {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
paramMap.add("appSecret", hongchengAppSecret);
paramMap.set("appSecret", hongchengAppSecret);
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<>(paramMap, headers);
log.info("api描述:{}", apiDesc);
......@@ -448,6 +448,24 @@ public class RestTemplateService {
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, httpEntity, String.class);
log.info("api response:{}", responseEntity);
try {
// 接口返回
JSONObject data = JSONObject.parseObject(responseEntity.getBody()).getJSONObject("data");
Integer count = threadLocal.get();
String threadName = Thread.currentThread().getName();
// 如异常返回,重新发送请求,限制重新请求次数两次
boolean errorResponse = data == null || RESPONSE_CODE_14.equals(data.getString("code"));
if (errorResponse && count < 2) {
threadLocal.set(++count);
log.info("线程名称:{},重新请求次数:{}", threadName, count);
// 重新发起调用请求
return hongChengSendRequest2(paramMap, apiMethod, apiDesc);
}
} finally {
threadLocal.remove();
}
return responseEntity;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment