users@jersey.java.net

Re: [Jersey] Client java stubs with Jersey

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 02 Sep 2009 09:59:38 +0200

On Sep 2, 2009, at 9:31 AM, xworker wrote:
>
> Hi
>
> I'm using Jersery for ws in my project. I've got a JPA backend with
> lots of
> entitys. Question:
>
> How do I generate java POJO stubs from my Jersey ws? For SOAP I was
> able to
> generate client-side stubs, but not for REST?

I advise against creating Java client stubs from Java server artifacts
because they make a tight coupling between client and server-side code
(but see later).


>
> Frontend is a backingbean with JSF pages.
>
> <code>
> wr =
> client.resource("http://localhost:8080/pe-backend/resources/
> activities");
> activityList = wr.get(new GenericType<List<Activity>>() {
> });
> </code>
>
> How shouold my backingbean know what Activity is?
>

Human readable documentation of the service to be read by the
developer. Because the client is separated from the server you can
also do:

   wr = client.resource("http://localhost:8080/pe-backend/resources/activities
");
   activityArray = wr.get(Activity[].class);

or perhaps use a different version of Activity (JAXB is somewhat
flexible in terms of consuming documents with additional XML it does
not understand). Or use some XPath on DOM.

WADL can be used to help create the human readable documentation that
can be served as part of the service. Jersey dynamically creates a
WADL description of the service, see also here:

   http://wikis.sun.com/display/Jersey/WADL

If you really want static client stubs you could use the wadl2java
facility available from:

   https://wadl.dev.java.net/

Paul.