Currently a template variable matches *zero* or more characters in a
request URI, e.g.:
@Path("{foo}")
public class Foo {
@GET
public String getFoo(@PathParam("foo") String foo) {return foo;}
}
GET /1 => "1"
GET / => empty
An issue has come up on the Jersey mailing list a few times recently
that results from the lower bound of the matching. Consider:
@Path("bar")
public class Bar {
@GET
public String getBar() {return "bar";}
@GET @Path("{foo}")
public String getFoo(@PathParam("foo") String foo) {return foo;}
}
GET /bar => "bar"
GET /bar/1 => "1"
GET /bar/ => empty
The problem is that the final request gets mapped to the getFoo method
which surprises developers.
To fix this we propose to change the rules such that a template
variable matches *one* or more characters in a request URI. With this
change the results for the example above become:
GET /bar => "bar"
GET /bar/1 => "1"
GET /bar/ => "bar"
The above matches developers expectations more closely but its worth
noting that the change will have consequences. E.g.
GET /foobaz will no longer match @Path("foo{bar}baz")
and
GET /foo//baz will no longer match @Path("foo/{bar}/baz")
On balance though we think this change is the best compromise.
Thoughts, comments ?
Marc.
---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.