jnorris jnorris - 1 month ago 7
HTTP Question

RESTEasy client framework authentication credentials

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?


Credentials can be provided by using ClientExecutor.

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

   ClientExecutor clientExecutor = new ApacheHttpClientExecutor(httpClient);

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