users@jersey.java.net

[Jersey] Re: Catch all requests under a specific path

From: Ted M. Young [_at_jitterted] <tedyoung_at_gmail.com>
Date: Thu, 20 Mar 2014 20:44:49 -0700

Hi Erik,

What would the benefit of this be? Why not just create two endpoints that
then call the same method internally? e.g.:

@Path("/foo")
public class StocksResource {
    @GET // just matches /foo
    @Produces(MediaType.APPLICATION_JSON)
    public Response getFoo() {
        return foo(false);
    }

    @GET
    @Path("/bar") // matches /foo/bar
    @Produces(MediaType.APPLICATION_JSON)
    public Response getFooBar() {
        return foo(true);
    }

    private foo(boolean hasBar) {
        // do stuff here
    }
}

;ted



On Thu, Mar 20, 2014 at 4:34 PM, Erik Holstad <erikholstad_at_gmail.com> wrote:

> Hey!
>
> I wounder if there is a way to route all calls to any sub paths to a given
> parent path.
>
> Let's pretend we have 2 endpoints
>
> GET /foo and
> GET /foo/bar
>
> I would like to be able to catch them both in one method and then branch
> afterwards.
>
> I know I can do this using the regular HttpServletRequest but I just want
> this functionality for one specific path so don't want to change the
> structure of the other servlets.
>
> --
> Regards Erik
>