|
@@ -71,24 +71,31 @@ public class ProxyHttpPoolClient {
|
|
|
}
|
|
|
|
|
|
public String request(HttpRequestBase request) throws IOException {
|
|
|
-
|
|
|
- HttpEntity entity = null;
|
|
|
- CloseableHttpResponse response = request((HttpUriRequest) request);
|
|
|
- if (response == null) {
|
|
|
- log.error("call api exception no response");
|
|
|
- throw new RuntimeException("call api exception no response");
|
|
|
- }
|
|
|
- entity = response.getEntity();
|
|
|
- String content = null;
|
|
|
- if (entity != null) {
|
|
|
- content = EntityUtils.toString(entity, "UTF-8");
|
|
|
- }
|
|
|
- int httpStatus = response.getStatusLine().getStatusCode();
|
|
|
- if (httpStatus == HttpStatus.SC_OK) {
|
|
|
- return content;
|
|
|
+ int retry = 0;
|
|
|
+ while (retry <= 3) {
|
|
|
+ try {
|
|
|
+ retry++;
|
|
|
+ HttpEntity entity = null;
|
|
|
+ CloseableHttpResponse response = request((HttpUriRequest) request);
|
|
|
+ if (response == null) {
|
|
|
+ log.error("call api exception no response");
|
|
|
+ throw new RuntimeException("call api exception no response");
|
|
|
+ }
|
|
|
+ entity = response.getEntity();
|
|
|
+ String content = null;
|
|
|
+ if (entity != null) {
|
|
|
+ content = EntityUtils.toString(entity, "UTF-8");
|
|
|
+ }
|
|
|
+ int httpStatus = response.getStatusLine().getStatusCode();
|
|
|
+ if (httpStatus == HttpStatus.SC_OK) {
|
|
|
+ return content;
|
|
|
+ }
|
|
|
+ String path = request.getURI().toString();
|
|
|
+ log.error("http call api {} fail response status {} content {}", path, httpStatus, content);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("request error", e);
|
|
|
+ }
|
|
|
}
|
|
|
- String path = request.getURI().toString();
|
|
|
- log.error("http call api {} fail response status {} content {}", path, httpStatus, content);
|
|
|
return null;
|
|
|
}
|
|
|
|