users@jersey.java.net

Generating WS client based on reflection

From: Jean Aurambault <aurambaj_at_yahoo-inc.com>
Date: Mon, 30 Nov 2009 18:14:28 -0800

Hi,

I'm thinking about a way of generating automatically clients for a WS
based on reflection. Could be by sharing the WS definition in an
interface or even using directly a jersey annotated class... Let's say
with an interface it would be something like this:

public interface ProductResource {

    @Path("/product/{id}")
    @GET
    @Produces({"application/xml", "application/json"})
    public ProductConverter get(@PathParam("id") int id);

    @Path("/product/{id}")
    @PUT
    @Consumes({"application/xml", "application/json"})
    public void put(@PathParam("id") int id, ProductConverter
productConverter);
}

the server would implement the interface

public class ProductResourceServerImpl implements ProductResource {
    ...
}

And on the client side having something like this:

Client client = new Client();
ProductResource pr = client.resource(ProductResource.class);
ProductConverter product = pr.get(1);
pr.put(2, new ProductConverter());

Is there anything close to this available? Any thoughts?

best regards,

Jean