From b2a12f09e4186b7c7f6eee2ea8c6d7a59066e422 Mon Sep 17 00:00:00 2001 From: madhawap Date: Tue, 15 May 2018 13:23:41 +0530 Subject: [PATCH] Make proxy configuration optional As per the current configurations it is mandatory to set a value for http.nonProxyHosts property in order to server to run on 'change-ip' mode. With this modification it is made optional where even without this property IoT server can be run on 'change-ip' mode. 'Change-ip' mode is where server is configured to run on a different IP other than localhost --- .../apimgt/integration/client/util/Utils.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/util/Utils.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/util/Utils.java index d42baf2c43..85004efd69 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/util/Utils.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.integration.client/src/main/java/org/wso2/carbon/apimgt/integration/client/util/Utils.java @@ -71,6 +71,10 @@ public class Utils { private static final String SSLV3 = "SSLv3"; + private static final String DEFAULT_HOST = "localhost"; + + private static final String DEFAULT_HOST_IP = "127.0.0.1"; + //This method is only used if the mb features are within DAS. public static String replaceProperties(String text) { @@ -98,19 +102,22 @@ public class Utils { final ProxySelector proxySelector = new ProxySelector() { @Override - public java.util.List select(final URI uri) { - final List proxyList = new ArrayList(1); - - final String host = uri.getHost(); - - if (host.startsWith("127.0.0.1") || host.startsWith("localhost") || StringUtils.contains - (nonProxyHostsValue, host)) { - proxyList.add(Proxy.NO_PROXY); + public java.util.List select(URI uri) { + List proxyList = new ArrayList<>(); + String host = uri.getHost(); + + if (!StringUtils.isEmpty(host)) { + if (host.startsWith(DEFAULT_HOST_IP) || host.startsWith(DEFAULT_HOST) || StringUtils + .isEmpty(nonProxyHostsValue) || StringUtils.contains(nonProxyHostsValue, host) || + StringUtils.isEmpty(proxyHost) || StringUtils.isEmpty(proxyPort)) { + proxyList.add(Proxy.NO_PROXY); + } else { + proxyList.add(new Proxy(Proxy.Type.HTTP, + new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)))); + } } else { - proxyList.add(new Proxy(Proxy.Type.HTTP, - new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)))); + log.error("Host is null. Host could not be empty or null"); } - return proxyList; }