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 e4d46a72a5..e28f7aa47e 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 @@ -11,7 +11,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 { @@ -68,7 +67,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(); @@ -85,7 +83,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);