Skip to content

Commit 54e9ad6

Browse files
authored
Use system settings proxy for Apache HttpClientBuilder (#330)
* remove explicit setting of Apache HTTP client proxy values that caused nonProxyHosts value to get ignored * allow override of ARU host
1 parent 0e329e6 commit 54e9ad6

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

imagetool/src/main/java/com/oracle/weblogic/imagetool/cli/menu/CommonOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public String buildId() {
281281
names = {"--fromImage"},
282282
paramLabel = FROM_IMAGE_LABEL,
283283
description = "Docker image to use as base image. Default: ${DEFAULT-VALUE}",
284-
defaultValue = "ghcr.io/oracle/oraclelinux:8-slim"
284+
defaultValue = Constants.ORACLE_LINUX
285285
)
286286
private String fromImage;
287287

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55

66
public final class Constants {
77

8-
public static final String ARU_REST_URL = "https://updates.oracle.com/Orion/Services";
8+
public static final String ARU_UPDATES_HOST =
9+
Utils.getEnvironmentProperty("WLSIMG_ARU_HOST", "updates.oracle.com");
10+
public static final String ARU_REST_URL = "https://" + ARU_UPDATES_HOST + "/Orion/Services";
911
public static final String REL_URL = ARU_REST_URL + "/metadata?table=aru_releases";
1012
public static final String RECOMMENDED_PATCHES_URL = ARU_REST_URL
1113
+ "/search?patch_type=all&life_cycle=Recommended&product=%s&release=%s";
1214
public static final String ARU_LANG_URL = ARU_REST_URL + "/metadata?table=aru_languages";
1315
public static final String CONFLICTCHECKER_URL = ARU_REST_URL + "/conflict_checks";
14-
public static final String GET_LSINVENTORY_URL = ARU_REST_URL + "/get_inventory_upi";
1516
public static final String CACHE_DIR_KEY = "cache.dir";
1617
public static final String DEFAULT_WLS_VERSION = "12.2.1.3.0";
1718
public static final String DEFAULT_JDK_VERSION = "8u202";
@@ -22,6 +23,7 @@ public final class Constants {
2223
public static final String PATCH_ID_REGEX = "^(\\d{8})(?:[_][0-9][0-9](?:\\.[0-9]){3,8}\\.(\\d+))?";
2324
public static final String RIGID_PATCH_ID_REGEX = "^(\\d{8})[_][0-9][0-9](?:\\.[0-9]){3,8}\\.(\\d+)";
2425
public static final String BUSYBOX = "busybox";
26+
public static final String ORACLE_LINUX = "ghcr.io/oracle/oraclelinux:8-slim";
2527

2628
private Constants() {
2729
//restrict access

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ public static HttpClient getOraClient(String userId, String password) {
120120

121121
CookieStore cookieStore = new BasicCookieStore();
122122

123-
String proxyHost = System.getProperty("https.proxyHost");
124-
String proxyPort = System.getProperty("https.proxyPort");
125-
HttpClient result;
126-
127123
HttpClientBuilder builder = HttpClientBuilder.create()
128124
.setDefaultRequestConfig(config.build())
129125
.setRetryHandler(retryHandler())
@@ -137,13 +133,7 @@ public static HttpClient getOraClient(String userId, String password) {
137133
builder.setDefaultCredentialsProvider(credentialsProvider);
138134
}
139135

140-
if (proxyHost != null) {
141-
// credentials are set in the getHttpExecutor
142-
builder.setProxy(new HttpHost(proxyHost, Integer.parseInt(proxyPort)));
143-
}
144-
145-
result = builder.build();
146-
136+
HttpClient result = builder.useSystemProperties().build();
147137
logger.exiting();
148138
return result;
149139
}
@@ -171,7 +161,7 @@ public static Executor getHttpExecutor(String supportUserName, String supportPas
171161

172162
executor
173163
.auth(new HttpHost("login.oracle.com", 443), supportUserName, supportPassword)
174-
.auth(new HttpHost("updates.oracle.com", 443), supportUserName, supportPassword)
164+
.auth(new HttpHost(Constants.ARU_UPDATES_HOST, 443), supportUserName, supportPassword)
175165
.authPreemptiveProxy(new HttpHost(proxyHost, Integer.parseInt(proxyPort)));
176166
}
177167
return executor;

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ public static String findProxyUrl(String proxyUrl, String protocol) {
476476
break;
477477
}
478478
}
479+
logger.finer("Discovered proxy setting ({0}): {1}", protocol, retVal);
479480
return retVal;
480481
}
481482

@@ -510,13 +511,17 @@ public static String getPasswordFromInputs(String passwordStr, Path passwordFile
510511
* Java properties.
511512
*
512513
* @param name the name of the environment variable, or Java property
514+
* @param defaultValue if no environment variable is defined, nor system property, return this value
513515
* @return the value defined in the env or system property
514516
*/
515-
public static String getEnvironmentProperty(String name) {
517+
public static String getEnvironmentProperty(String name, String defaultValue) {
516518
String result = System.getenv(name);
517519
if (isEmptyString(result)) {
518520
result = System.getProperty(name);
519521
}
522+
if (isEmptyString(result)) {
523+
return defaultValue;
524+
}
520525
return result;
521526
}
522527

@@ -526,10 +531,7 @@ public static String getEnvironmentProperty(String name) {
526531
* @return working directory
527532
*/
528533
public static String getBuildWorkingDir() throws IOException {
529-
String workingDir = getEnvironmentProperty("WLSIMG_BLDDIR");
530-
if (workingDir == null) {
531-
workingDir = System.getProperty("user.home");
532-
}
534+
String workingDir = getEnvironmentProperty("WLSIMG_BLDDIR", System.getProperty("user.home"));
533535
Path path = Paths.get(workingDir);
534536

535537
boolean pathExists = Files.exists(path, LinkOption.NOFOLLOW_LINKS);

0 commit comments

Comments
 (0)