本文介绍了RESTEasy客户端框架身份验证凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
RESTEasy(一个JAX-RS实现)有一个很好的客户端框架,例如:
RESTEasy (a JAX-RS implementation) has a nice client framework, eg:
ServiceApi client = ProxyFactory.create(ServiceApi.class, baseUri);
如何向此客户提供HTTP身份验证凭据?
How do you provide HTTP authentication credentials to this client?
推荐答案
可以使用ClientExecutor提供凭证。
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);
这篇关于RESTEasy客户端框架身份验证凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!