0
我在寫一個servlet過濾器來根據某些條件轉發Jersy請求。但他們似乎並沒有轉發。使用過濾器轉發請求到另一個休息服務
public class SampleFilter
extends GenericFilterBean
{
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
throws IOException, ServletException
{
String generateRedirectUrl=FormURL((HttpServletRequest)req);
RequestDispatcher dispatcher = req.getRequestDispatcher(generateRedirectUrl);
dispatcher.forward(req, resp);
}
private String FormURL(HttpServletRequest req)
{
// get the request check if it contains the customer
String reqUrl = req.getRequestURI();
log.info("Original Url is"+reqUrl);
if(reqUrl.contains("test"))
{
return "/api/abcd/" +"test";
}
return "Someurl";
}
}
我需要轉發網址如下。
Original: http://localhost/api/test/1234/true
New URL:http://localhost/api/abcd/1234/true
我是否在做任何錯誤的事情。