users@jersey.java.net

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

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Mon, 10 Mar 2008 17:03:15 -0400

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.