From a7685b6edff5374ab5b6386226e7ce1a791f763b Mon Sep 17 00:00:00 2001 From: ash74268 Date: Mon, 19 Jul 2021 16:05:55 -0500 Subject: SDC Distribution Client proxy support to skip IP address lookup when proxy is configured Issue-ID: SDC-3613 Signed-off-by: ash74268 Change-Id: I7ef553b4daf35ef5213ae7287140537de9f06c26 --- .../org/onap/sdc/impl/DistributionClientImpl.java | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java index c372642..3a25abb 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java @@ -36,6 +36,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.apache.http.HttpHost; import org.onap.sdc.api.IDistributionClient; import org.onap.sdc.api.IDistributionStatusMessageJsonBuilder; import org.onap.sdc.api.consumer.IComponentDoneStatusMessage; @@ -706,9 +707,38 @@ public class DistributionClientImpl implements IDistributionClient { List msgBusAddresses = configuration.getMsgBusAddress(); if (msgBusAddresses.isEmpty()) { return Either.right(new DistributionClientResultImpl(DistributionActionResultEnum.CONF_MISSING_MSG_BUS_ADDRESS, "Message bus address was not found in the config file")); - } else { + } else if (getHttpProxyHost() == null && getHttpsProxyHost() == null) { + // If there is no proxy configured, convert to valid host name return GeneralUtils.convertToValidHostName(msgBusAddresses); - } + } else { + // skip the IP address lookup when proxy is configured and treat all + // hosts as valid + return Either.left(msgBusAddresses); + } + } + + private HttpHost getHttpProxyHost() { + HttpHost proxyHost = null; + if (configuration.isUseSystemProxy() && System.getProperty("http.proxyHost") != null + && System.getProperty("http.proxyPort") != null) { + proxyHost = new HttpHost(System.getProperty("http.proxyHost"), + Integer.valueOf(System.getProperty("http.proxyPort"))); + } else if (configuration.getHttpProxyHost() != null && configuration.getHttpProxyPort() != 0) { + proxyHost = new HttpHost(configuration.getHttpProxyHost(), configuration.getHttpProxyPort()); + } + return proxyHost; + } + + private HttpHost getHttpsProxyHost() { + HttpHost proxyHost = null; + if (configuration.isUseSystemProxy() && System.getProperty("https.proxyHost") != null + && System.getProperty("https.proxyPort") != null) { + proxyHost = new HttpHost(System.getProperty("https.proxyHost"), + Integer.valueOf(System.getProperty("https.proxyPort"))); + } else if (configuration.getHttpsProxyHost() != null && configuration.getHttpsProxyPort() != 0) { + proxyHost = new HttpHost(configuration.getHttpsProxyHost(), configuration.getHttpsProxyPort()); + } + return proxyHost; } -- cgit 1.2.3-korg