users@jersey.java.net

[Jersey] Re: Regex matches for path segments

From: Cameron Jones <cmhjones_at_gmail.com>
Date: Mon, 13 Aug 2012 15:01:08 +0100

On Fri, Aug 10, 2012 at 2:41 PM, Ben Hood <0x6e6562_at_gmail.com> wrote:
> Hi,
>
> I'm using Jersey 1.13 and I want to configure my resources to match on
> multiple path segments. I have been able to get this to work by
> configuring my resource thusly:
>
> @Path("/foo")
> class SomeResource {
>
> @Path("/{path:.+}/bar")
> def method1(@PathParam("path") space:String) = {
> // do something here
> }
>
> @Path("/{path:.+}/baz")
> def method2(@PathParam("path") space:String) = {
> // do something here
> }
> }
>
> However, I'd like pull the {path:.+} match up to the class level, e.g.:
>
> @Path("/foo/{path:.+}")
> class SomeResource {
>
> @Path("/bar")
> def method1(@PathParam("path") space:String) = {
> // do something here
> }
>
> @Path("/baz")
> def method2(@PathParam("path") space:String) = {
> // do something here
> }
> }
>
> When I do the latter, Jersey fails to match the route and returns a 405.
>
> Is there something I'm doing wrong here?
>
> Cheers,
>
> Ben

The problem is your class level attribute will capture all of the rest
of the string leaving nothing to match on, you just want to capture up
to the next separator allowing the method locators to match on the
rest. I think this is the default behavior of path matching in jersey
so you should just be able to replace with @Path("/foo/{path}"). Your
sub-resource locators can also remove their preceding slash as they're
unnecessary.

Thanks,
Cam