users@jersey.java.net

[Jersey] Re: Optional path parameter at the beginning

From: Adam Lindenthal <adam.lindenthal_at_oracle.com>
Date: Mon, 9 Mar 2015 18:33:24 +0100

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 <arun_at_orbyo.com> 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 <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 <http://www.orbyo.com/services/0.0.1/param1/param2>
> (where http://www.orbyo.com/services <http://www.orbyo.com/services> is the base url ).
> Need help. Any idea why?
> Thanks in advance.
> Regards,
> Arun