users@jersey.java.net

Re: [Jersey] Generating WS client based on reflection

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 01 Dec 2009 10:25:23 +0100

Hi Jean,

A proxy-based client-side solution has been discussed, but there is
nothing implemented in Jersey to support this. Notably, Gerard
Davidson has some ideas in this area.

My opinion is that such proxies, as you present, unduly encourages the
coupling of the client to the server and it really does not give much
over utilizing the Jersey client API as of today, for example:

  Client c = Client.create();
  URI u = ...
  UriBuilder ub = UriBuilder.fromUri(u).path("product/{id}");

  ProductConverter pc =
c.resource(ub.build(1)).get(ProductConverter.class);
  c.resource(ub.build(2)).put(new ProductConverter());

Or creating a simple ProductResource class that encapsulates the
above. Note that in your ProductResource interface there is no way the
client can distinguish between XML or JSON.

I think the main advantage to any proxy-based solution is in terms of
documentation and especially when utilized with IDEs.

What i would really like to see is a focus on proxy-based solutions
for *representations* supporting typed links. That IMHO is the right
place for proxying or even static code generation as the media types
and link types are important types for hypermedia processing. There
has been some nice work w.r.t. in Ruby:

http://www.infoq.com/news/2009/11/restfulie-hypermedia-services

Any exploration of the client area also needs to be coupled with
solutions on the server-side for supporting typed links.

Paul.

On Dec 1, 2009, at 3:14 AM, Jean Aurambault wrote:

> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>