You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Tim Morrow 2 <ti...@gmail.com> on 2008/06/07 00:52:36 UTC

JAX-RS specifying multiple values in a pathparam

I can easily invoke a resource passing in a single value, for example:
   /products/123
Is it possible to bind a url like this:
   /products/123;456;789
to a method signature?  Basically I'd like to return multiple products at
once.

I tried defining an @PathParam on an array parameter, but that didn't work. 
I tried a @MatrixParam, but as far as I can tell that is for name=value
pairs.

Any help or example would be greatly appreciated,

Thanks,

Tim


-- 
View this message in context: http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17702725.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-RS specifying multiple values in a pathparam

Posted by Tim Morrow 2 <ti...@gmail.com>.
BTW, a properly escaped semi-colon (%3B) is preserved by getPathInfo.  

http://www.ietf.org/rfc/rfc2396.txt section 3.3 states that ";" delimits a
sequence of parameters in a path segment.  Whatever that means.  Not sure
why its dropped by getPathInfo().

I'm in over my head.

:)

Tim


Tim Morrow 2 wrote:
> 
> I can easily invoke a resource passing in a single value, for example:
>    /products/123
> Is it possible to bind a url like this:
>    /products/123;456;789
> to a method signature?  Basically I'd like to return multiple products at
> once.
> 
> I tried defining an @PathParam on an array parameter, but that didn't
> work.  I tried a @MatrixParam, but as far as I can tell that is for
> name=value pairs.
> 
> Any help or example would be greatly appreciated,
> 
> Thanks,
> 
> Tim
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17736887.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-RS specifying multiple values in a pathparam

Posted by Ian Roberts <i....@dcs.shef.ac.uk>.
Tim Morrow 2 wrote:
> Thanks for the suggestions. I could work with an upper limit of values rather
> than an open ended list.
> 
> I tried @Path("/{id1};{id2};{id3}") with 3 @PathParam parameters but got a
> "No operation matching request path ... is found" error.
> 
> I also tried keeping @Path("/{id}") mapping to a String parameter.  However,
> a path of /123;456 resulted in the string id beging set to "123" only. 
> Something is slicing up the id at ";".  

Probably the servlet container.  I know tomcat uses a ; for session 
cookies (http://..../page;jsessionid=xxxxx).

Ian

-- 
Ian Roberts               | Department of Computer Science
i.roberts@dcs.shef.ac.uk  | University of Sheffield, UK

Re: JAX-RS specifying multiple values in a pathparam

Posted by Tim Morrow 2 <ti...@gmail.com>.
Thanks for the suggestions. I could work with an upper limit of values rather
than an open ended list.

I tried @Path("/{id1};{id2};{id3}") with 3 @PathParam parameters but got a
"No operation matching request path ... is found" error.

I also tried keeping @Path("/{id}") mapping to a String parameter.  However,
a path of /123;456 resulted in the string id beging set to "123" only. 
Something is slicing up the id at ";".  

Digging deeper into setupMessage() in AbstractHTTPDestination, it seems that
"request.getPathInfo()" will only return /123 not /123;456.  Confirmed on
both Jetty 6 and Tomcat 6.  That probably explains my first problem too.

So it seems having a ";" anywhere in the path portion of the URL is going to
be problematic?  

I tried changing setupMessage() to use request.getRequestURI() (which does
return the full path with the semi-colons).  But it appears that the
PATH_INFO value in the message must be exactly <servletContext> +
<pathInfo>; that is, it cannot contain the servlet mapping part itself. 
Manually screwing with that in the debugger, success!  It correctly mapped
to @Path("/{id1};{id2};{id3}") and 3 method parameters.

So that seems like it be a solution: basically "reimplement" getPathInfo()
by chopping up getRequestURI().

Meanwhile... I'm going to continue to with accepting a single parameter for
now.

Thanks,

Tim




Sergey Beryozkin wrote:
> 
> Hi
> 
> Would PathParam("{id1};{id2};{id3}") work ?
> 
> Or are you thinking of being able to handle a different number of  product
> ids per request ?
> Perhaps the simpliest way would be to do
> 
> PathParam("productIds") String
> 
> and then String.split(";") in the function body
> 
> I'm not sure JAX-RS provides for a way to have an open-ended list of
> parameters(Path, Matrix, etc) be mapped to an array.
> Still, it's an interesting idea, perhaps we can come up with some
> extension to handle such cases...
> 
> Cheers, Sergey
> 
> ----- Original Message ----- 
> From: "Tim Morrow 2" <ti...@gmail.com>
> To: <us...@cxf.apache.org>
> Sent: Friday, June 06, 2008 11:52 PM
> Subject: JAX-RS specifying multiple values in a pathparam
> 
> 
>> 
>> I can easily invoke a resource passing in a single value, for example:
>>   /products/123
>> Is it possible to bind a url like this:
>>   /products/123;456;789
>> to a method signature?  Basically I'd like to return multiple products at
>> once.
>> 
>> I tried defining an @PathParam on an array parameter, but that didn't
>> work. 
>> I tried a @MatrixParam, but as far as I can tell that is for name=value
>> pairs.
>> 
>> Any help or example would be greatly appreciated,
>> 
>> Thanks,
>> 
>> Tim
>> 
>> 
>> -- 
>> View this message in context:
>> http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17702725.html
>> Sent from the cxf-user mailing list archive at Nabble.com. 
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> 
> 

-- 
View this message in context: http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17736574.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: JAX-RS specifying multiple values in a pathparam

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

Would PathParam("{id1};{id2};{id3}") work ?

Or are you thinking of being able to handle a different number of  product ids per request ?
Perhaps the simpliest way would be to do

PathParam("productIds") String

and then String.split(";") in the function body

I'm not sure JAX-RS provides for a way to have an open-ended list of parameters(Path, Matrix, etc) be mapped to an array.
Still, it's an interesting idea, perhaps we can come up with some extension to handle such cases...

Cheers, Sergey

----- Original Message ----- 
From: "Tim Morrow 2" <ti...@gmail.com>
To: <us...@cxf.apache.org>
Sent: Friday, June 06, 2008 11:52 PM
Subject: JAX-RS specifying multiple values in a pathparam


> 
> I can easily invoke a resource passing in a single value, for example:
>   /products/123
> Is it possible to bind a url like this:
>   /products/123;456;789
> to a method signature?  Basically I'd like to return multiple products at
> once.
> 
> I tried defining an @PathParam on an array parameter, but that didn't work. 
> I tried a @MatrixParam, but as far as I can tell that is for name=value
> pairs.
> 
> Any help or example would be greatly appreciated,
> 
> Thanks,
> 
> Tim
> 
> 
> -- 
> View this message in context: http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17702725.html
> Sent from the cxf-user mailing list archive at Nabble.com. 

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

RE: JAX-RS specifying multiple values in a pathparam

Posted by Tim Morrow 2 <ti...@gmail.com>.

This is what I ended up going with.  I turned my parameter into a string and
went with a path like:
  /products/123,456,789
and manually chopped it up and turned them into longs.

Thanks for the suggestions,

Tim


So may be you can use ',' as a separator between multiple params in a single
path segment then ?

Cheers, Sergey


-- 
View this message in context: http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17824890.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: JAX-RS specifying multiple values in a pathparam

Posted by dmathai <ge...@yahoo.co.in>.
If the number of parameters are fixed you can try
"/products/{productIdOne}/{productIdTwo}"



--
View this message in context: http://cxf.547215.n5.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp555098p5727586.html
Sent from the cxf-user mailing list archive at Nabble.com.

RE: JAX-RS specifying multiple values in a pathparam

Posted by Sergey Beryozkin <se...@iona.com>.
So may be you can use ',' as a separator between multiple params in a single
path segment then ?

Cheers, Sergey

-----Original Message-----
From: Tim Morrow 2 [mailto:tim.morrow@gmail.com] 
Sent: 09 June 2008 20:36
To: users@cxf.apache.org
Subject: RE: JAX-RS specifying multiple values in a pathparam



Thanks.

I did also try that.  request.getPathInfo() dropped _everything_ after the
first semi-colon in the path.

There seemed to have been a bit of a discussion regarding Tomcat's handling
of ";" in the path in 2006:
http://markmail.org/message/4h3kqe7cbwx3ujqi?q=marc+parameters+in+URL+path+s
egments&page=1&refer=pzinulobvldtpil4

Tim


Sergey Beryozkin wrote:
> 
> Hi
> 
> Perhaps you can do (note the trailing '/')
> 
> @Path("/{id1};{id2};{id3}/")
> 
> And then just do /1;2;3/ ?
> 
> Cheers, Sergey
> 
> 
> 
> -----Original Message-----
> From: Tim Morrow 2 [mailto:tim.morrow@gmail.com] 
> Sent: 09 June 2008 17:51
> To: users@cxf.apache.org
> Subject: Re: JAX-RS specifying multiple values in a pathparam
> 
> 
> Couple more points:
> 
> * A properly escaped semi-colon (%3B) is preserved by getPathInfo.  
> * http://www.ietf.org/rfc/rfc2396.txt section 3.3 states that ";" delimits
> a
> sequence of parameters in a path segment.  Whatever that means.  Not sure
> why its dropped by getPathInfo().
> * Specifying "/{id}" and @Path(value="/{id}", limited=false) allows me to
> pass "/123/456" as a string, but that isn't the look I'm going for.
> 
> I'm in over my head.
> 
> :)
> 
> Tim
> 
> 
> Tim Morrow 2 wrote:
>> 
>> I can easily invoke a resource passing in a single value, for example:
>>    /products/123
>> Is it possible to bind a url like this:
>>    /products/123;456;789
>> to a method signature?  Basically I'd like to return multiple products at
>> once.
>> 
>> I tried defining an @PathParam on an array parameter, but that didn't
>> work.  I tried a @MatrixParam, but as far as I can tell that is for
>> name=value pairs.
>> 
>> Any help or example would be greatly appreciated,
>> 
>> Thanks,
>> 
>> Tim
>> 
>> 
>> 
> 
> -- 
> View this message in context:
>
http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp177
> 02725p17737052.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> 
> 

-- 
View this message in context:
http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp177
02725p17740085.html
Sent from the cxf-user mailing list archive at Nabble.com.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

RE: JAX-RS specifying multiple values in a pathparam

Posted by Tim Morrow 2 <ti...@gmail.com>.

Thanks.

I did also try that.  request.getPathInfo() dropped _everything_ after the
first semi-colon in the path.

There seemed to have been a bit of a discussion regarding Tomcat's handling
of ";" in the path in 2006:
http://markmail.org/message/4h3kqe7cbwx3ujqi?q=marc+parameters+in+URL+path+segments&page=1&refer=pzinulobvldtpil4

Tim


Sergey Beryozkin wrote:
> 
> Hi
> 
> Perhaps you can do (note the trailing '/')
> 
> @Path("/{id1};{id2};{id3}/")
> 
> And then just do /1;2;3/ ?
> 
> Cheers, Sergey
> 
> 
> 
> -----Original Message-----
> From: Tim Morrow 2 [mailto:tim.morrow@gmail.com] 
> Sent: 09 June 2008 17:51
> To: users@cxf.apache.org
> Subject: Re: JAX-RS specifying multiple values in a pathparam
> 
> 
> Couple more points:
> 
> * A properly escaped semi-colon (%3B) is preserved by getPathInfo.  
> * http://www.ietf.org/rfc/rfc2396.txt section 3.3 states that ";" delimits
> a
> sequence of parameters in a path segment.  Whatever that means.  Not sure
> why its dropped by getPathInfo().
> * Specifying "/{id}" and @Path(value="/{id}", limited=false) allows me to
> pass "/123/456" as a string, but that isn't the look I'm going for.
> 
> I'm in over my head.
> 
> :)
> 
> Tim
> 
> 
> Tim Morrow 2 wrote:
>> 
>> I can easily invoke a resource passing in a single value, for example:
>>    /products/123
>> Is it possible to bind a url like this:
>>    /products/123;456;789
>> to a method signature?  Basically I'd like to return multiple products at
>> once.
>> 
>> I tried defining an @PathParam on an array parameter, but that didn't
>> work.  I tried a @MatrixParam, but as far as I can tell that is for
>> name=value pairs.
>> 
>> Any help or example would be greatly appreciated,
>> 
>> Thanks,
>> 
>> Tim
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp177
> 02725p17737052.html
> Sent from the cxf-user mailing list archive at Nabble.com.
> 
> ----------------------------
> IONA Technologies PLC (registered in Ireland)
> Registered Number: 171387
> Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland
> 
> 

-- 
View this message in context: http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17740085.html
Sent from the cxf-user mailing list archive at Nabble.com.


RE: JAX-RS specifying multiple values in a pathparam

Posted by Sergey Beryozkin <se...@iona.com>.
Hi

Perhaps you can do (note the trailing '/')

@Path("/{id1};{id2};{id3}/")

And then just do /1;2;3/ ?

Cheers, Sergey



-----Original Message-----
From: Tim Morrow 2 [mailto:tim.morrow@gmail.com] 
Sent: 09 June 2008 17:51
To: users@cxf.apache.org
Subject: Re: JAX-RS specifying multiple values in a pathparam


Couple more points:

* A properly escaped semi-colon (%3B) is preserved by getPathInfo.  
* http://www.ietf.org/rfc/rfc2396.txt section 3.3 states that ";" delimits a
sequence of parameters in a path segment.  Whatever that means.  Not sure
why its dropped by getPathInfo().
* Specifying "/{id}" and @Path(value="/{id}", limited=false) allows me to
pass "/123/456" as a string, but that isn't the look I'm going for.

I'm in over my head.

:)

Tim


Tim Morrow 2 wrote:
> 
> I can easily invoke a resource passing in a single value, for example:
>    /products/123
> Is it possible to bind a url like this:
>    /products/123;456;789
> to a method signature?  Basically I'd like to return multiple products at
> once.
> 
> I tried defining an @PathParam on an array parameter, but that didn't
> work.  I tried a @MatrixParam, but as far as I can tell that is for
> name=value pairs.
> 
> Any help or example would be greatly appreciated,
> 
> Thanks,
> 
> Tim
> 
> 
> 

-- 
View this message in context:
http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp177
02725p17737052.html
Sent from the cxf-user mailing list archive at Nabble.com.

----------------------------
IONA Technologies PLC (registered in Ireland)
Registered Number: 171387
Registered Address: The IONA Building, Shelbourne Road, Dublin 4, Ireland

Re: JAX-RS specifying multiple values in a pathparam

Posted by Tim Morrow 2 <ti...@gmail.com>.
Couple more points:

* A properly escaped semi-colon (%3B) is preserved by getPathInfo.  
* http://www.ietf.org/rfc/rfc2396.txt section 3.3 states that ";" delimits a
sequence of parameters in a path segment.  Whatever that means.  Not sure
why its dropped by getPathInfo().
* Specifying "/{id}" and @Path(value="/{id}", limited=false) allows me to
pass "/123/456" as a string, but that isn't the look I'm going for.

I'm in over my head.

:)

Tim


Tim Morrow 2 wrote:
> 
> I can easily invoke a resource passing in a single value, for example:
>    /products/123
> Is it possible to bind a url like this:
>    /products/123;456;789
> to a method signature?  Basically I'd like to return multiple products at
> once.
> 
> I tried defining an @PathParam on an array parameter, but that didn't
> work.  I tried a @MatrixParam, but as far as I can tell that is for
> name=value pairs.
> 
> Any help or example would be greatly appreciated,
> 
> Thanks,
> 
> Tim
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/JAX-RS-specifying-multiple-values-in-a-pathparam-tp17702725p17737052.html
Sent from the cxf-user mailing list archive at Nabble.com.