package com.eactive.eai.rms.ext.user.sync;

import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

@Configuration
public class RestTemplateConfiguration {
	
	@Bean
	public HttpClient httpClient() {
		
		HttpClient httpClient = 
				HttpClientBuilder.create()
				.setMaxConnTotal(50)
				.setMaxConnPerRoute(20)
				.build();
		
		return httpClient;
	}
	
	@Bean
	public HttpComponentsClientHttpRequestFactory factory(HttpClient httpClient) {
		HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
		factory.setHttpClient(httpClient);
		return factory;
	}
	
	@Bean
	public RestTemplate restTemplate(HttpComponentsClientHttpRequestFactory factory) {
		RestTemplate restTemplate = new RestTemplate();
		restTemplate.setRequestFactory(factory);
		return restTemplate;
	}

}
