【发布时间】:2017-04-01 23:11:33
【问题描述】:
我可以为部署在 Tomcat 中的单个 webapp 控制或配置代理服务器信息吗?在工作中,我位于公司防火墙后面,因此任何访问外部 Web 资源(在我的情况下为第三方 REST API)的代码只有在我在执行环境中设置代理信息时才能工作:
System.setProperty("https.proxyHost", "proxy.company.com");
System.setProperty("https.proxyPort", "2345");
但我不想在代码中包含这个,因为生产环境不涉及代理服务器。
如何将此配置外部化,以便在开发环境中设置代理服务器配置/标志,但在生产环境中跳过该步骤?无论解决方案是什么,它都应该只影响特定的 Web 应用程序,而不是 Tomcat 服务器上的所有 Web 应用程序。
2016 年 11 月 21 日编辑:我正在使用 Spring 的 RestTemplate 来调用 REST API 方法。
@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);
}
【问题讨论】:
标签: tomcat web-applications proxy