title: Spring 4.0.0 basic authentication with RestTemplate
body: <p>I am currently working on integration of a third party application with our local reporting system. I would like to implement REST calls with basic authentication but facing issues in Spring 4.0.0. I have a simple solution what works nicely:</p>
  
  <pre><code>final RestTemplate restTemplate = new RestTemplate();
  final String plainCreds = "username:password";
  final byte[] plainCredsBytes = plainCreds.getBytes();
  final byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes);
  final String base64Creds = new String(base64CredsBytes);
  
  final HttpHeaders headers = new HttpHeaders();
  headers.add("Authorization", "Basic " + base64Creds);
  final HttpEntity&lt;String&gt; request = new HttpEntity&lt;String&gt;(headers);
  
  final ResponseEntity&lt;MyDto&gt; response = restTemplate.exchange("myUrl", HttpMethod.GET, request, MyDto.class);
  final MyDto dot = response.getBody();
  </code></pre>
  
  <p>but wanted to rewrite this to use <strong>ClientHttpRequestFactory</strong> in the following way:</p>
  
  <pre><code>final RestTemplate restTemplate = new RestTemplate(createSecureTransport("username", "password"));
  
  private ClientHttpRequestFactory createSecureTransport(final String username, final String password) {
      final HttpClient client = new HttpClient();
      final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(username, password);
      client.getState().setCredentials(new AuthScope(null, 9090, AuthScope.ANY_REALM), credentials);
      return new CommonsClientHttpRequestFactory(client);
  }
  </code></pre>
  
  <p>This code is not compiling as the <strong>CommonsClientHttpRequestFactory</strong> class not exists anymore in Spring 4.0.0. Do somebody know any alternative solution to this? I am quite new in this REST world therefore any help will be appreciated. </p>