fix: restTemplate设置超时时间
This commit is contained in:
parent
47617eea2d
commit
7ac223d42e
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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<String, Object> paramMap) {
|
||||
String sessionId = login();
|
||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, new HttpHeaders());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
ResponseEntity<String> response = null;
|
||||
try {
|
||||
String bugCreate = requestUrl.getBugCreate();
|
||||
|
@ -85,7 +83,6 @@ public abstract class ZentaoClient extends BaseClient {
|
|||
public void updateIssue(String id, MultiValueMap<String, Object> paramMap) {
|
||||
String sessionId = login();
|
||||
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(paramMap, new HttpHeaders());
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
try {
|
||||
restTemplate.exchange(requestUrl.getBugUpdate(),
|
||||
HttpMethod.POST, requestEntity, String.class, id, sessionId);
|
||||
|
|
Loading…
Reference in New Issue