ClientRequestFactory RestEasy Deprecated… Any othe

2019-04-14 05:12发布

问题:

I need to create rest-easy client, using de interface of the RestService created by others... That's work good, except by just one thing...

When i update from rest-easy 2.3.5.Final to rest-easy 3.0.x, the ClientRequestFactory class appear like @Deprecated.

The actual code is:

ClientRequestFactory crf = new ClientRequestFactory(UriBuilder.fromUri("http://url-of-service").build());
SomeRestInterface client = crf.createProxy(SomeRestInterface.class);
client.theMethod();

Any one, now what is the alternative of rest-easy for ClientRequestFactory at version 3.0.x?

回答1:

Resteasy Client-API has been marked deprecated as JAX-RS standardized a Client-API. You can find information about the Resteasy-integration of the new Client-API in the documentation.

Your example could look like (untested):

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

Or if you want to use Resteasy Proxy Framework:

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