Hello Stokes,
The routing mechanism is based on Template objects
(http://www.restlet.org/documentation/1.0/api/index.html?org/restlet/util/Template.html)
and Variable objects.
When defining a "route" with the "attach" method, a Template object is
created and then associated with this "route". This Template object is
in charge of parsing the requested URI and give it a score according to
some attributes. then the Router can compare the score of each route
defined and choose the one it prefers ([1]).
The way the Template object assigns a score can be customized with the
following modes :
- MODE_START_WITH (default)
- MODE_EQUALS
In order to solve your problem, you can use the "equals" mode :
//Define routing to FooListFinder
component.getDefaultHost().attach("/foos", <FooListFinder>);
//Define routing to FooFinder
Route route = component.getDefaultHost().attach("/foos/{fooid}",
<FooFinder>);
route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
route =
component.getDefaultHost().attach("/foos/{fooid}?{fooQuery}", ,
<FooFinder>);
route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
//In this case, the variable "fooQuery" is redefined : it's a
query variable, and it is not required (in order to allow such URIs :
/foos/123?).
Variable variable = new Variable(Variable.TYPE_URI_QUERY, "",
false, false);
route.getTemplate().getVariables().put("fooQuery", variable);
I hope this helps you.
Best regards,
Thierry Boileau
PS :
[1] 6 modes are available :
* Best match (default)
* First match
* Last match
* Random match
* Round robin
* Custom
If I have a router with two Restlets attached as follows:
/foos ==> FooListFinder
/foos/{fooId} ==> FooFinder
... then, as expected, these request route as follows:
/foos --routes to--> FooListFinder
/foos?somearg=true --routes to--> FooListFinder
/foos/123 --routes to--> FooFinder
/foos/123?someotherarg=456 --routes to--> FooFinder
All of that is good.
But as a side-effect, I get these that I _don't_ want:
/foos/123/garbage --routes to--> FooFinder
/foos/123/more/garbage --routes to--> FooFinder
Any suggestions for how to prevent these last two? I need to handle this at the
framework/router level, so that the Finder implementations aren't concerned.
In my case my API is very particular about syntax, so I want the last two
requests above to result in an error page (400).
Thanks,
Stokes.