users@jersey.java.net

Beginners questions on Uri's and templates etc.

From: Jeff Gortatowsky <indanapt_at_yahoo.com>
Date: Sat, 8 Dec 2007 19:42:22 -0800 (PST)

Assume I have resources I want to expose like so:

1) items = /items/;ids=112233;ids=232144; ids=2253252
2) container = /container/{container_id}
3) items in a container = /container/{container_id)/items

Number one worked great as soon as I screwed around for about 48 hours, finally looking at the test cases and finding out how to use MatrixParam().
Number two also is a no-brainer. Works fine.
Number three is impossible for me to figure out. I tried to forward #3 to the Items resource using a different UriTemplate than #1. When I say forward, I mean returning an newly created ItemsResource(UriInfo context) in the ContainerResource.

In my mind 1 and 3 are the same 'type' of resource. Both should be handled by the items resource. They are both a list of items. One is a list of item references using a list of ids, the other by a what parent container (referenced by container_id) they are in. They both produce ItemReferencs fed into an ItemsConverter which produces the representation which is a collection/list of Item-References in XML. (Can you tell I am using CustomerDB as my basis?)

Try as I might I can not get the container resource to forward to the items resource because the items resource seems to insist all items resources have to start with /items not /container - so I get a 404. What I was trying to do is when the container resource matched the "/container/{container_id)/items" resource is forward that to the items resources with the container_id and produce a list of item references. I was and am trying to be DRY. I know I can use the same method, as one takes a list of ids and the other nothing, but I can not come up with an @UriTemplate in the items resource that works. Instead it calls the first example with an empty list.

When I say 'forward' I mean even though Jersey called a method in the ContainerResource, the resource returned is an ItemsResource that need further processing based in the URI to was created with.

I know this sounds like a lot to bite off for a first RESTful web service, and the documentation right now is mostly in the source which is understandably as Jersey is still in development, but I was taken aback that the same resource, but in a different context, is not recognized. Maybe that is not RESTful?

Thanks for reading this.
Best wishes,


---------------------------------------

Jeffrey D. Gortatowsky
Fullerton, California