Created
July 22, 2016 20:46
-
-
Save kartikshah/7261a89bd42e5d839afda6329e1b6d1a to your computer and use it in GitHub Desktop.
sample AppConfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
@ComponentScan(basePackageClasses = Application.class) | |
public class AppConfig | |
{ | |
@Bean | |
public RestTemplate restTemplate() { | |
RestTemplate restTemplate = new RestTemplate(httpRequestFactory()); | |
List<HttpMessageConverter<?>> converters = restTemplate.getMessageConverters(); | |
for (HttpMessageConverter<?> converter : converters) { | |
if (converter instanceof MappingJackson2HttpMessageConverter) { | |
MappingJackson2HttpMessageConverter jsonConverter = (MappingJackson2HttpMessageConverter) converter; | |
jsonConverter.setObjectMapper(new ObjectMapper()); | |
jsonConverter.setSupportedMediaTypes(Arrays.asList(new MediaType("application", "json", MappingJackson2HttpMessageConverter.DEFAULT_CHARSET), new MediaType("text", "javascript", MappingJackson2HttpMessageConverter.DEFAULT_CHARSET))); | |
} | |
} | |
return restTemplate; | |
} | |
@Bean | |
public ClientHttpRequestFactory httpRequestFactory() { | |
return new HttpComponentsClientHttpRequestFactory(httpClient()); | |
} | |
@Bean | |
public HttpClient httpClient() { | |
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(); | |
CloseableHttpClient closeableHttpClient = HttpClientBuilder.create().setConnectionManager(connectionManager).build(); | |
connectionManager.setMaxTotal(5); | |
connectionManager.setDefaultMaxPerRoute(5); | |
return closeableHttpClient; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment