views:

425

answers:

1

RESTEasy (a JAX-RS implementation) has a nice client framework, eg:

ServiceApi client = ProxyFactory.create(ServiceApi.class, baseUri);

How do you provide HTTP authentication credentials to this client?

+1  A: 

Credentials can be provided by using ClientExecutor.

   Credentials credentials = new UsernamePasswordCredentials(userId, password);
   HttpClient httpClient = new HttpClient();
   httpClient.getState().setCredentials(AuthScope.ANY, credentials);
   httpClient.getParams().setAuthenticationPreemptive(true);

   ClientExecutor clientExecutor = new ApacheHttpClientExecutor(httpClient);

   ServiceApi client = ProxyFactory.create(ServiceApi.class, baseUri, clientExecutor);
jnorris