Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 63162 invoked from network); 22 Mar 2007 21:00:43 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 22 Mar 2007 21:00:43 -0000 Received: (qmail 34140 invoked by uid 500); 22 Mar 2007 21:00:45 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 34100 invoked by uid 500); 22 Mar 2007 21:00:45 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 34089 invoked by uid 99); 22 Mar 2007 21:00:45 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2007 14:00:45 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of lists@nabble.com designates 72.21.53.35 as permitted sender) Received: from [72.21.53.35] (HELO talk.nabble.com) (72.21.53.35) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2007 14:00:37 -0700 Received: from [72.21.53.38] (helo=jubjub.nabble.com) by talk.nabble.com with esmtp (Exim 4.50) id 1HUUOO-0003Ls-H8 for users@myfaces.apache.org; Thu, 22 Mar 2007 14:00:16 -0700 Message-ID: <9623982.post@talk.nabble.com> Date: Thu, 22 Mar 2007 14:00:16 -0700 (PDT) From: mraible To: users@myfaces.apache.org Subject: Using a StaticFilter and dispatching to FacesServlet doesn't work MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: matt@raibledesigns.com X-Virus-Checked: Checked by ClamAV on apache.org In my web application, I prefer to have FacesServlet mapped to *.html. This has worked fine for me for the last couple of years. Recently, I've tried to add a StaticFilter that looks for static files (i.e. /content/faq.html) and dispatches to those if they're found. If they're not found, I dispatch to the FacesServlet, which doesn't have a in web.xml. This all works great, except that seems to need the servlet mapping in order to create its links. If I have the following in my web.xml: dwr-invoker /dwr/* Links are rendered as /dwr/foo.xhtml instead of /foo.html. Is this a known issue? Is there a better way to do what I'm trying to do (without using a different extension)? Thanks, Matt package org.appfuse.webapp.filter; import org.apache.commons.lang.StringUtils; import org.springframework.util.PatternMatchUtils; import org.springframework.web.filter.OncePerRequestFilter; import org.springframework.web.util.UrlPathHelper; import javax.servlet.FilterChain; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Iterator; import java.util.Set; /** * A simple filter that allows the application to continue using the .html prefix for actions but also allows * static files to be served up with the same extension. Dojo to serve up its HTML template code. The filter works * on an include/exclude basis where all requests for active pages are redirected by the filter to thee dispatch * servlet. All Dojo related .html requests are allowed to pass straight through to be processed by the servlet * container as per normal. */ public class StaticFilter extends OncePerRequestFilter { private final static String DEFAULT_INCLUDES = "*.html"; private final static String DEFAULT_EXCLUDES = ""; private static final String INCLUDES_PARAMETER = "includes"; private static final String EXCLUDES_PARAMETER = "excludes"; private static final String SERVLETNAME_PARAMETER = "servletName"; private String[] excludes; private String[] includes; private String servletName = null; /** * Read the includes/excludes paramters and set the filter accordingly. */ public void initFilterBean() { String includesParam = getFilterConfig().getInitParameter(INCLUDES_PARAMETER); if (StringUtils.isEmpty(includesParam)) { includes = parsePatterns(DEFAULT_INCLUDES); } else { includes = parsePatterns(includesParam); } String excludesParam = getFilterConfig().getInitParameter(EXCLUDES_PARAMETER); if (StringUtils.isEmpty(excludesParam)) { excludes = parsePatterns(DEFAULT_EXCLUDES); } else { excludes = parsePatterns(excludesParam); } // if servletName is specified, set it servletName = getFilterConfig().getInitParameter(SERVLETNAME_PARAMETER); } private String[] parsePatterns(String delimitedPatterns) { //make sure no patterns are repeated. Set patternSet = org.springframework.util.StringUtils.commaDelimitedListToSet(delimitedPatterns); String[] patterns = new String[patternSet.size()]; int i = 0; for (Iterator iterator = patternSet.iterator(); iterator.hasNext(); i++) { //no trailing/leading white space. String pattern = (String) iterator.next(); patterns[i] = pattern.trim(); } return patterns; } /** * This method checks to see if the current path matches includes or excludes. If it matches includes and * not excludes, it forwards to the static resource and ends the filter chain. Otherwise, it forwards to the * next filter in the chain. * * @param request the current request * @param response the current response * @param chain the filter chain * @throws IOException * @throws ServletException */ public void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { UrlPathHelper urlPathHelper = new UrlPathHelper(); String path = urlPathHelper.getPathWithinApplication(request); boolean pathExcluded = PatternMatchUtils.simpleMatch(excludes, path); boolean pathIncluded = PatternMatchUtils.simpleMatch(includes, path); if (pathIncluded && !pathExcluded) { if (logger.isDebugEnabled()) { logger.debug("Forwarding to static resource: " + path); } RequestDispatcher rd = getServletContext().getRequestDispatcher(path); rd.forward(request, response); return; } if (servletName != null) { RequestDispatcher rd = getServletContext().getNamedDispatcher(servletName); rd.forward(request, response); return; } chain.doFilter(request, response); } } -- View this message in context: http://www.nabble.com/Using-a-StaticFilter-and-dispatching-to-FacesServlet-doesn%27t-work-tf3450338.html#a9623982 Sent from the MyFaces - Users mailing list archive at Nabble.com.