package com.style24.batch.support.config;

import java.nio.charset.Charset;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC Configuration
 * 
 * @author gagamel
 * @since 2020. 11. 16
 */
@Configuration
public class TsbWebMvcConfig implements WebMvcConfigurer {

	/**
	 * API 호출을 위한 RestTemplate 설정
	 * @return
	 */
	@Bean
	public RestTemplate restTemplate() {
		HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
		factory.setConnectTimeout(300000);
		factory.setReadTimeout(300000);

		RestTemplate restTemplate = new RestTemplate(factory);

		// Convert the message to UTF-8
		restTemplate.getMessageConverters().add(0, new StringHttpMessageConverter(Charset.forName("UTF-8")));

		return restTemplate;
	}

}
