users@jersey.java.net

Re: Re: [Jersey] Client java stubs with Jersey

From: gerard davison <gerard.davison_at_oracle.com>
Date: Thu, 03 Sep 2009 13:46:40 +0100

Paul,

I can understand the desire for loose coupling; but from a tools
developer perspective almost the first thing people ask for is the
ability to generate some kind of static java interface for a given WADL.
I can see the argument against it; but in many cases your "basic
work-a-day" developer is not going to understand the finer distinctions
in REST and wants a simple API to program against. This is the same
thing we see with JAX-WS/WSDL where most user appear to treat it as a
black box.

Now with Jersey, as it currently stands, we can at least generate some
JAXB files for the user if we expose the grammar using the WADL
extension. I do wonder if this should be the default as it would make
tooling much each to write. What is the reasoning behind not making this
a default feature of the WADL generator?

As to the client interface, I guess this along with HATEOAS is something
for JAX-RS 2.x, I do like how RESTEasy present these client interfaces:

http://jboss.org/file-access/default/members/resteasy/freezone/docs/1.1.GA/userguide/html/RESTEasy_Client_Framework.html

I am not saying this should be the only way to talk to a service; but it
is certainly a nice model to present to developer who want something
more concrete. It is also something we can easily give the users to get
them going. I have looked at the wadl2java project; but would prefer
from a simplicity point of view to be able to point users at some part
of the Jersey project.

Cheers,

Gerard


On 19:59, Paul Sandoz wrote:
> <div class="moz-text-flowed" style="font-family: -moz-fixed">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.
> </div>
>

-- 
Gerard Davison | Senior Principal Software Engineer | +44 118 924 5095
Oracle JDeveloper Web Service Tooling Development
Oracle Corporation UK Ltd is a company incorporated in England & Wales.
Company Reg. No. 1782505.
Reg. office: Oracle Parkway, Thames Valley Park, Reading RG6 1RA.
Blog http://kingsfleet.blogspot.com