String proxyUser = Play.configuration.getProperty("http.proxyUser", System.getProperty("http.proxyUser"));
String proxyPassword = Play.configuration.getProperty("http.proxyPassword", System.getProperty("http.proxyPassword"));
String nonProxyHosts = Play.configuration.getProperty("http.nonProxyHosts", System.getProperty("http.nonProxyHosts"));
String userAgent = Play.configuration.getProperty("http.userAgent");
Builder confBuilder = new AsyncHttpClientConfig.Builder();
if (proxyHost != null) {
int proxyPortInt = 0;
try {
proxyPortInt = Integer.parseInt(proxyPort);
} catch (NumberFormatException e) {
Logger.error("Cannot parse the proxy port property '%s'. Check property http.proxyPort either in System configuration or in Play config file.", proxyPort);
throw new IllegalStateException("WS proxy is misconfigured -- check the logs for details");
}
ProxyServer proxy = new ProxyServer(proxyHost, proxyPortInt, proxyUser, proxyPassword);
if (nonProxyHosts != null) {
final String[] strings = nonProxyHosts.split("\\|");
for (String uril : strings) {
proxy.addNonProxyHost(uril);
}
}
confBuilder.setProxyServer(proxy);
}
if (userAgent != null) {
confBuilder.setUserAgent(userAgent);
}
// when using raw urls, AHC does not encode the params in url.
// this means we can/must encode it(with correct encoding) before passing it to AHC
confBuilder.setUseRawUrl(true);
httpClient = new AsyncHttpClient(confBuilder.build());
}