I have a web service running on my dev box implemented using Spring-MVC 3.0. I have various JUnits that test against that service using RestTemplate. What I would like to do
Spring has a good documentation using a Customizer to determine different proxy
public class ProxyCustomizer implements RestTemplateCustomizer {
@Override
public void customize(RestTemplate restTemplate) {
final String proxyUrl = "proxy.example.com";
final int port = 3128;
HttpHost proxy = new HttpHost(proxyUrl, port);
HttpClient httpClient = HttpClientBuilder.create().setRoutePlanner(new DefaultProxyRoutePlanner(proxy) {
@Override
protected HttpHost determineProxy(HttpHost target, HttpRequest request, HttpContext context)
throws HttpException {
if (target.getHostName().equals("gturnquist-quoters.cfapps.io")) {
return super.determineProxy(target, request, context);
}
return null;
}
}).build();
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
}
}
and the call to apply the ProxyCustomizer is
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.additionalCustomizers(new ProxyCustomizer()).build();
}