Hi Jeff,
Thanks for persisting. You have found a rather subtle bug related to '/'
termination of a request path and matrix parameters.
IIUC your use-case you are almost there :-) A work around is to have a
template variable for the item in addition to matrix parameters:
/items/{id}
/container/{container_id)/items/{id}
Another work around is to add a '/' to the end of the template used for 3).
I realize these are non-obvious thing to do... I have added units tests
[1] that uses the templates you presented and has tests that pass or
fail. Hopefully looking at that code will help you out.
Some more technical details follow on the issue.
Given a URI request path:
/container/c/items/;ids=1;ids=2;ids=3
Jersey first strips off the matrix parameters:
/container/c/items/
The above modified path will match the container resource with
"/container/c" leaving "/items/" to be matched by the sub-resources of
the container reosurce.
"/items/" matches the sub-locator method of the container resource but
because the request path ends with a slash and the template, "items",
does not Jersey is returning a 404. Jersey is not taking into account
that there is content after the '/' because it has been stripped out.
Jersey has a feature, turned on by default, to return 404 or redirection
responses if:
- a URI request path ends with a '/' and the final matching
template does not, then a 404 response is returned;
- a URI request path does not ends with a '/' and the final
matching template does, then a redirect response to the URI request
path appended with a '/' is returned.
This does not work very well when only matrix parameters are present on
a path segment :-(
Paul.
[1]
https://jersey.dev.java.net/source/browse/*checkout*/jersey/trunk/jersey/test/com/sun/ws/rest/impl/resource/ContainerItemMatrixTest.java
Jeff Gortatowsky wrote:
> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net For
> additional commands, e-mail: users-help_at_jersey.dev.java.net
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109