@@ -636,49 +636,48 @@ private static HttpClientBuilder setupProxy(HttpClientBuilder httpClientbuilder,
636636 }
637637
638638 private static HttpClientBuilder useLegacyProxyConfiguration (HttpClientBuilder httpClientbuilder , SplitClientConfig config ) {
639- HttpHost proxyHost ;
640- String userName = null ;
641- String password = null ;
642- proxyHost = config .proxy ();
639+ HttpHost proxyHost = config .proxy ();
640+ httpClientbuilder = addProxyHost (httpClientbuilder , proxyHost );
643641 if (config .proxyUsername () != null && config .proxyPassword () != null ) {
644- userName = config .proxyUsername ();
645- password = config .proxyPassword ();
642+ return addProxyBasicAuth (httpClientbuilder , proxyHost , config .proxyUsername (), config .proxyPassword ());
646643 }
647- return addProxyParams (httpClientbuilder , proxyHost , userName , password );
644+
645+ return httpClientbuilder ;
648646 }
649647
650648 private static HttpClientBuilder useProxyConfiguration (HttpClientBuilder httpClientbuilder , SplitClientConfig config ) {
651- HttpHost proxyHost ;
652- String userName = null ;
653- String password = null ;
654- proxyHost = config .proxyConfiguration ().getHost ();
655- if (config .proxyConfiguration ().getProxyCredentialsProvider () != null ) {
656- if (config .proxyConfiguration ().getProxyCredentialsProvider () instanceof io .split .client .dtos .BasicCredentialsProvider ) {
657- io .split .client .dtos .BasicCredentialsProvider basicAuth =
658- (io .split .client .dtos .BasicCredentialsProvider ) config .proxyConfiguration ().getProxyCredentialsProvider ();
659- userName = basicAuth .getUsername ();
660- password = basicAuth .getPassword ();
661- } else if (config .proxyConfiguration ().getProxyCredentialsProvider () instanceof io .split .client .dtos .BearerCredentialsProvider ) {
662- _log .debug ("Proxy setup using Bearer token" );
663- httpClientbuilder .setDefaultCredentialsProvider (new HttpClientDynamicCredentials (
664- (BearerCredentialsProvider ) config .proxyConfiguration ().getProxyCredentialsProvider ()));
665- }
649+ HttpHost proxyHost = config .proxyConfiguration ().getHost ();
650+ httpClientbuilder = addProxyHost (httpClientbuilder , proxyHost );
651+ if (config .proxyConfiguration ().getProxyCredentialsProvider () == null ) {
652+ return httpClientbuilder ;
666653 }
667- return addProxyParams (httpClientbuilder , proxyHost , userName , password );
654+
655+ if (config .proxyConfiguration ().getProxyCredentialsProvider () instanceof io .split .client .dtos .BasicCredentialsProvider ) {
656+ io .split .client .dtos .BasicCredentialsProvider basicAuth =
657+ (io .split .client .dtos .BasicCredentialsProvider ) config .proxyConfiguration ().getProxyCredentialsProvider ();
658+ return addProxyBasicAuth (httpClientbuilder , proxyHost , basicAuth .getUsername (), basicAuth .getPassword ());
659+ }
660+
661+ _log .debug ("Proxy setup using Bearer token" );
662+ httpClientbuilder .setDefaultCredentialsProvider (new HttpClientDynamicCredentials (
663+ (BearerCredentialsProvider ) config .proxyConfiguration ().getProxyCredentialsProvider ()));
664+ return httpClientbuilder ;
668665 }
669666
670- private static HttpClientBuilder addProxyParams (HttpClientBuilder httpClientbuilder , HttpHost proxyHost , String userName , String password ) {
667+ private static HttpClientBuilder addProxyHost (HttpClientBuilder httpClientbuilder , HttpHost proxyHost ) {
671668 DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner (proxyHost );
672669 httpClientbuilder .setRoutePlanner (routePlanner );
673- if (userName != null && password != null ) {
674- _log .debug ("Proxy setup using Basic authentication" );
675- BasicCredentialsProvider credsProvider = new BasicCredentialsProvider ();
676- AuthScope siteScope = new AuthScope (proxyHost .getHostName (), proxyHost .getPort ());
677- Credentials siteCreds = new UsernamePasswordCredentials (userName ,
678- password .toCharArray ());
679- credsProvider .setCredentials (siteScope , siteCreds );
680- httpClientbuilder .setDefaultCredentialsProvider (credsProvider );
681- }
670+ return httpClientbuilder ;
671+ }
672+
673+ private static HttpClientBuilder addProxyBasicAuth (HttpClientBuilder httpClientbuilder , HttpHost proxyHost , String userName , String password ) {
674+ _log .debug ("Proxy setup using Basic authentication" );
675+ BasicCredentialsProvider credsProvider = new BasicCredentialsProvider ();
676+ AuthScope siteScope = new AuthScope (proxyHost .getHostName (), proxyHost .getPort ());
677+ Credentials siteCreds = new UsernamePasswordCredentials (userName ,
678+ password .toCharArray ());
679+ credsProvider .setCredentials (siteScope , siteCreds );
680+ httpClientbuilder .setDefaultCredentialsProvider (credsProvider );
682681 return httpClientbuilder ;
683682 }
684683
0 commit comments