dev@jersey.java.net

Re: Anyway to specify optional value in an uri template?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 03 Oct 2007 11:25:04 +0200

Peter Liu wrote:
> I am trying to specify an uri template that lets the users specify a
> query string
> as a uri parameter. For example, @UriTemplate("customers[{query}]").
> However, I would like the [{query}] portion to be optional. Is there anyway
> to specify this in jersey?
>

The URI template is only used with the URI path component (scoping
should only be done using the URI path).

If you want access to the query parameters of the URI query component
you can use the @QueryParam annotation for specific query parameters.
The @DefaultValue annotation can be used in conjunction with a
@QueryParam to provide a default value in the absence of a parameter in
the query component. To access to all the query parameters use
UriInfo.getQueryParameters(). In either case you don't have to worry
about parsing the query component.

If you want the query parameters to be described in the WADL then it is
best to be explicit and use QueryParam on a constructor or a method.

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109