jsr339-experts@jax-rs-spec.java.net

[jsr339-experts] Re: [jax-rs-spec users] Re: UriTemplate API?

From: Marek Potociar <marek.potociar_at_oracle.com>
Date: Thu, 21 Feb 2013 17:45:39 +0100

On Feb 21, 2013, at 4:30 PM, Bill Burke <bburke_at_redhat.com> wrote:

>
>
> On 2/21/2013 10:28 AM, Sergey Beryozkin wrote:
>> On 21/02/13 14:08, Bill Burke wrote:
>>>
>>>
>>> On 2/20/2013 12:08 PM, Marek Potociar wrote:
>>>> Hello experts,
>>>>
>>>> Please review the issue that has been recently filed:
>>>> http://java.net/jira/browse/JAX_RS_SPEC-359
>>>>
>>>> In summary the user wants to be able take a URI template, e.g.
>>>> "http://example.com/name/{name}/age/{age}" and then take a URI, e.g.
>>>> "http://example.com/name/Arnold/age/65" (guess who...) and extract the
>>>> parameter values information into a Map<String, String> instance.
>>>>
>>>> The solution may look like:
>>>>
>>>> UriBuilder builder
>>>> = UriBuilder.fromUri("http://example.com/name/{name}/age/{age}");
>>>> UriTemplate template = builder.template();
>>>> Map<String, String> params = new HashMap<String, String>();
>>>> if (template.match("http://example.com/name/Arnold/age/65", params)) {
>>>> params.put("name", "Alois");
>>>> URI uri = builder.buildFromMap(params);
>>>> ...
>>>> }
>>>>
>>>> The above requires following API changes:
>>>>
>>>> * introduce UriTemplate to represent, well, URI templates...
>>>> * add ability to get UriTemplate instances from UriBuilder and WebTarget
>>>> * expose the boolean UriTemplate.match(URI, Map<String,
>>>> String>) method as part of the UriTemplate API.
>>>>
>>>> Now, finally, my question is:
>>>>
>>>> Q1. Do you think the above API would be useful?
>>>> Q2. Is it something we should still try to add into JAX-RS 2.0, given
>>>> where we are?
>>>>
>>>
>>> I'd say extend UriBuilder with a match() method instead of adding yet
>>> another class we have to include within RuntimeDelegate. Something like:
>>>
>>> Map<String, String> match(String URI);
>>>
>>> match() returns null if it can't match the current expression with the
>>> passed in URI.
>>>
>> This is simpler indeed, the question is then where do we stop with
>> respect to supporting UriTemplate centric functions - so this can lead
>> more methods added, seems like UriTemplate would be more useful, that
>> said, I'm not exactly sure
>>
>>
>>> Useful. Yes. Include in JAX-RS 2.0?
>>
>> I've no strong opinion on it, as I haven't heard any specific
>> requirements from users; if the changes were to be made than I'd favor
>> UriTemplate, whatever you all decide :-)
>>
>
> I disagree. UriBuilder already acts as uri template. Keep everything in UriBuilder.

That's a valid point.

<side-note>
Even though I'm used to looking at UriBuilder as, well, a builder. So I'd like to get us to an immutable version of UriTemplate at some point (if we see a need for working with URI templates more).
</side-note>

Marek

>
> --
> Bill Burke
> JBoss, a division of Red Hat
> http://bill.burkecentral.com