Java Restlets - 匹配任意长的 URI 路径参数
使用 Restlet,您可以使用基于 URI 模板规范。我希望能够路由与以下模式匹配的 URI
http://www.blah.com/something/...arbitrarily long path.../somethingelse/
因此,以下两个 URI 将进行相同的匹配和路由:
http://www.blah.com/something/a/b/c/d/somethingelse/
and:
http://www.blah.com/something/z/y/x/w/v/somethingelse/
如何使用 Restlet 实现此目的?
干杯,
皮特
Using Restlets you can route URIs using a system based on the URI template specification. I want to be able to route URIs which match the following pattern
http://www.blah.com/something/...arbitrarily long path.../somethingelse/
So, the following two URIs would be matched and routed the same:
http://www.blah.com/something/a/b/c/d/somethingelse/
and:
http://www.blah.com/something/z/y/x/w/v/somethingelse/
How can I achieve this using Restlets?
Cheers,
Pete
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
设置路由的最常见方法是使用路由器,如下所示:
“attach”返回 Route,其方法为 setMatchingMode,因此您可以执行以下操作:
这将路由设置为匹配以提供的模式开头的任何 URL。
我希望这足以满足您的需求。我不知道有任何内置方法可以将 URL 与特定前缀和特定后缀进行匹配。但如果这正是您所需要的,您可能可以实现自己的模板、路由等子类(我不确定需要哪个。)
我很确定基于正则表达式的路由已经在 Restlet 邮件中讨论过列表;你可能想在那里搜索。
The most common way to set up routes is with a Router, like so:
'attach' returns a Route, which has the method setMatchingMode, so you can do this:
This sets the route to match any URL which starts with the supplied pattern.
I hope that's sufficient for your needs. I'm not aware of any built-in way to match URLs with a particular prefix and a particular suffix. But if that's specifically what you need, you could probably implement your own subclass of Template, Route, etc (I'm not sure which would be needed.)
I'm pretty sure that regex-based routing has been discussed on the Restlet mailing list; you may want to search there.