Gili wrote:
> Paul Sandoz wrote:
>
>> 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.
>>
>>
>
> I don't understand how the above would work. Are you saying that "images"
> would have 3 matrix parameters: 1, 2 and 5? Or would images be a matrix
> parameter itself?
>
>
I haven't played much with matrix parameters, but it appears they are
for name/value pairs attached to a path segment:
GET /images;name=foo;type=gif
in a resource method receiving this URI:
@GET
public Response images(@MatrixParam("name") String name,
@MatrixParam("type") String type) {
System.out.println(name); // Prints "foo"
System.out.println(type); // Prints "gif"
}
You can use List<String> if you allow more than one value. There are
mumblings in the mail archives about not being able to know which path
segment this parameter came from, so there is probably more to the story.
> Paul Sandoz wrote:
>
>> You can also use a URI like:
>>
>> http://example.com/images/1,2,5/tags
>>
>>
>>
>
> Does it matter whether I use commas or semicolons? I would prefer using
> semicolons to hint that the element order is not important.
>
>
Path parameters are an RFC specification thing, and semicolons are
required. That being said, i've seen people use commas in ways similar
to what you describe above. I'd experiment with a path parameter of
type PathSegment as Paul describes below and see what you get.
> Paul Sandoz wrote:
>
>> 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.
>>
>>
>
> I'm confused. What does @Path("{id: image}") signify? It looks like id is
> the parameter name, but what does "image" refer to?
>
It means that this will match an "{id}" setting in a @PathParam
annotation, but that the value *must* match "image" exactly. The
"image" part can actually be a regular expression. The point of this is
to make sure you grab the path parameters from the correct path segment
(since they can be included on *any* path segment).
Craig