RESTEasy 看起来会忽略尾部斜杠,因此我无法编写带有和不带有尾部斜杠的两个不同的 Web 服务,此示例显示:
@Path("foo")
public class TestClass {
@GET
@Path("/bar")
public Response bar1() {
...
}
@GET
@Path("/bar/")
public Response bar2() {
...
}
}
使用 RESTEasy,对/foo/bar 和/foo/bar/的 GET 请求由 bar2() 处理。考虑到 RFC3986 和 JAX-RS 规范,我不明白为什么要这样处理。这可能是 RESTEasy 的问题还是我监督的问题?
最佳答案
这是什么JAX-RS specification说
3.7 资源方法请求匹配
3.7.3 将 URI 模板转换为正则表达式
- URI encode the template, ignoring URI template variable specifications.
- Escape any regular expression characters in the URI template, again ignoring URI template variable specifications.
- Replace each URI template variable with a capturing group containing the specified regular expression or ‘([^/]+?)’ if no regular expression is specified.
- If the resulting string ends with ‘/’ then remove the final character.
- Append ‘(/.*)?’ to the result.
当我阅读它时,RESTEasy 正确地实现了规范。
关于休息 - RESTEasy 切割@Path 的尾部斜线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15196698/