URLConnection connection;
if (url.getProtocol().equalsIgnoreCase("http") ||
url.getProtocol().equalsIgnoreCase("https")) {
Properties synapseProperties = SynapsePropertiesLoader.loadSynapseProperties();
String proxyHost = synapseProperties.getProperty(
SynapseConstants.SYNPASE_HTTP_PROXY_HOST);
String proxyPort = synapseProperties.getProperty(
SynapseConstants.SYNPASE_HTTP_PROXY_PORT);
// get the list of excluded hosts for proxy
List<String> excludedHosts = getExcludedHostsForProxy(synapseProperties);
if (proxyHost != null && proxyPort != null && !excludedHosts.contains(proxyHost)) {
SocketAddress sockaddr = new InetSocketAddress(
proxyHost, Integer.parseInt(proxyPort));
Proxy proxy = new Proxy(Proxy.Type.HTTP, sockaddr);
if (url.getProtocol().equalsIgnoreCase("https")) {
connection = getHttpsURLConnection(url, synapseProperties, proxy);
} else {
connection = url.openConnection(proxy);
}
} else {
if (url.getProtocol().equalsIgnoreCase("https")) {
connection = getHttpsURLConnection(url, synapseProperties, null);
} else {
connection = url.openConnection();
}
}
// try to see weather authentication is required
String userName = synapseProperties.getProperty(
SynapseConstants.SYNPASE_HTTP_PROXY_USER);
String password = synapseProperties.getProperty(
SynapseConstants.SYNPASE_HTTP_PROXY_PASSWORD);
if (userName != null && password != null) {
String header = userName + ":" + password;
byte[] encodedHeaderBytes = new Base64().encode(header.getBytes());
String encodedHeader = new String(encodedHeaderBytes);