users@jersey.java.net

Re: Using _at_QueryParam, using UriBuilder

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

Ok after tesing with and without UriBuilder, the behaviour does actually
change.

If I use the UriBuilder to create the client-side request, then i get
the wrong method being called on the server side, if I don't use the
UriBuilder it works as predicted.

Here are the code examples:

// This builds the base URI
URI uri =
UriBuilder.fromUri(getServerUri()).path(user.getBaseURIAppliances().toString()).build();

// uri here is: something like http:<name>:<port>/user/<name>/appliances
     

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.

If I do the following instead:
URI qUri = new URI(uri.toString() + "/?id=" +id);

It works, the correct server-side method gets called.

When should UriBuilder be used ?, there seems to be some side-effects.

Thanks
James



James Weir wrote:
> Hi,
>
> If I do that, then the following method is called:
>
> // GET for URI: /users/<name>/appliances/<id>
> @Path(value="{id}", limited=false)
> @GET
> public Response getItem(@PathParam("name") String userName,
> @PathParam("id") String id) {
> ...
> }
>
> and not the one for searching.
>
> The @PathParam holds the value: "?id=1"
>
> James
>
>
> Paul Sandoz wrote:
>> Hi James,
>>
>> We removed (by default) automatic redirection from a request URI
>> without a '/' to a request URI with a '/'. This "magic" was causing
>> confusion and was slightly inconsistent sometimes.
>>
>> Try this request URI:
>>
>> http://127.0.0.1:9998/users/jim/appliances/?id=1
>>
>> You can enable the previous behavior by setting the feature:
>>
>> com.sun.ws.rest.config.feature.Redirect
>>
>> to "true" on the ResourceConfig.
>>
>> Paul.
>>
>> James Weir wrote:
>>> Hi,
>>>
>>> I have a resource that will allow me to recuperate an item or query
>>> for several items. My resource (based on the Storage Example) has
>>> the following template:
>>>
>>> @Path("/users/{name}/appliances/")
>>> @ProduceMime({"application/xml", "application/json"})
>>> @ConsumeMime({"application/xml", "application/json"})
>>> public class MyResource {
>>>
>>> // GET for URI: /users/<name>/appliances?id=<appliance id>
>>> @GET
>>> public Response get(@PathParam("name") String userName,
>>> @QueryParam("id") String applId) {
>>> ....
>>> }
>>>
>>> // GET for URI: /users/<name>/appliances/<id>
>>> @Path(value="{id}", limited=false)
>>> @GET
>>> public Response getItem(@PathParam("name") String userName,
>>> @PathParam("id") String id) {
>>> ...
>>> }
>>> }
>>>
>>> However when I send a GET request:
>>> http://127.0.0.1:9998/users/jim/appliances?id=1
>>>
>>> I get a 404 response back (traces from client side)
>>>
>>> 11:46:03,921 DEBUG [Thread-4] (ApplianceMsg.java:UserMsg:316) -
>>> Querying appliance tickets with uri:
>>> http://127.0.0.1:9998/users/jim/appliances?id=1
>>> 11:46:03,921 DEBUG [Thread-4] (CacheFilter.java:CacheFilter:36) -
>>> CacheFilter.handle(http://127.0.0.1:9998/users/jim/appliances?id=1)
>>> 11:46:03,921 DEBUG [Thread-4] (CacheFilter.java:CacheFilter:61) -
>>> CacheFilter response status....: 404
>>>
>>> The server side code does not seem to be executed.
>>> For the moment I cannot see what I am doing wrong here. Any ideas ?
>>>
>>> Thanks for any help
>>> James
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>