users@jersey.java.net

Re: [Jersey] RE: delimiter for QueryParam using List<T>

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 17 Jun 2009 17:01:39 +0200

On Jun 17, 2009, at 3:21 PM, Turner, George wrote:

> Thanks Paul.
>
> This is a REALLY surprising answer, because I would think it is a
> non-standard usages of query parameters.

Not at all, the URI/URL specification allows it.


> Most implementations would
> throw all of the parameters into a Map and then you would only be able
> to retrieve the last one entered.

Those implementations would be incorrect :-) that is why JAX-RS
defines a MultivaluedMap that is common for many types of multi-valued
parameter: path, matrix, query, cookie and header.


> I was expecting a pipe "|" or
> something but not this answer. Is there a W3C reference to this
> style?

No, AFAIK there is no standard for the syntax of a query parameter
value that represents a list of stuff. It is really up to the
*application* to define the syntax of those parameter valuess, and
what if any the relationship is to multiple parameters with the name
parameter name.

FWIW HTTP defines certain headers that declare lists of stuff as comma
separated values. If there are multiple headers of the same name in
the request, then the values of those headers can be concatenated into
one header.


>
> I had a class like the one given that split on a comma, but dropped it
> to use the List<T> construct, but couldn't get it to work, but now I
> know why.
>

OK!

Paul.

> Thanks
>
> Gene
>
> -----Original Message-----
> From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
> Sent: Wednesday, June 17, 2009 03:24
> To: Turner, George
> Subject: Re: delimiter for QueryParam using List<T>
>
> Hi Gene
>
> Given, for example, the following URL:
>
> http://host:8080/path?a=1&a=2
>
> That results in the following resource method to be invoked:
>
> @GET
> public String get(@QueryParam("a") List<String> la) {
> }
>
> Then the list "la" will contain the values "1" and "2".
>
> i.e. the list handles *multiple* values of the same parameter. If you
> want to support some form of lexical syntax for a particular value
> then
> you will have to write your own class that conforms to the rules of
> classes e.g. a constructor that takes a String value, like that
> which is
> used in the Sparklines sample (see code below).
>
> Paul.
>
> P.S. i strongly recommend you use the jersey users list, that way you
> may get a quicker response and others can also benefit from the
> responses as well.
>
> public class IntegerList extends ArrayList<Integer> {
> public IntegerList(String s) {
> super();
>
> for (String v : s.split(",")) {
> try {
> add(Integer.parseInt(v.trim()));
> } catch (Exception ex) {
> ex.printStackTrace();
> throw new WebApplicationException(400);
> }
> }
> if (isEmpty())
> throw new WebApplicationException(400);
> }
> }
>
> On Jun 16, 2009, at 7:13 PM, Turner, George wrote:
>
>> Paul,
>>
>> I have searched everywhere and cannot find documentation for the
>> valid
>
>> delimiter when using the List<T> QueryParam. I have always used a
>> comma when handling it manually before Jersey, but would like to now
>> use the the RI to handle this, but can't seem to get anything to
>> work,
>
>> even with the 1.1.0-ea.
>> Help?
>>
>> Thanks
>>
>> Gene
>>
>> George (Gene) Turner
>> <image001.png>
>> Senior Staff Software Engineer
>> Information Systems & Global Services
>> Work:(719) 277-5244 Cell:(719) 237-0490 george.turner_at_lmco.com
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>