@@ -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