Skip to content

Commit 310c540

Browse files
author
Darin Howard
committed
RT-857 - adding in http proxy configuration via properties
1 parent 60293f9 commit 310c540

2 files changed

Lines changed: 12 additions & 21 deletions

File tree

src/main/java/com/stackify/api/common/http/HttpClient.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@ public class HttpClient {
6060
* Constructor
6161
* @param apiConfig API configuration
6262
*/
63-
public HttpClient(final ApiConfiguration apiConfig) {
64-
Preconditions.checkNotNull(apiConfig);
65-
this.apiConfig = apiConfig;
63+
public HttpClient(final ApiConfiguration apiConfig) {
64+
Preconditions.checkNotNull(apiConfig);
65+
this.apiConfig = apiConfig;
6666

6767
if (apiConfig.getHttpProxyHost() != null &&
6868
!apiConfig.getHttpProxyHost().isEmpty() &&
6969
apiConfig.getHttpProxyPort() != null &&
7070
!apiConfig.getHttpProxyPort().isEmpty()) {
71-
this.proxy = HttpProxy.build(apiConfig.getHttpProxyHost(), Integer.parseInt(apiConfig.getHttpProxyPort()));
71+
this.proxy = HttpProxy.build(apiConfig.getHttpProxyHost(), apiConfig.getHttpProxyPort());
7272
} else {
7373
this.proxy = HttpProxy.fromSystemProperties();
7474
}

src/main/java/com/stackify/api/common/http/HttpProxy.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.stackify.api.common.http;
1717

18-
import lombok.NonNull;
1918
import lombok.experimental.UtilityClass;
2019
import lombok.extern.slf4j.Slf4j;
2120

@@ -35,26 +34,18 @@ public class HttpProxy {
3534
* @return Proxy from system settings
3635
*/
3736
public static Proxy fromSystemProperties() {
38-
39-
try {
40-
String proxyHost = System.getProperty("https.proxyHost");
41-
String proxyPort = System.getProperty("https.proxyPort");
42-
43-
return build(proxyHost, Integer.parseInt(proxyPort));
44-
45-
} catch (Throwable t) {
46-
log.info("Unable to read HTTP proxy information from system properties", t);
47-
}
48-
49-
return Proxy.NO_PROXY;
37+
return build(System.getProperty("https.proxyHost"), System.getProperty("https.proxyPort"));
5038
}
5139

52-
public static Proxy build(@NonNull final String httpProxyHost,
53-
@NonNull final int httpProxyPort) {
40+
public static Proxy build(final String httpProxyHost,
41+
final String httpProxyPort) {
5442

5543
try {
56-
if (!httpProxyHost.isEmpty()) {
57-
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpProxyHost, httpProxyPort));
44+
if (httpProxyHost != null &&
45+
!httpProxyHost.isEmpty() &&
46+
httpProxyPort != null &&
47+
!httpProxyPort.isEmpty()) {
48+
return new Proxy(Proxy.Type.HTTP, new InetSocketAddress(httpProxyHost, Integer.parseInt(httpProxyPort)));
5849
}
5950
} catch (Throwable t) {
6051
log.info("Unable to read HTTP proxy information from system properties", t);

0 commit comments

Comments
 (0)