RESTEasy Client Proxy Overhead?

依然范特西╮ 提交于 2019-11-30 05:22:36

You can specify MyClass client as a spring bean, for instance, and inject it wherever it's needed. Be aware of thread safety because the RestEasy proxy client uses underneath the Apache Commons Http Client and as default the SimpleHttpConnectionManager which is not thread safe.

To achieve this in a multithreaded enironment(running in a Servlet Container) do this:

MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();
HttpClient httpClient = new HttpClient(connectionManager);

// Only needed if you have a authentication
Credentials credentials = new UsernamePasswordCredentials(username, password);
httpClient.getState().setCredentials(AuthScope.ANY, credentials);
httpClient.getParams().setAuthenticationPreemptive(true);

clientExecutor = new ApacheHttpClientExecutor(httpClient);

MyClass client = ProxyFactory.create(MyClass.class, "http://localhost:8080", clientExecutor);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!