3

我需要使用其他人创建的 RestService 的 de 接口创建易于休息的客户端......这很好用,除了一件事......

当我从 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 替代方案是什么?

4

1 回答 1

6

Resteasy Client-API 已被标记为弃用,因为 JAX-RS 标准化了 Client-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();
于 2013-08-24T06:50:20.950 回答