Skip to content

Commit 906de61

Browse files
committed
+ Fixing naming convention
+ Scenarios covered for proxy setting with auth
1 parent 36afd75 commit 906de61

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

src/main/java/net/authorize/util/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public final class Constants {
66
public static final String HTTPS_USE_PROXY = "https.proxyUse";
77
public static final String HTTPS_PROXY_HOST = "https.proxyHost";
88
public static final String HTTPS_PROXY_PORT = "https.proxyPort";
9-
public static final String HTTPS_PROXY_USERNAME = "https.proxyUser";
9+
public static final String HTTPS_PROXY_USERNAME = "https.proxyUsername";
1010
public static final String HTTPS_PROXY_PASSWORD = "https.proxyPassword";
1111

1212
public static final String HTTP_USE_PROXY = "http.proxyUse";

src/main/java/net/authorize/util/HttpClient.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -344,39 +344,44 @@ static CloseableHttpClient getHttpsClient() throws Exception {
344344

345345
CloseableHttpClient httpClient;
346346

347-
if ( !UseProxy && ( ProxyHost == null || proxyUsername == null || proxyPassword == null ) ) {
348-
LogHelper.warn(logger, "Defaulting to non-proxy environment");
349-
350-
httpClient = HttpClients.custom()
351-
.setSSLSocketFactory(sslSocketFactory)
352-
.setDefaultRequestConfig(requestConfig)
353-
.setRedirectStrategy(new LaxRedirectStrategy())
354-
.build();
355-
}
356-
357-
else {
347+
if ( UseProxy && ProxyHost != null) {
358348

359349
LogHelper.info(logger, "Setting up proxy to URL: '%s://%s:%d'", Constants.PROXY_PROTOCOL, ProxyHost, ProxyPort);
360-
CredentialsProvider credsProvider = new BasicCredentialsProvider();
361-
362-
AuthScope proxyScope = new AuthScope(ProxyHost, ProxyPort);
363-
Credentials proxyCreds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
364-
credsProvider.setCredentials(proxyScope, proxyCreds);
365-
366-
HttpClientBuilder hcBuilder = HttpClients.custom()
367-
.setSSLSocketFactory(sslSocketFactory)
368-
.setDefaultRequestConfig(requestConfig)
369-
.setRedirectStrategy(new LaxRedirectStrategy())
370-
.setDefaultCredentialsProvider(credsProvider);
350+
HttpClientBuilder hcBuilder;
351+
if (proxyUsername != null && proxyPassword != null) {
352+
CredentialsProvider credsProvider = new BasicCredentialsProvider();
353+
AuthScope proxyScope = new AuthScope(ProxyHost, ProxyPort);
354+
Credentials proxyCreds = new UsernamePasswordCredentials(proxyUsername, proxyPassword);
355+
credsProvider.setCredentials(proxyScope, proxyCreds);
356+
hcBuilder = HttpClients.custom()
357+
.setSSLSocketFactory(sslSocketFactory)
358+
.setDefaultRequestConfig(requestConfig)
359+
.setRedirectStrategy(new LaxRedirectStrategy())
360+
.setDefaultCredentialsProvider(credsProvider);
361+
}
362+
else {
363+
hcBuilder = HttpClients.custom()
364+
.setSSLSocketFactory(sslSocketFactory)
365+
.setDefaultRequestConfig(requestConfig)
366+
.setRedirectStrategy(new LaxRedirectStrategy());
367+
}
371368

372369
HttpHost httpProxy = new HttpHost(ProxyHost, ProxyPort, Constants.PROXY_PROTOCOL);
373-
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(httpProxy);
374-
hcBuilder.setRoutePlanner(routePlanner);
370+
hcBuilder.setProxy(httpProxy);
375371

376372
httpClient = hcBuilder.build();
377373

378374
proxySet = true;
379-
}
375+
}
376+
else {
377+
LogHelper.warn(logger, "Defaulting to non-proxy environment");
378+
379+
httpClient = HttpClients.custom()
380+
.setSSLSocketFactory(sslSocketFactory)
381+
.setDefaultRequestConfig(requestConfig)
382+
.setRedirectStrategy(new LaxRedirectStrategy())
383+
.build();
384+
}
380385

381386
return httpClient;
382387
} catch (Exception e) {

0 commit comments

Comments
 (0)