Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
jiwei-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
马天浩
jiwei-api
Commits
236443ad
Commit
236443ad
authored
May 20, 2021
by
matianhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[鸿程接口] <feat> 增加请求失败重试机制
parent
e628134a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletion
+19
-1
RestTemplateService.java
...va/com/mth/requestsecret/service/RestTemplateService.java
+19
-1
No files found.
src/main/java/com/mth/requestsecret/service/RestTemplateService.java
View file @
236443ad
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment