KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > appfuse > webapp > filter > MockFilterChain


1 package org.appfuse.webapp.filter;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.FilterChain JavaDoc;
6 import javax.servlet.RequestDispatcher JavaDoc;
7 import javax.servlet.ServletException JavaDoc;
8 import javax.servlet.ServletRequest JavaDoc;
9 import javax.servlet.ServletResponse JavaDoc;
10 import javax.servlet.http.HttpServletRequest JavaDoc;
11
12 import org.apache.commons.lang.StringUtils;
13 import org.apache.commons.logging.Log;
14 import org.apache.commons.logging.LogFactory;
15
16 /**
17  * Borrowed from the Display Tag project:
18  * http://displaytag.sourceforge.net/xref-test/org/displaytag/filter/MockFilterSupport.html
19  */

20 public class MockFilterChain implements FilterChain JavaDoc {
21     private final Log log = LogFactory.getLog(MockFilterChain.class);
22     
23     public void doFilter(ServletRequest JavaDoc request, ServletResponse JavaDoc response)
24     throws IOException JavaDoc, ServletException JavaDoc {
25         String JavaDoc uri = ((HttpServletRequest JavaDoc) request).getRequestURI();
26         String JavaDoc requestContext = ((HttpServletRequest JavaDoc) request).getContextPath();
27
28         if (StringUtils.isNotEmpty(requestContext) &&
29                 uri.startsWith(requestContext)) {
30             uri = uri.substring(requestContext.length());
31         }
32
33         if (log.isDebugEnabled()) {
34             log.debug("Redirecting to [" + uri + "]");
35         }
36
37         RequestDispatcher JavaDoc dispatcher = request.getRequestDispatcher(uri);
38         dispatcher.forward(request, response);
39     }
40 }
41
Popular Tags