title: Forward request to another rest service using filter
body: <p>I am writing a servlet filter to forward Jersy requests based on certain condition. But they does not seem to forwarding.</p>
  
  <pre><code>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";
  
      }
  
  }
  </code></pre>
  
  <p>I need to forward the url as below.</p>
  
  <pre><code>Original: http://localhost/api/test/1234/true
  
  New URL:http://localhost/api/abcd/1234/true
  </code></pre>
  
  <p>Am I doing any thing wrong.</p>