I'm developing a REST API using Restlet.
So far everything has been working just fine. However, I now encountered an issue with the Router
mapping of URL to ServerResource
.
I've got the following scenario:
/car
returns a list of all cars/car/{id}
returns details about the car with id 1/car/advancedsearch?param1=test
should run a search across all cars with some parametersThe first two calls work without any problems. If I try to hit the third call though, the Restlet Router
somehow maps it to the second one instead. How can I tell Restlet to instead use the third case?
My mapping is defined as follows:
router.attach("/car", CarListResource.class);
router.attach("/car/{id}", CarResource.class);
router.attach("/car/advancedsearch", CarSearchResource.class);
CarSearchResource
is never invoked, but rather the request ends up in CarResource
.
The router's default matching mode is set to Template.MODE_EQUALS
, so that can't be causing it.
Does anyone have any further suggestions how I could fix it?
Please don't suggest to use /car
with the parameters instead, as there's already another kind of search in place on that level. Also, I'm not in control of the API structure, so it has to remain as it is.
I was able to solve this by simply reordering the attach
statements:
router.attach("/car/advancedsearch", CarSearchResource.class);
router.attach("/car", CarListResource.class);
router.attach("/car/{id}", CarResource.class);