feat:(add customize resttempalte timeout.)

pull/389/head
Leixinxin 2019-11-19 23:36:51 +08:00
parent 627b15fa92
commit dbfa77e992
3 changed files with 16 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package run.halo.app.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.client.RestTemplateBuilder;
@ -29,6 +30,7 @@ import run.halo.app.utils.HttpClientUtils;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.time.temporal.ChronoUnit;
/**
* Halo configuration.
@ -40,7 +42,8 @@ import java.security.NoSuchAlgorithmException;
@Slf4j
public class HaloConfiguration {
private final static int TIMEOUT = 5000;
@Autowired
HaloProperties haloProperties;
@Bean
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
@ -51,7 +54,8 @@ public class HaloConfiguration {
@Bean
public RestTemplate httpsRestTemplate(RestTemplateBuilder builder) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {
RestTemplate httpsRestTemplate = builder.build();
httpsRestTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(HttpClientUtils.createHttpsClient(TIMEOUT)));
httpsRestTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(HttpClientUtils.createHttpsClient(
(int) haloProperties.getDownloadTimeout().toMillis())));
return httpsRestTemplate;
}

View File

@ -8,6 +8,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.Duration;
/**
@ -59,6 +60,11 @@ public class HaloProperties {
*/
private String backupUrlPrefix = "/backup";
/**
* Download Timeout.
*/
private Duration downloadTimeout = Duration.ofSeconds(30);
public HaloProperties() throws IOException {
// Create work directory if not exist
Files.createDirectories(Paths.get(workDir));

View File

@ -46,4 +46,7 @@ logging:
level:
run.halo.app: INFO
file:
path: ${user.home}/.halo/logs
path: ${user.home}/.halo/logs
halo:
download-timeout: 5m