RESTEasy client framework authentication credentials

前端 未结 3 1833
谎友^
谎友^ 2020-12-08 03:32

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

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

How

3条回答
  •  生来不讨喜
    2020-12-08 03:52

    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);
    

提交回复
热议问题