use of com.zimbra.common.net.ProxyHostConfiguration in project zm-mailbox by Zimbra.
the class HttpProxyConfig method getProxyConfig.
public static ProxyHostConfiguration getProxyConfig(HostConfiguration hc, String uriStr) {
if (!LC.client_use_system_proxy.booleanValue())
return null;
URI uri = null;
try {
uri = new URI(uriStr);
} catch (URISyntaxException x) {
ZimbraLog.net.info(uriStr, x);
return null;
}
//no need to filter out localhost as the DefaultProxySelector will do that.
List<Proxy> proxies = ProxySelectors.defaultProxySelector().select(uri);
for (Proxy proxy : proxies) {
switch(proxy.type()) {
case DIRECT:
return null;
case HTTP:
InetSocketAddress addr = (InetSocketAddress) proxy.address();
if (ZimbraLog.net.isDebugEnabled()) {
ZimbraLog.net.debug("URI %s to use HTTP proxy %s", safePrint(uri), addr.toString());
}
ProxyHostConfiguration nhc = new ProxyHostConfiguration(hc);
nhc.setProxy(addr.getHostName(), addr.getPort());
if (proxy instanceof AuthProxy) {
nhc.setUsername(((AuthProxy) proxy).getUsername());
nhc.setPassword(((AuthProxy) proxy).getPassword());
}
return nhc;
//socks proxy can be handled at socket factory level
case SOCKS:
default:
continue;
}
}
return null;
}
Aggregations