users@jersey.java.net

Bringing RESTful "connectedness" to my existing domain objects

From: Brett Dargan <brett.dargan_at_gmail.com>
Date: Mon, 8 Dec 2008 10:02:04 +1000

I'm not sure if we are quite talking about the same things, so I've attached
some code (very rough).

My goal is to provide a sound api around some existing jaxb annotated
objects.
They currently represent our core messages used throughout multiple
applications.
They are not the same classes used for persistence, they are used by some
existing web applications.

The new services won't provide much html representations and if they do it
will be limited to html fragments.

The only thing I'm embedding about the view in my objects is the links to
other Resources (and that is only because of the annotations, we could do
this in an external file as well).
My api shouldn't change too much, ;) how many times have we said that
before.

Given that jersey allows us to easily create multiple representations, but
in order to fully "connect" my resources I can't see how I can achieve this
without marking up my domain objects in some way as the marshalling is done
via jersey on my domain objects.

Especially when I may want fine-grained links, so a User may have Payments
and one Representation of a UserResource may list the individual payment
links, not just a link to a PaymentResource that identifies payments for
that user. (actually i didn't do that in the sample)

I've attached a diff that can be applied to the helloworld sample in jersey
1.0.1, to try it out

i jersey-1.0.1/samples/helloworld
patch -p0 < connectedness.patch

run it up with mvn compile exec:java
in another window run the ./go script to hit some urls (assuming you have
curl).

cheers,
Brett.