客户端请求工厂RestEasy已被弃用...还有其他的RestEasy替代方案吗?

3
我需要创建rest-easy客户端,使用其他人创建的RestService接口... 这很好用,除了一个小问题...
当我从rest-easy 2.3.5.Final更新到rest-easy 3.0.x时,ClientRequestFactory类看起来像是@Deprecated。
实际代码如下:
ClientRequestFactory crf = new ClientRequestFactory(UriBuilder.fromUri("http://url-of-service").build());
SomeRestInterface client = crf.createProxy(SomeRestInterface.class);
client.theMethod();

现在,针对版本3.0.x的ClientRequestFactory,有没有rest-easy的替代方案呢?


1个回答

5

Resteasy客户端API已被标记为过时,因为JAX-RS标准化了一个客户端API。 您可以在文档中找到有关新客户端API的Resteasy集成的信息。

您的示例可能如下(未经测试):

Client client = ClientBuilder.newClient();
Response response = client.target("http://url-of-service").request().get();
// read and close the response

或者如果你想使用Resteasy代理框架:

Client client = ClientFactory.newClient();
ResteasyWebTarget target = (ResteasyWebTarget) client.target("http://url-of-service");
SomeRestInterface client = target.proxy(SomeRestInterface.class);
client.theMethod();

我需要做同样的事情,但我找不到ClientFactory,你是从哪个jar使用ClientFactory的?谢谢! :) - aurelius
不知道这个类是否在中间被重命名,但它应该是来自 JAX-RS 2.0 API 的 ClientBuilder。感谢提示,我已更新答案。 - lefloh
在3.0.x版本中,以下两行代码将被替换为什么? ClientResponse<List<Student>> response = request.get(new GenericType<List<Student>>(){}); List<Student> students = response.getEntity(); - user4821194
request#get 返回什么? - lefloh
现在没有请求对象。我想使用最新的API,旧的已经不相关了。我在这里更新了我的查询:http://stackoverflow.com/questions/36319394/what-should-we-use-for-clientresponse-and-generictype-in-latest-version-3-0-x,请指导。 - user4821194

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接