users@jersey.java.net

Re: Using _at_QueryParam, using UriBuilder

From: James Weir <James.Weir_at_Sun.COM>
Date: Tue, 18 Mar 2008 14:59:24 +0100

Hi Paul,

See comments inline
Thanks
James


Paul Sandoz wrote:
> James Weir wrote:
>> If I now use the UriBuilder to add "/?id=<id>", namely:
>>
>> URI qUri = UriBuilder.fromUri(uri).path("?id="+id).build();
>>
> > it doesn't work. The UriBuilder correctly replaces the "?" with the
>> correct special character, however it seems that the server-side gets
>> confused and calls the wrong method.
>>
>
> You are asking that "?id=1" be part of a path segment and not a query
> component of the URI. You should find that the URI "qUri" does not
> have any query parameters if you call qUri.getQuery(). Thus the
> correct method is getting called on the resource class.
>
>
>> If I do the following instead:
>> URI qUri = new URI(uri.toString() + "/?id=" +id);
>>
>
> If you are using URI builder you need to do this:
>
> URI qUri = UriBuilder.fromUri(uri).queryParam("id", id).build();
>
> Paul.
>
thats what I had originally actually which provides the following URI:

http://127.0.0.1:9998/users/jim/appliances?id=1

which goes back to my original email :(

In order for it to work I need to create the following URI:
http://127.0.0.1:9998/users/jim/appliances/?id=1

ie an extra "/" between "appliances" and the "?"

without Redirect (as you specified) the URI calls the wrong method on
the server side. If Redirect is switched off (by default) then the
UriBuilder in essence is creating the wrong URIs when using
queryParam(). Its a small inconsistency with an easy workaround, but
(again) this is causing confusion.