title: RESTEasy Client Proxy Preemptive Basic Authentication
body: <p>I am using <code>RESTEasy Proxy Framework</code> to call my Rest-Services. I would like to use preemptive authentication with the proxy framework. </p>
  
  <p>Thats my current Code:</p>
  
  <pre><code>public void callSomeService() throws Exception {
  
      RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
  
      DefaultHttpClient client = new DefaultHttpClient();
      UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
              USERNAME, PASSWORD);
      AuthScope authscope = new AuthScope(AuthScope.ANY_HOST,
              AuthScope.ANY_PORT, AuthScope.ANY_REALM);
      client.getCredentialsProvider().setCredentials(authscope, credentials);
      ApacheHttpClient4Executor executer = new ApacheHttpClient4Executor(client);
      dummyResource = ProxyFactory.create(DummyResource.class,
              "http://localhost:8888/myapp/rest/", executer);
  
      // Do some calls here       
  }
  </code></pre>
  
  <p>When I monitor the traffic of my application, the Rest-Service gets called twice:</p>
  
  <ol>
  <li>First the client receives an 401 Error (UNAUTHORIZED) </li>
  <li>In the second request there is the Authorization Header added and everything works
  fine.</li>
  </ol>
  
  <p><strong>What I actually want to do is that the Authorization Header is already added in the first request! How can I do that?</strong></p>
  
  <p>I am using RESTEasy 2.3.5! I also read the documentation (<a href="http://docs.jboss.org/resteasy/docs/2.3.5.Final/userguide/html_single/index.html#transport_layer" rel="nofollow">http://docs.jboss.org/resteasy/docs/2.3.5.Final/userguide/html_single/index.html#transport_layer</a>) where is an example given for preemptive authentication, which actually doesnt work, because of this code:</p>
  
  <pre><code>BasicScheme basicAuth = new BasicScheme();
  authCache.put("com.bluemonkeydiamond.sippycups", basicAuth);
  </code></pre>