dev@jsr311.java.net

Re: Platonic URIs

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Thu, 27 Sep 2007 15:20:05 +0200

Marc Hadley wrote:
> On Sep 25, 2007, at 7:05 AM, Paul Sandoz wrote:
>>
>> I don't think it makes sense to support:
>>
>> /collection.xml/1
>> /collection.xml/1.xml
>>
>> The suffices only makes sense on last path segment of the URI.
>>
> The use of sub-resource methods will make this quite complex and
> possibly counter-intuitive. Would it make sense to match the URIs above
> but to simply ignore the extensions on the path segments matched to the
> parent class. E.g.
>
> @UriTemplate(value="collection" extensions=true)
> public class SomeResource {
>
> @HttpMethod
> SomeCollection getAll(@UriExtensions String exts[]) {
> ...
> }
>
> @UriTemplate(value="{id}" extensions=true)
> @HttpMethod
> SomeItem getItem(@UriParam("id") String itemId, @UriExtensions String
> exts[]) {
> ...
> }
> }
>
> With the above you want both
>
> GET /collection.xml, and
> GET /collection/1.xml
>
> to work so it could be tricky to disallow GET /collection.xml/1.xml

My eyes are going a but cross eyed looking at these expressions but i
think it can be done easily using the same matching algorithm we have
specified. The following expressions generated for the URI template on
SomeResource should solve that:

1) /collection.(\w+)(/)?
2) /collection(/.*)?

1) first will match:

   /collection.xml rhp = null
   /collection.xml/ rhp = "/"

and since the last matching group is either null or '/' the matching
algorithm terminates:

2) will match:

   /collection rhp = null
   /collection/ rhp = "/"
   /collection/1.xml rhp = "/1.xml"

for the first two matches the algorithm will terminate, for the third
the algorithm will continue by matching the sub-resources of
SomeResource using "/1.xml" as the path.

1) and 2) will not match

   /collection.xml/1.xml

so a 404 can be returned.

Paul.

-- 
| ? + ? = To question
----------------\
    Paul Sandoz
         x38109
+33-4-76188109