users@jersey.java.net

Re: [Jersey] how to generate WADL:Fault elements for exceptions?

From: Martin Grotzke <martin.grotzke_at_freiheit.com>
Date: Thu, 04 Jun 2009 00:08:53 +0200

Hi Krishna,

On Wed, 2009-06-03 at 14:14 -0700, Krishna K Kamity wrote:
> I am new to REST/WADL stuff and I started using jersey for one of my
> projects. (jersey-1.1.1.ea-snapshot)
>
> I came across lot of articles on wadl particulary using yahoo search
> api as an example. I understood how to generate client stubs using
> wadl and wadl2java. But I am not able to understand how a
> WebApplicationException gets converted to fault element in WADL?
>
> For e.g, I have a very simple resource namely Project and it throws
> EntityNotFoundException (a subclass of WebApplicationException) . what
> is the process involved in representing this exception as a fault
> element in WADL?
>
> I took the following steps:
>
> Created the Resource 'Project'
> Created the Exception 'EntityNotFoundException' (subclass of WAE)
>
> Used schemagen to generate corresponding xsd's
> Used wadl-generator to generate wadl from those xsds.
>
> However the generated wadl does not contain fault elements like the
> ones in yahoo search API.
>
> Could you please help me figure how to create those fault elements in
> wadl ? is it a manual process?
You might add this to the wadl by creating your own WadlGenerator. In
the implementation of "createResponse" you would check the exceptions of
the method and add appropriate fault elements to the response element.

For more information about jersey and wadl the wiki is a good start:
http://wikis.sun.com/display/Jersey/WADL

However, it would also be good to have support for faults in the jersey
wadl integration. Right now this is just handled via representation
elements (which are from the structural aspect equal to fault elements,
just without the special semantics).
So you might also submit a feature request to the jersey issue tracker
for this.

Cheers,
Martin



>
> Thanks in advance