users@jersey.java.net

URI Matching

From: Alex McManus <A.McManus_at_oclcpica.org>
Date: Fri, 2 Nov 2007 16:18:46 +0100

I have a query about URI matching; I'd be grateful for any help...

Given the following example:

@UriTemplate("widgets")
public class WidgetList {

    @UriTemplate("latest")
    Widget getLatest() {...}

    @UriTemplate("{id}")
    Widget findWidget(@UriParam("id") String id) {
        return lookupWidget(id);
    }
}

...which method should match a URI of "widgets/latest"? The
specification suggests that it is random, given that matching methods
are only sorted by input and output media type. Is this correct?

I think this type of construct would be useful. If I have understood the
spec correctly and this is not supported, I would like to propose a
change: that when matching methods are sorted, it orders patterns with a
smaller number of URI parameters ahead of those with more. In this case,
"widgets/latest" (0 params) would be ordered ahead of "widgets/{0}" (1
param).

Also, I'm confused by the example in section 2.1.1 of the spec. It
states that methods annotated with @UriTemplate and **not** @HttpMethod
are sub-resource locators, used to further resolve the object that will
handle the request. Yet in the example (copied below), that description
seems to apply to the getDiscounted() method, which is actually
annotated with both.

@UriTemplate("widgets")
public class WidgetList {
    @HttpMethod
    @UriTemplate("offers")
    WidgetList getDiscounted() {...}

    @UriTemplate("{id}")
    Widget findWidget(@UriParam("id") String id) {
        return lookupWidget(id);
    }
}

If I understand this correctly, the @HttpMethod annotation should be
applied to findWidget() and not getDiscounted()..?

Thanks in advance for any help,

Alex.