users@jersey.java.net

[Jersey] Re: Optional path parameter at the beginning

From: Arun PV <arun_at_orbyo.com>
Date: Tue, 10 Mar 2015 11:20:59 +0530

Thanks. That worked.
Regards,
Arun
---- On Mon, 09 Mar 2015 23:03:24 +0530 Adam Lindenthal&lt;adam.lindenthal_at_oracle.com&gt; wrote ----

Hi,

I am afraid your regex currently matches (optionally) the exact string “ver”, which is probably not what you intended.
I played a bit with it for a while and this is what seems to do the trick:


@Path("{ver : ([0-9\\.]*)?}{p:/?}{param1}/{param2}")


But I am not an expert in regular expressions, so you might want to tweak it to your needs and to do a more sophisticated matching of your exact version format (this accepts any string composed of ‘0’-‘9' digits and a dot in any combination and any order, yo might want to set other rules for it).


Hope this helps,
Adam



On 09 Mar 2015, at 16:12, Arun PV &lt;arun_at_orbyo.com&gt; wrote:



Hi,

I'm developing a REST service API. Got stuck when tried the following method in the path parameter


@Path("/{ver : (ver/)?}{param1}/{param2}")The first parameter is optional, it's version number.This works if I try with no version no, like http://www.orbyo.com/services/param1/param2 However it's not working if version parameter has a value, like http://www.orbyo.com/services/0.0.1/param1/param2 (where http://www.orbyo.com/services is the base url ).Need help. Any idea why?Thanks in advance.Regards,Arun