package net.northking.cctp.se.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
@Slf4j
public class RestTemplateConfig {

    private final static int timeout = 10000;

    @Bean
    public RestTemplate createRestTemplate() {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        log.info("加载RestTemplate，设置连接超时时间：{}ms，读取超时时间：{}ms", timeout, timeout);
        factory.setConnectTimeout(timeout);
        factory.setReadTimeout(timeout);
        RestTemplate template = new RestTemplate(factory);
        template.setErrorHandler(new HttpErrorHandler());
        return template;
    }
}
