开发者

Java Restlets - Match arbitrarily long URI path parameter

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/s开发者_C百科omething/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


The most common way to set up routes is with a Router, like so:

router.attach("/path/to/resource", MyResource.class);

'attach' returns a Route, which has the method setMatchingMode, so you can do this:

router.attach("/path/to/resource", MyResource.class).setMatchingMode(Template.MODE_STARTS_WITH);

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜