users@jersey.java.net

Re: [Jersey] Optional PathParam is it possible?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 18 Feb 2010 10:34:04 +0100

On Feb 18, 2010, at 12:40 AM, Dário Abdulrehman wrote:

> Given the following resource method:
>
> @GET @Path("tfs/{tf : .*}/genes/{gene : .*}/evidence_codes/
> {evidence_code: .*}")
> public Response doGet(@Context Request req,
> @PathParam("tf") List<PathSegment> tfs,
> @PathParam("gene") List<PathSegment> genes,
> @PathParam("evidence_code") List<PathSegment> ecs,
>
>
> I would like to make each one of the PathSegments optional (tfs/,
> genes/ and evidence_codes/), however like it is now, if I don't
> provide for instance, any genes,

Are they independently optional? if so why not use query parameters?

Or is there a hierarchical dependency? for example if "genes" is
present then "tfs" must be present? If so may need to be explicit and
do:

   @Path("tfs/{tf : .+}")

   @Path("tfs/{tf : .+}/genes/{gene : .+}")

   @Path("tfs/{tf : .+}/genes/{gene : .+}/evidence_codes/
{evidence_code: .+}")


Here is a bit of regex from "Master Foo" that you could use to match
path segments optionally and independently:

     @Path("{a : (?:a/.+?)?}{b : (?:/b/.+?)?}{c: (?:/c/.+?)?}")

"Master Foo" will not tell me how to modify this such that if "a" is
present "b" and "c" may or may not be present, and if "b" is present
"c" may or may not be present. He says the path to regex enlightenment
must be found within oneself :-)

Paul.