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???