Can I control or configure the proxy server information for an individual webapp deployed in Tomcat? At work, I am behind a corporate firewall, so any code that accesses external web resources (3rd party REST API, in my case) will work only if I set proxy information in the executing environment:
System.setProperty("https.proxyHost", "proxy.company.com");
System.setProperty("https.proxyPort", "2345");
But I don't want to include this in the code, because the production environment does not involve the proxy server.
How can I externalize this configuration so I can set proxy server configuration/flags in the development environment but skip the step in the production environment? Whatever the solution is, it should affect only a particular web application and not all web applications on the Tomcat server.
Edited 11/21/2016: I am using Spring's RestTemplate
to invoke the REST API method.
@RequestMapping(value="/{userId}",
method = RequestMethod.GET)
public ResponseEntity<String> getUserInfo(@PathVariable String userId,
@RequestHeader String apikey) {
String url = UserAPIProperties.getUsersUrl() + "/users/{userId}";
// Set headers for the request
Map<String,Object> headersMap = new HashMap<String,Object>();
headersMap.put("apiKey", apiKey);
headersMap.put("Accept", "application/json");
HttpEntity<?> httpEntity = getHttpEntity(headersMap);
log.debug("API Key: {}, User ID: {}", apikey, userId);
RestTemplate restTemplate = new RestTemplate();
return restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class, userId);
}