users@jax-rs-spec.java.net

[jax-rs-spec users] [jsr339-experts] Re: Desired behavior of UriBuilder.fromResource

From: Jan Algermissen <jan.algermissen_at_nordsc.com>
Date: Thu, 8 Nov 2012 20:08:14 +0100

On Nov 8, 2012, at 7:48 PM, "Markus KARG" <markus_at_headcrashing.eu> wrote:

>> Suppose I have:
>>
>> @Path("customer/{id}")
>> public class CustomerResource {
>>
>>
>> When I use UriBuilder.fromResource(CustomerResource.class)
>>
>> The builder creates a URI, %-encoding the { and } in the path.
>>
>> This sort feels both, wrong and correct :-)
>>
>> Question: what is the desired behavior?
>
> The above code is not creating an URI, it is creating an URIBuilder.
>
> To create an URI you must invoke build("MyID") on this URIBuilder, which
> creates an URI that looks like "customer/MyID".

Thanks - missed the toTemplate() method.

WebTarget customerTarget = baseTarget.path(UriBuilder.fromResource(CustomerResource.class).build().toASCIIString());

should have been

WebTarget customerTarget = baseTarget.path(UriBuilder.fromResource(CustomerResource.class).toTemplate());

but the fluent API was just carrying me along without thinking :-)


Kinda tricky .... the combinations between these APIs :-)

Jan








>
> If that is not produced by your software, then it is definitively wrong and
> you should file a ticket.
>
> Regards
> Markus
>