0

I have made a filter that is responsible for adding .do to requests and is the first declared filter:

 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

    if(! (request instanceof  HttpServletRequest)){
      chain.doFilter(request, response );
    }

    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    String requestUrl = httpServletRequest.getServletPath();

    if(!isBetaPathRequest(httpServletRequest) || StringUtils.contains(requestUrl,".")){
      chain.doFilter(request, response );
      return;
    }

    String newUrl = requestUrl;

    int lastIndexOf = requestUrl.lastIndexOf("?");
    if(lastIndexOf == -1){

      if(requestUrl.charAt(requestUrl.length()-1) != '/'){
        newUrl = newUrl.concat(".do");
      }

    }
    else{
      newUrl = requestUrl.substring(0, lastIndexOf-1) .concat(".do")  .concat(requestUrl.substring(lastIndexOf));
    }

    final RequestDispatcher rq = getRequestDispatcher(request, newUrl);
    rq.forward(request, response);
  }

There are other various filters also declared in the project web.xml file and I am notificing with the debugger that they are not being run.

The current mapping for one important filter is for example:

ContentResponseCachingFilter *.do

But the initial incoming request does not include .do in the URl until it passed through the BetaRewriteUrlFilter.

When RequestDispatcher.forward is called, are the filters applied or do we need to manually cal them or instead use a 302 redirect???

Menelaos
  • 23,508
  • 18
  • 90
  • 155

1 Answers1

0

What I ended up doing was to place this new filter last in the web.xml definiton.

This rewrite filter needed to be last on the chain, since using the request dispatcher forward method would not break functionallity or inhibit the running of the other filters.

Menelaos
  • 23,508
  • 18
  • 90
  • 155