Search code examples
javaresturirestleturl-pattern

Restlet URL/path pattern mismapping


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:

  • GET /car returns a list of all cars
  • GET /car/{id} returns details about the car with id 1
  • GET /car/advancedsearch?param1=test should run a search across all cars with some parameters

The 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.


Solution

  • 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);