2010-11-05 59 views
4

我知道这不是很“宁静”,但我想知道是否以及如何处理所有与我的REST资源中的任何方法都不匹配的请求(I想要将这些请求代理到另一台服务器)。例如,它可以像一个方法:在Jersey中使用默认的方法来实现不匹配的REST方法

@GET 
@Path("*") 
public Response defaultMethod(@Context HttpServletRequest request, @Context HttpServletResponse response) 
{ 
    // do proxying here 
} 

我怎么能做到这一点?

BR,

SerkanC

回答

2

一种可能的选择是定义一个定制的404映射。由于404s处理所有不匹配的请求,它应该捕获所有未定义的URL。

我添加了下面这对我web.xml文件

<error-page> 
    <error-code>404</error-code> 
    <location>/error/404</location> 
    </error-page> 

位置在哪里,你是想直接请求的路径。然后,将该呼叫定义为正常。

8
@Path("/{default: .*}") 

这适用于:

  • http://example.com/someUnexpectedPath
  • http://example.com/someUnexpectedPath/withAdditionalSubPaths
  • http://example.com/someUnexpectedPath/withAdditionalSubPaths?andParams=whatever