protected HttpClient buildClient ( ) { HttpClientBuilder builder = HttpClientBuilder . create ( ) . useSystemProperties ( ) . setConnectionManager ( connManager ) ; if ( ! isBlank ( username ) && ! isBlank ( password ) ) { final URI uri = URI . create ( url ) ; final CredentialsProvider credsProvider = new BasicCredentialsProvider ( ) ; credsProvider . setCredentials ( new AuthScope ( uri . getHost ( ) , uri . getPort ( ) ) , new UsernamePasswordCredentials ( username , password ) ) ; builder = builder . setDefaultCredentialsProvider ( credsProvider ) ; } return builder . build ( ) ; }
Setup authentication in httpclient .