}
protected HostConfiguration getHostConfiguration(HttpClient client,
MessageContext context,
URL targetURL) {
TransportClientProperties tcp =
TransportClientPropertiesFactory.create(targetURL.getProtocol()); // http or https
int port = targetURL.getPort();
boolean hostInNonProxyList =
isHostInNonProxyList(targetURL.getHost(), tcp.getNonProxyHosts());
HostConfiguration config = new HostConfiguration();
if (port == -1) {
if(targetURL.getProtocol().equalsIgnoreCase("https")) {
port = 443; // default port for https being 443
} else { // it must be http
port = 80; // default port for http being 80
}
}
if(hostInNonProxyList){
config.setHost(targetURL.getHost(), port, targetURL.getProtocol());
} else {
if (tcp.getProxyHost().length() == 0 ||
tcp.getProxyPort().length() == 0) {
config.setHost(targetURL.getHost(), port, targetURL.getProtocol());
} else {
if (tcp.getProxyUser().length() != 0) {
Credentials proxyCred =
new UsernamePasswordCredentials(tcp.getProxyUser(),
tcp.getProxyPassword());
// if the username is in the form "user\domain"
// then use NTCredentials instead.
int domainIndex = tcp.getProxyUser().indexOf("\\");
if (domainIndex > 0) {
String domain = tcp.getProxyUser().substring(0, domainIndex);
if (tcp.getProxyUser().length() > domainIndex + 1) {
String user = tcp.getProxyUser().substring(domainIndex + 1);
proxyCred = new NTCredentials(user,
tcp.getProxyPassword(),
tcp.getProxyHost(), domain);
}
}
client.getState().setProxyCredentials(AuthScope.ANY, proxyCred);
}
int proxyPort = new Integer(tcp.getProxyPort()).intValue();
config.setProxy(tcp.getProxyHost(), proxyPort);
}
}
return config;
}