From f8fb37447498ef2a90a9892d1ee44bbc8c610d18 Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Thu, 23 Dec 2021 14:23:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20restTemplate=E8=AE=BE=E7=BD=AE=E8=B6=85?= =?UTF-8?q?=E6=97=B6=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/metersphere/config/WebConfig.java | 12 ++++++++---- .../metersphere/track/issue/client/ZentaoClient.java | 3 --- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/src/main/java/io/metersphere/config/WebConfig.java b/backend/src/main/java/io/metersphere/config/WebConfig.java index e745a2e187..6200b43fd3 100644 --- a/backend/src/main/java/io/metersphere/config/WebConfig.java +++ b/backend/src/main/java/io/metersphere/config/WebConfig.java @@ -11,16 +11,20 @@ public class WebConfig implements WebMvcConfigurer { @Bean public RestTemplate restTemplate() { - return new RestTemplate(); + return getTimeOutTemplate(10 * 1000, 10 * 1000, 30 * 1000); } @Bean public RestTemplate restTemplateWithTimeOut() { + return getTimeOutTemplate(4000, 4000, 10 * 1000); + } + + private RestTemplate getTimeOutTemplate(int requestTimeout, int connectTimeout, int readTimeout) { RestTemplate restTemplate = new RestTemplate(); HttpComponentsClientHttpRequestFactory httpRequestFactory = new HttpComponentsClientHttpRequestFactory(); - httpRequestFactory.setConnectionRequestTimeout(4000); - httpRequestFactory.setConnectTimeout(4000); - httpRequestFactory.setReadTimeout(10 * 1000); + httpRequestFactory.setConnectionRequestTimeout(requestTimeout); + httpRequestFactory.setConnectTimeout(connectTimeout); + httpRequestFactory.setReadTimeout(readTimeout); restTemplate.setRequestFactory(httpRequestFactory); return restTemplate; } diff --git a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java index cec22915f3..0ff1c9aa1e 100644 --- a/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java +++ b/backend/src/main/java/io/metersphere/track/issue/client/ZentaoClient.java @@ -15,7 +15,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import org.springframework.web.client.RestTemplate; public abstract class ZentaoClient extends BaseClient { @@ -74,7 +73,6 @@ public abstract class ZentaoClient extends BaseClient { public AddIssueResponse.Issue addIssue(MultiValueMap paramMap) { String sessionId = login(); HttpEntity> requestEntity = new HttpEntity<>(paramMap, new HttpHeaders()); - RestTemplate restTemplate = new RestTemplate(); ResponseEntity response = null; try { String bugCreate = requestUrl.getBugCreate(); @@ -91,7 +89,6 @@ public abstract class ZentaoClient extends BaseClient { public void updateIssue(String id, MultiValueMap paramMap) { String sessionId = login(); HttpEntity> requestEntity = new HttpEntity<>(paramMap, new HttpHeaders()); - RestTemplate restTemplate = new RestTemplate(); try { restTemplate.exchange(requestUrl.getBugUpdate(), HttpMethod.POST, requestEntity, String.class, id, sessionId);