stackoverflower
stackoverflower

Reputation: 4063

What is the alternative to ClientResponse in Resteasy 3 and above?

I am currently working with Resteasy 2.3.6.Final and want to upgrade to Resteasy 3.0.4.Final. However, the API doc indicates that the class is now deprecated. So my questions are:

  1. What is the reason that ClientResponse is deprecated? Is this to do with the fact that JAX-RS 2.0 was introduced in Resteasy 3+?
  2. What is the recommended return type of Resteasy resources now? I read the user doc, and in section 47.2 there are some examples. It suggested using javax.ws.rs.core.Response if you want to get everything back, but this will remove the generic parameter. How do I keep the generic parameter?

Thanks for any help.

Edit 1

Here is an example of what I am talking about.

I currently some code like this:

   @GET
   @Path("matrixParam")
   @Produces("application/json")
   ClientResponse<Matrix> getMatrix(@MatrixParam("param")String param);

ClientResponse takes in a generic parameter. If I use Response instead, then it would become:

   @GET
   @Path("matrixParam")
   @Produces("application/json")
   Response getMatrix(@MatrixParam("param")String param);

And the generic parameter is removed. This would be inconvenient because the caller needs to know what type the returned object is.

Edit 2

The answer from Pascal and the book Restful Java with JAX-RS 2.0 both say that the generic parameter is no longer needed because the interface methods can return the desired type directly. Thanks Pascal for answering.

Upvotes: 3

Views: 2102

Answers (1)

Pascal Rodriguez
Pascal Rodriguez

Reputation: 1091

You don't need the generic parameter anymore as you can directly use your own type in the client interface method like this:

    @GET
    @Path("matrixParam")
    @Produces("application/json")
    Matrix getMatrix(@MatrixParam("param")String param);

And to query the remote service you can use the resteasy client proxy framework:

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://host/path");
    ResteasyWebTarget rsWebTarget = (ResteasyWebTarget)target;
    SimpleMatrixClient simple = rsWebTarget.proxy(SimpleMatrixClient.class);
    Matrix m = simple.getMatrix("myMatrixParamValue");

Upvotes: 2

Related Questions