Felipe Gaścho wrote:
> Thanks.. so the default option is to create such types manually.. ok..
> I will follow that..
>
I think that "default option" is actually too strong an assumption. The
right way to look at this is "computing the content of the response is
the application's problem, not Jersey's problem." The fact that Jersey
provides some help in deciding what the right URI for a particular link
href might be is independent from the concept that you might wish to use
an Atom-like or HTML-like <link> tag to express that link in your response.
A simple concept that I find useful in designing REST applications: in
MVC terms, the URI of a resource is a *view* tier concept, not a *model*
tier concept. Therefore, your model tier should have no notion of "the
uri of this resource" since that is totally a function of the web
service, not of the model tier. Do not get yourself into the trap of
thinking that the URI of a resource should be a column in a database table.
Craig
> On Wed, Sep 16, 2009 at 6:22 PM, Craig McClanahan
> <Craig.McClanahan_at_sun.com> wrote:
>
>> Felipe Gaścho wrote:
>>
>>> If I want to produce an output like:
>>>
>>> <account>
>>> <id>ADK31242</id>
>>> <link href="http://bank.org/account/ADK31242" rel="self"/>
>>> <link rel="http://bank.org/rel/transfer"
>>> type="application/vnd.bank.org.customer+xml"
>>> href="http://bank.org/transfers"/>
>>> <balance currency="USD">534.62</balance>
>>> </account>
>>>
>>> Is there some special support in Jersey to produce such LINK and REL
>>> elements and attributes .. ? or should I import the HTML schema or to
>>> define these types by myself ?
>>>
>>>
>>>
>>>
>>>
>>>
>> There are two pieces to this puzzle.
>>
>> Jersey does have support for calculating what the URI value to be included
>> in your link tags should be. Check out the UriBuilder[1] class in the
>> JAX-RS API. It lets you build up a URI, for example, by knowing the
>> resource class and path template arguments you want to use. You can also
>> google "jersey uribuilder examples" for some links to sample code using
>> this.
>>
>> Everything about converting your response entity into an XML data structure
>> like this (whether it is a link or not) is totally dependent on the
>> mechanism you are using to create the response. A couple of choices for
>> this case:
>>
>> * Manually build up the XML as a string yourself, and send it as the
>> response entity.
>> There's nothing Jersey can really do for you here ... it doesn't pay any
>> attention to
>> the actual content.
>>
>> * Create classes for Account and Link that are annotated with JAXB
>> annotations.
>> In particular on the Link class, you'll want to use the annotations that
>> make the
>> "href" and "rel" properties come out as XML attributes, rather than as
>> nested elements
>> (which is the JAXB default). The Account class might have a "links"
>> property of
>> type List<Link> or something, which you could use to configure the links.
>> Then,
>> all you need is to return the Account instance as your response entity.
>>
>> Craig
>>
>> [1]
>> https://jsr311.dev.java.net/nonav/releases/1.1/javax/ws/rs/core/UriBuilder.html
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>>
>
>
>
>