@@ -344,7 +344,37 @@ static CloseableHttpClient getHttpsClient() throws Exception {
344344
345345 CloseableHttpClient httpClient ;
346346
347- if ( !UseProxy && ( ProxyHost == null || proxyUsername == null || proxyPassword == null ) ) {
347+ if ( UseProxy && ProxyHost != null ) {
348+
349+ HttpClientBuilder hcBuilder ;
350+ if (proxyUsername != null && proxyPassword != null ) {
351+ LogHelper .info (logger , "Setting up proxy to URL with Authentication: '%s://%s@%s:%d'" , Constants .PROXY_PROTOCOL , proxyUsername , ProxyHost , ProxyPort );
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+ LogHelper .info (logger , "Setting up proxy to URL: '%s://%s:%d'" , Constants .PROXY_PROTOCOL , ProxyHost , ProxyPort );
364+ hcBuilder = HttpClients .custom ()
365+ .setSSLSocketFactory (sslSocketFactory )
366+ .setDefaultRequestConfig (requestConfig )
367+ .setRedirectStrategy (new LaxRedirectStrategy ());
368+ }
369+
370+ HttpHost httpProxy = new HttpHost (ProxyHost , ProxyPort , Constants .PROXY_PROTOCOL );
371+ hcBuilder .setProxy (httpProxy );
372+
373+ httpClient = hcBuilder .build ();
374+
375+ proxySet = true ;
376+ }
377+ else {
348378 LogHelper .warn (logger , "Defaulting to non-proxy environment" );
349379
350380 httpClient = HttpClients .custom ()
@@ -353,30 +383,6 @@ static CloseableHttpClient getHttpsClient() throws Exception {
353383 .setRedirectStrategy (new LaxRedirectStrategy ())
354384 .build ();
355385 }
356-
357- else {
358-
359- 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 );
371-
372- HttpHost httpProxy = new HttpHost (ProxyHost , ProxyPort , Constants .PROXY_PROTOCOL );
373- DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner (httpProxy );
374- hcBuilder .setRoutePlanner (routePlanner );
375-
376- httpClient = hcBuilder .build ();
377-
378- proxySet = true ;
379- }
380386
381387 return httpClient ;
382388 } catch (Exception e ) {
0 commit comments