Restlet路由的噩梦? [英] Restlet routing nightmare?

查看:41
本文介绍了Restlet路由的噩梦?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,这很荒谬:(或者我的设计可能是:)

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

现在有趣的部分:

如果代码按上述顺序排序,则调用 POST:/myProject/WinCondition 会路由到带有wallName的第一条路由!从而得到405.

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.

如果我将/{projectName}/{wallName} 移至底部,则会正确路由!

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

现在这是我所知道的:

  • Restlet中的默认路由模式是MODE_FIRST_MATCH.我将其设置为MODE_BEST_MATCH和URL的顺序仍然很重要!我无法访问'亲和力'得分来检查什么问题/分数.匹配模式为Template.MODE_EQUALS.

然后的问题是:我是否必须关心如何在Java文件中订购URL ????即使从维护的角度来看,这也很可怕.

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

推荐答案

"/{projectName}/{wallName}"和"/{projectName}/WinCondition"将同时获得FIRST_MATCH和BEST_MATCH相同的分数,因此它仍然是路线列表中的第一个获胜.

"/{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.

但这实际上是一个副作用,您一般不应该使自己陷入困境.问题在于,您似乎为相同的URI(例如"/myProject/WindCondition")建议了到两个不同资源类的两条路由.

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").

您应该真正考虑重新设计URI,以防止发生此类冲突.这是一个建议:

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.

这篇关于Restlet路由的噩梦?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆