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.
> 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
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109