Skip to content

Commit 5274f2b

Browse files
committed
fixed bug in findProxyUrl with non_proxy where empty system property was not detected
1 parent 1d4d269 commit 5274f2b

File tree

2 files changed

+31
-27
lines changed
  • imagetool/src

2 files changed

+31
-27
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/util/Utils.java

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -450,36 +450,39 @@ private static List<String> getDockerRunCmd(String builder, String scriptToRun,
450450
* @return proxy url for given protocol
451451
*/
452452
public static String findProxyUrl(String proxyUrl, String protocol) {
453-
String retVal = proxyUrl;
454-
if (isEmptyString(retVal) && !isEmptyString(protocol)) {
455-
switch (protocol.toLowerCase()) {
456-
case Constants.HTTP:
457-
case Constants.HTTPS:
458-
String envVarName = String.format("%s_proxy", protocol);
459-
retVal = getProxyEnvironmentVariableValue(envVarName);
460-
if (isEmptyString(retVal)) {
461-
String proxyHost = System.getProperty(String.format("%s.proxyHost", protocol), null);
462-
String proxyPort = System.getProperty(String.format("%s.proxyPort", protocol), "80");
463-
if (proxyHost != null) {
464-
retVal = String.format("%s://%s:%s", protocol, proxyHost, proxyPort);
465-
}
453+
if (!isEmptyString(proxyUrl)) {
454+
return proxyUrl;
455+
}
456+
String result;
457+
switch (protocol.toLowerCase()) {
458+
case Constants.HTTP:
459+
case Constants.HTTPS:
460+
String envVarName = String.format("%s_proxy", protocol);
461+
result = getProxyEnvironmentVariableValue(envVarName);
462+
if (isEmptyString(result)) {
463+
String proxyHost = System.getProperty(String.format("%s.proxyHost", protocol), null);
464+
String proxyPort = System.getProperty(String.format("%s.proxyPort", protocol), "80");
465+
if (proxyHost != null) {
466+
result = String.format("%s://%s:%s", protocol, proxyHost, proxyPort);
466467
}
467-
break;
468-
case "none":
469-
default:
470-
retVal = getProxyEnvironmentVariableValue("no_proxy");
471-
if (isEmptyString(retVal)) {
472-
retVal = System.getProperty("http.nonProxyHosts", null);
473-
if (!isEmptyString(retVal)) {
474-
//http.nonProxyHosts property uses | instead of , as a separator
475-
retVal = retVal.replace("|", ",");
476-
}
468+
}
469+
break;
470+
case "none":
471+
default:
472+
result = getProxyEnvironmentVariableValue("no_proxy");
473+
if (isEmptyString(result)) {
474+
String propertyValue = System.getProperty("http.nonProxyHosts", null);
475+
if (isEmptyString(propertyValue)) {
476+
result = null;
477+
} else {
478+
//http.nonProxyHosts property uses | instead of , as a separator
479+
result = propertyValue.replace("|", ",");
477480
}
478-
break;
479-
}
481+
}
482+
break;
480483
}
481-
logger.finer("Discovered proxy setting ({0}): {1}", protocol, retVal);
482-
return retVal;
484+
logger.finer("Discovered proxy setting ({0}): {1}", protocol, result);
485+
return result;
483486
}
484487

485488
/**

imagetool/src/test/java/com/oracle/weblogic/imagetool/util/UtilsTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void findProxyUrlForNoProxy() {
204204
// No ENV variable set (filed issue on SystemStub)
205205
environment.set("no_proxy", null);
206206
environment.set("NO_PROXY", null);
207+
overrideProperties.set("http.nonProxyHosts", "");
207208
assertNull(Utils.findProxyUrl("", "none"));
208209

209210
String expected = ".host.com,.anotherhost.com,.and.another.com";

0 commit comments

Comments
 (0)