users@jersey.java.net

Re: [Jersey] Matrix Parameter question

From: Geoff hendrey <geoff_hendrey_at_yahoo.com>
Date: Mon, 2 Nov 2009 10:14:09 -0800 (PST)

Hi Paul,

I found a good description of the current behavior here: http://n2.nabble.com/PathSegment-and-MatrixParam-confusion-td1572432.html

For my needs, I get the Matrix Parameter from the PathSegment as an injected class-level property.

@PathParam("tbl") protected PathSegment tblPathParam;

I than manually pass this PathSegement on to subresources by setters or constructor arguments on the sub-resource so they can have access to the matrix parameters of their "parent" resources, as needed.

I will log a Jira issue per your suggested behavior, below.

Thanks,
geoff

--
http://nextdb.net - RESTful Relational Database
http://www.nextdb.net/wiki/en/REST
--- On Mon, 11/2/09, Paul Sandoz <Paul.Sandoz_at_Sun.COM> wrote:
From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Subject: Re: [Jersey] Matrix Parameter question
To: users_at_jersey.dev.java.net
Date: Monday, November 2, 2009, 1:35 AM
Hi Geoffrey,
Unfortunately only the matrix parameters that are at the end of the URI path can be bound to @MatrixParam.
The case of the end "/" looks like a bug. What version of Jersey are you using?
All matrix parameters are available from the UriInfo.getPathSegments:
  https://jsr311.dev.java.net/nonav/javadoc/javax/ws/rs/core/UriInfo.html#getPathSegments%28%29
If you want to get access to the map of matrix parameters you can identify the path segment as parameter:
@Path("{id: X}") // Use a regex that maps the literal character 'X'
public class X {
  public X(@PathParam("id") PathSegment ps) {
    MultivaluedMap<String, String> mps = ps.getMatrixParameters();
    ...
  }
}
I think what we are missing from JAX-RS is the following:
1) The ability to get the current path segment or segments associated with the resource; and
2) a qualifier on @MatrixParam to declare that the matrix parameter is associated with the current path segment
     (or the last path segment in the current set).
Could you log a feature?
Paul.
On Nov 2, 2009, at 3:09 AM, geoffrey hendrey wrote:
> Hi,
> 
> I've got a resource class, call it X, on an arbitrary path.
> 
> .../X
> 
> If I pass a URL matrix parameter to Resource X as follows, the matrix parameter is properly injected into class X
> .../X;a=hello
> 
> However, if I add so much as a trailing slash to the path, then I don't receive the injected matrix parameter. E.g., this doesn't work:
> 
> .../X;a=hello/
> 
> and this doesn't work either
> 
> .../X;a=hello/b/c/d
> 
> Everything I have read indicates that I should be able to receive parameter "a". Any ideas on what might cause this to fail?
> 
> -geoff
> 
> --http:nextdb.net - RESTful Relational Database
> http://www.nextdb.net/wiki/en/REST
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net