Restlet路由噩梦?
好吧,这很荒谬:(或者可能我的设计是:)
以下是我们正在使用的 URL:
/{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
现在有趣的部分:
如果代码按上面的顺序排序,则调用 POST: /myProject/WinCondition
得到路由到第一条带有 wallName 的路由!因此得到 405。
如果我将 /{projectName}/{wallName}
移到底部,那么它就会正确路由!
现在我知道的是:
- Restlet中的默认路由模式 是 MODE_FIRST_MATCH。我将其设置为 MODE_BEST_MATCH 和 URL 的顺序 仍然很重要!我无法访问 “亲和力”分数来检查什么 问题/分数。匹配模式为Template.MODE_EQUALS。
那么问题是:我是否必须关心如何在 java 文件中对 URL 进行排序???即使从维护的角度来看,这也会很可怕。
有什么建议吗?我应该重新设计我的网址吗?但“结构”仍然趋于相同,导致同样的问题
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“/{projectName}/{wallName}”和“/{projectName}/WinCondition”将在 FIRST_MATCH 和 BEST_MATCH 中获得相同的分数,因此它仍然是路线列表中的第一个获胜。
但这确实是一个副作用,一般来说您不应该陷入其中。问题在于,您似乎为相同的 URI(例如“/myProject/WindCondition”)提出了通往两个不同资源类的两条路由。
您确实应该考虑重新设计您的 URI 以防止此类冲突。这里有一个建议:
否则,如果依赖路由顺序让你感到害怕,可以自定义默认路由逻辑考虑评分的目标方法。
"/{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:
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.