On Nov 10, 2008, at 9:26 PM, Gili wrote:
>
> Hi,
>
> JAX-RS and Jersey mention matrix URIs in a couple of places in the
> documentation but don't seem to provide example code anywhere.
>
> Does anyone have a clear example showing the usage of matrix URIs
> using
> JAX-RS? For example, given:
>
> http://example.com/images/1;2;5/tags
>
A better use would be:
http://example.com/images;1;2;5/tags
as then the matrix parameters are associated with a named path
segment. Matrix parameters are ignored when path matching. The best
way to think about them is as query parameters scoped to a path segment.
You can also use a URI like:
http://example.com/images/1,2,5/tags
if you wish and don't require support for name value pairs and require
that the path segment of the list of image names be matched.
You should be able to do this:
@GET_at_Path("{id: image}/tags")
public ... get(@PathParam("id") PathSegment ps) { ... }
and from the PathSegment you can get the multivalued map of matrix
parameters. @MatrixParam will not be much use to you as you want to be
rather general.
If you are using the path segment matching approach you could do:
@GET_at_Path("images/{id: <regex for digits and commas>}/tags")
public ... get(@PathParam("id") ImageList images) { ... }
and the class ImageList has a string constructor that parses the comma
separated list of names (see the Sparklines sample [1]).
Hope that helps,
Paul.
[1]
http://download.java.net/maven/2/com/sun/jersey/samples/sparklines/1.0/sparklines-1.0-project.zip
> I expect to get back the tags associated with images 1, 2 and 5 (all
> in one
> response). It's not clear how to implement this.
>
> Alternatively, I want to be able to use these kinds of URIs:
>
> http://example.com/images/1;2;5?select=random
>
> which means that "select=random" should be applied on images "1, 2,
> 5". In
> theory this means the server should select a random image from
> within that
> set.
>
> Thanks,
> Gili
> --
> View this message in context: http://n2.nabble.com/Example-of-matrix-URIs--tp1482069p1482069.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>