Skip to content

Instantly share code, notes, and snippets.

@aboodz
Last active November 26, 2016 19:27
Show Gist options
  • Select an option

  • Save aboodz/f408087351524ec43b6fc17157e87ee4 to your computer and use it in GitHub Desktop.

Select an option

Save aboodz/f408087351524ec43b6fc17157e87ee4 to your computer and use it in GitHub Desktop.
using RESTeasy RestClientProxyFactoryBean
@Configuration
@ImportResource("classpath:springmvc-resteasy.xml")
public class RestClientConfiguration {
@Inject
private Environment environment;
@Bean
public HttpClient httpClient() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
// Get the poolMaxTotal value from our application[-?].yml or default to 10 if not explicitly set
connectionManager.setMaxTotal(environment.getProperty("poolMaxTotal", Integer.class, 10));
// TODO: explore more settings
return HttpClientBuilder
.create()
.setConnectionManager(connectionManager)
.build();
}
@Bean
@Inject
public RestClientProxyFactoryBean<PingClient> restClientProxyFactoryBean(HttpClient httpClient) throws URISyntaxException {
RestClientProxyFactoryBean<PingClient> restClientProxyFactoryBean = new RestClientProxyFactoryBean<>();
restClientProxyFactoryBean.setBaseUri(new URI("http://10.0.1.9:8787/restful-service/"));
restClientProxyFactoryBean.setHttpClient(httpClient); // This is very important, the default http client is deprecated
restClientProxyFactoryBean.setServiceInterface(PingClient.class);
return restClientProxyFactoryBean;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment