users@jersey.java.net

Re: [Jersey] Hypermedia on the server. was Re: [Jersey] Re: Hypermedia for JAX-RS/Jersey clients and server

From: gerard davison <gerard.davison_at_oracle.com>
Date: Wed, 13 Jan 2010 16:01:49 +0000

On 13/01/2010 15:24, Marc Hadley wrote:
> On Jan 13, 2010, at 5:39 AM, gerard davison wrote:
>
>> I have been reading your updates to this in your wiki page which are really useful, like the example model:
>>
>> http://wikis.sun.com/display/Jersey/Hypermedia+Examples
>>
>> In the section "Serialization By Reference" you have an annotation that breaks references to object. The only problem with this that I see is that perhaps it doesn't give a consistent programming model. When I have been playing in this area I have explicitly used the resources in the model so you example becomes:
>>
>> public class CustomerBean
>> {
>> public List<AddressResource> addresses;
>> }
>>
>>
> I like the idea of not having to repeat the URI but I think some kind of annotation to mark fields that are subject to special processing (i.e. link generation) is a good idea. IOW, I think link generation should be requested by the developer rather than completely automatic.
>
> As an alternative to the markup in the wiki:
>
> @XmlUri("http://foo.com/customers/${this.id}/addresses/${that.id}")
>
> we could do something like:
>
> @Link(resource=AddressResource.class, bindings = {
> @Binding(name="customer_id", value="${this.id}"),
> @Binding(name="address_id", value="${that.id}")
> })
>
> That way you don't have to repeat the URI template in an annotation in the model, instead you can extract it from the resource class controller.
>

I do prefer that.

> What scopes do we need for the EL that defines the value of a URI template parameter ? I can think of three:
>
> (i) The representation bean (model)
> (ii) The annotated field instance for a collection (model.field[i])
> (iii) The resource that returned the representation
>

(iv) Any parent resources by name and by type.

> Are there any others ?
>


It did trigger a related idea. Part of the problem with using JAX-B is
that it defined one and only one mapping to XML. With HATEOAS you want
to be able to cut the XML model in different ways depending on what the
user is asking for. (Variability to use the terms the LinkedIn people
prefer) So in some cases the Address should be a URI in others the
completed document. It would be nice to be able to map the XML with
different named cut points so:

@GET
@XmlUriCutPoint("short")
public Customer get(....);

@GET
@Path("/full");
@XmlUriCutPoint("full")
public Customer get(....);

This address reference might look like:

@XmlUriCutPoint({
    @XmlUri(name="short",
value="http://foo.com/customers/${this.id}/addresses/${that.id}")})
public List<Address> getAddress();

In the "full" case you get the address object inlined.



>
>> It would them be up to the address resource to specify how the URI is built, but I was thinking along the same lines but making use of Path parameters:
>>
>> @Path("/{parent}/{address}"):
>> @PathParamEL("this.id","customer.id")
>> public class AddressResource
>> {
>> @GET
>> public Address getAddress()
>> {
>> ...
>> }
>> }
>>
>> The advantage here is that you don't assume that Customer and Address are on the same machine. For example it is perfectly possibly that the addresses could like in a different space. It does though restrict your server side design though, and does bring into question whether AddressResource should be a class/ interface / both. (I guess that is what I was getting at in http://kingsfleet.blogspot.com/2009/10/proxy-client-based-on-jersey-with-bit.html, but I haven't written up the server side yet)
>>
>>
> I have to think about that some more, not sure how you would get the correct base URI for a resource on a different machine.
>

I guess in this case you probably already storing the full URI in your
model or something that can easily be mapped. In this case it is pretty
easy to convert to a URI. Another option is to cheat a little bit and
just include the full URL in a path variable for the interface /
resource; but I would be worried about hard coding the location of a
remote machine. I guess this is a generic problem to solve.

Gerard


> Marc.
>
>
>> On 11/12/2009 19:31, Santiago Pericas-Geertsen wrote:
>>
>>> Gerard,
>>>
>>> Added section to [1] about use cases. Also, started new wiki [2] to develop a complete example that includes some exploration (mostly braindumping) of ideas/solutions.
>>>
>>> -- Santiago
>>>
>>> [1] http://wikis.sun.com/display/Jersey/Hypermedia+and+Client+APIs
>>> [2] http://wikis.sun.com/display/Jersey/Hypermedia+Examples
>>>
>>> On Dec 11, 2009, at 12:56 PM, gerard davison wrote:
>>>
>

-- 
Gerard Davison | Senior Principal Software Engineer | +44 118 924 5095
Oracle JDeveloper Web Service, Spring, Weblogic SCA 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 Twitter kingsfleet