Hi Daniel,
The PathSegment issue is a bug, i have fixed it in the trunk, a build
(1.0.1-SNAPSHOT) should make its way to the maven repo in about 1 hour.
The observation on matrix parameters is the correct behavior, it is
global and not local to the current matching path position. One has to
use PathSegment to get matrix params specific to a path.
Paul.
On Nov 24, 2008, at 4:18 PM, Daniel Larsson wrote:
> Hi,
>
> I'm having a hierarchy of resources, and want to use matrix
> parameters to pass parameters to each resource in the path. I wrote
> a real simple example to illustrate, pasted in below.
>
> When using the URL http://localhost:8080/MatrixParamTest/resources/Items/1;matrix=m1/2;matrix=m2/3;matrix=m3
> I get the following logs:
>
> // No output about PathSegment, so it's null here
> getItemResource(String) 1
> getItemResource(matrix) m3
>
> Matrix param = null
> getSubResource(PathSegment) 2
> getSubResource(String) 2
> getSubResource(matrix) m3
>
> Matrix param = null
> getSubResource(PathSegment) 3
> getSubResource(String) 3
> getSubResource(matrix) m3
>
> Matrix param = null
> getXml(PathSegment) 3
> getXml(String) 3
> getXml(matrix) m3
>
> I had expected the PathSegment parameter to be filled in at
> ItemsResource.getItemResource(), and the matrix parameter to have
> the value m1 and m2 in the first two logs.
>
> --
> package com.example;
>
> import java.util.logging.Logger;
> import javax.ws.rs.MatrixParam;
> import javax.ws.rs.Path;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.core.PathSegment;
>
> @Path("/Items")
> public class ItemsResource {
> private Logger log =
> Logger.getLogger(ItemsResource.class.getName());
>
> public ItemsResource() {}
>
> @Path("{id}")
> public ItemResource getItemResource(
> @PathParam("id") PathSegment ps,
> @PathParam("id") String id,
> @MatrixParam("matrix") String m) {
> if (ps != null)
> log.info("getItemResource(PathSegment) " + ps.getPath());
> log.info("getItemResource(String) " + id);
> log.info("getItemResource(matrix) " + m);
> return new ItemResource();
> }
> }
>
> --
>
> package com.example;
>
> import java.util.logging.Logger;
> import javax.ws.rs.GET;
> import javax.ws.rs.MatrixParam;
> import javax.ws.rs.Produces;
> import javax.ws.rs.PathParam;
> import javax.ws.rs.Path;
> import javax.ws.rs.core.PathSegment;
>
> public class ItemResource {
> private static Logger log =
> Logger.getLogger(ItemResource.class.getName());
>
> @MatrixParam("matrix")
> String matrix;
>
> public ItemResource() {
> log.info("Matrix param = " + matrix);
> }
>
> @GET
> @Produces("application/xml")
> public String getXml(
> @PathParam("id") PathSegment ps,
> @PathParam("id") String id,
> @MatrixParam("matrix") String m) {
> if (ps != null)
> log.info("getXml(PathSegment) " + ps.getPath());
> log.info("getXml(String) " + id);
> log.info("getXml(matrix) " + m);
> return "Hello";
> }
>
> @Path("{id}")
> public ItemResource getSubResource(
> @PathParam("id") PathSegment ps,
> @PathParam("id") String id,
> @MatrixParam("matrix") String m) {
> if (ps != null)
> log.info("getSubResource(PathSegment) " + ps.getPath());
> log.info("getSubResource(String) " + id);
> log.info("getSubResource(matrix) " + m);
> return new ItemResource();
> }
> }
>
> --
>
>