users@jersey.java.net

Re: How to retrieve list of resources - use MatrixParams?

From: Martin Grotzke <martin.grotzke_at_javakaffee.de>
Date: Tue, 11 Mar 2008 09:22:27 +0100

Hi Marc,

thanx for your feedback! Would it be easier if I used s.th.
like /products/123,234,345?

Shouldn't such a basic concept of REST be supported a little bit better
- with a higher level of abstraction? If I would have to bother with
PathSegements it would be more intuitive to use comma, and simply do a
string.split. But this doesn't seem to be what it should be...

So is this an outstanding issue of the spec?

Thanx && cheers,
Martin


On Mon, 2008-03-10 at 17:03 -0400, Marc Hadley wrote:
> On Mar 10, 2008, at 4:45 PM, Martin Grotzke wrote:
> >
> > I want to allow the user to retrieve a list of specified products
> > under
> > a URL like this: /products/123;234;345
> >
> > How is this possible with jersey?
> >
>
> Semicolon is used to mark the start of matrix parameters in a URI path
> segment. Try something like:
>
> @Path("/products/{id}")
> public class ProductList {
>
> @Context
> UriInfo uri;
>
> @GET
> public XXX get(@PathParam("id") String id) {
> // id contains the first product (123 above)
> List<PathSegment> segs = uri.getPathSegments();
> PathSegment p = segs.get(segs.size()-1);
> Set<String> ids = p.getMatrixParams().keySet();
> // ids contains the rest of the ids (234, 345 above)
> return ...
> }
>
> Marc.
>
> ---
> Marc Hadley <marc.hadley at sun.com>
> CTO Office, Sun Microsystems.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>