在 Jersey 中对不匹配的 REST 方法使用默认方法
我知道这不太“安静”,但是我想了解是否以及如何处理与 REST 资源中的任何方法不匹配的所有请求(我想将这些请求代理到另一台服务器)。例如,它可以是这样的方法:
@GET
@Path("*")
public Response defaultMethod(@Context HttpServletRequest request, @Context HttpServletResponse response)
{
// do proxying here
}
我怎样才能实现这个目标?
BR,
塞尔坎C
I know this is not quite "restful" but, I want to learn if and how I can handle all requests which do not match any of the methods in my REST resource (I want to proxy these requests to another server). For example, it could be a method like:
@GET
@Path("*")
public Response defaultMethod(@Context HttpServletRequest request, @Context HttpServletResponse response)
{
// do proxying here
}
how can I achieve this?
BR,
SerkanC
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这适用于:
http://example.com/someUnexpectedPath
http://example.com/someUnexpectedPath/withAdditionalSubPaths
http://example.com/someUnexpectedPath /withAdditionalSubPaths?andParams=whatever
This works for:
http://example.com/someUnexpectedPath
http://example.com/someUnexpectedPath/withAdditionalSubPaths
http://example.com/someUnexpectedPath/withAdditionalSubPaths?andParams=whatever
一种可能的选择是定义自定义 404 映射。由于 404s 处理所有不匹配的请求,因此它应该捕获所有未定义的 url。
我将以下内容添加到我的
web.xml
文件中,其中 location 是您要将请求定向到的路径。然后只需将调用定义为正常即可。
One possible option would be to define a custom 404 mapping. Since 404s handles all unmatched requests it should catch all undefined urls.
I added the following this to my
web.xml
fileWhere location is the path you want to direct the request to. Then just define that the call as normal.