jnorris jnorris - 1 year ago 141
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?

Answer Source

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download