Restlet routing nightmare?

混江龙づ霸主 提交于 2019-11-27 08:32:50

问题


Okay this is ridiculous: (or probably my design is :)

Here are the URLs that we are using:


/{projectName}/{wallName}        - GET only: fetch all win conditions posted to the all
/{projectName}/WinCondition      - POST a new Win Condition
/{projectName}/WinCondition/{id} - GET, PUT & DELETE

Now the funny part:

If the code is ordered as above the call POST: /myProject/WinCondition gets routed to the first route with wallName! And thus get a 405.

If I shift the /{projectName}/{wallName} to the bottom then it gets routed correctly!

Now here's what I know:

  • The default routing mode in Restlet is MODE_FIRST_MATCH. I set that to MODE_BEST_MATCH and the order of URLs still matters! I am unable to access the 'affinity' score to check what's the problem/score. Matching mode is Template.MODE_EQUALS.

The question is then this: Do I have to be concerned with how I order the URLs in my java file???? That'll be scary, even from a maintenance point of view.

Any suggestions? Should I redesign my URLs?? But the 'structure' still tends to be the same leading to the same problem


回答1:


"/{projectName}/{wallName}" and "/{projectName}/WinCondition" will obtain the same score for both FIRST_MATCH and BEST_MATCH so it is still the first in the route list that wins.

But this is really a side effect that you shouldn't get yourself into generally speaking. The problem is that it looks like you propose two routes to two different resource classes for the same URIs (such as "/myProject/WindCondition").

You should really consider redesigning your URIs to prevent such conflict. Here is a suggestion:

  • /{projectName}/walls/{wallName}
  • /{projectName}/winCondition
  • /{projectName}/winCondition/{id]

Otherwise, if relying on routes order scares you, it is possible to customize the default routing logic to take into account the target method for the scoring.

|improve this answer

来源:https://stackoverflow.com/questions/5682226/restlet-routing-nightmare

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!