roller-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gango...@apache.org
Subject svn commit: r219427 - in /incubator/roller/trunk: metadata/xdoclet/ src/org/roller/presentation/filters/ src/org/roller/presentation/velocity/
Date Sun, 17 Jul 2005 23:38:46 GMT
Author: gangolli
Date: Sun Jul 17 16:38:42 2005
New Revision: 219427

URL: http://svn.apache.org/viewcvs?rev=219427&view=rev
Log:
Fix for ROL-760.  Extracted the setting of character encoding and synchronization of JSTL
and Struts locale from RequestFilter and put it in CharEncodingFilter, which is mapped for
all URIs.

Removed setting of character encoding in the SearchServlet, which was happening too late.
 An earlier getParameterMap() call in BasePageServlet was causing the request encoding used
for parameters to be determined by that point.

Added:
    incubator/roller/trunk/src/org/roller/presentation/filters/CharEncodingFilter.java   (with
props)
Modified:
    incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml
    incubator/roller/trunk/src/org/roller/presentation/filters/RequestFilter.java
    incubator/roller/trunk/src/org/roller/presentation/velocity/SearchServlet.java

Modified: incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml?rev=219427&r1=219426&r2=219427&view=diff
==============================================================================
--- incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml (original)
+++ incubator/roller/trunk/metadata/xdoclet/filter-mappings.xml Sun Jul 17 16:38:42 2005
@@ -5,18 +5,32 @@
     ******************************************************* -->
 
 <!--
+     NOTE: Wherever "dispatcher" elements are specified in the filter mappings, they are
+     required for Servlet API 2.4 containers, such as Tomcat 5+ and Resin 3+, but should
be
+     commented out for Servlet API 2.3 containers, like Tomcat 4.x and Resin 2.x.
+-->
+
+<!--
 <filter-mapping>
     <filter-name>UrlRewriteFilter</filter-name>
     <url-pattern>/*</url-pattern>
 </filter-mapping>
 -->
 
-<!-- Map everything to the PersistenceSessionFilter -->
+<!-- Ensures character encoding set to UTF-8 and JSTL and Struts locales are in sync.
+     Note: Any filters preceding this one MUST not cause request parsing. -->
+<filter-mapping>
+    <filter-name>CharEncodingFilter</filter-name>
+    <url-pattern>/*</url-pattern>
+    <dispatcher>REQUEST</dispatcher>
+    <dispatcher>FORWARD</dispatcher>
+</filter-mapping>
+
+<!-- Map everything to the PersistenceSessionFilter.
+     NOTE: Any filters preceding this one MUST NOT use persistence sessions.-->
 <filter-mapping>
     <filter-name>PersistenceSessionFilter</filter-name>
     <url-pattern>/*</url-pattern>
-    <!-- You must uncomment these two dispatcher lines on Tomcat 5+ and any Servlet API
2.4+ container
-         in order to avoid database connection leaks on the FORWARD dispatch paths. -->
     <dispatcher>REQUEST</dispatcher>
     <dispatcher>FORWARD</dispatcher>
 </filter-mapping>
@@ -64,8 +78,6 @@
 <filter-mapping>
     <filter-name>loginFilter</filter-name>
     <url-pattern>/login.jsp</url-pattern>
-    <!-- You must uncomment these two dispatcher lines on Tomcat 5+ and any Servlet API
2.4+ container
-         in order for RememberMe to work in these environments, because we can reach login.jsp
via FORWARD. -->
     <dispatcher>REQUEST</dispatcher>
     <dispatcher>FORWARD</dispatcher>
 </filter-mapping>

Added: incubator/roller/trunk/src/org/roller/presentation/filters/CharEncodingFilter.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/filters/CharEncodingFilter.java?rev=219427&view=auto
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/filters/CharEncodingFilter.java (added)
+++ incubator/roller/trunk/src/org/roller/presentation/filters/CharEncodingFilter.java Sun
Jul 17 16:38:42 2005
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2005
+ * Anil R. Gangolli. All rights reserved.
+ *
+ * Distributed with the Roller Weblogger Project under the terms of the Roller Software
+ * License
+ */
+
+package org.roller.presentation.filters;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.Locale;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.jstl.core.Config;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.struts.Globals;
+
+/**
+ * Entry point filter for all requests.  This filter ensures that the request encoding is
set to UTF-8 before any other
+ * processing forces request parsing using a default encoding.  It also syncs up the Struts
and JSTL locales.  This
+ * filter should normally be first and last in the chain.
+ *
+ * @author Anil Gangolli
+ * @web.filter name="CharEncodingFilter"
+ */
+
+public class CharEncodingFilter implements Filter
+{
+    private FilterConfig mFilterConfig = null;
+    private static Log mLogger =
+        LogFactory.getFactory().getInstance(CharEncodingFilter.class);
+
+    /**
+     * init
+     */
+    public void init(FilterConfig filterConfig) throws ServletException
+    {
+        mFilterConfig = filterConfig;
+    }
+
+    /**
+     * destroy
+     */
+    public void destroy()
+    {
+    }
+
+    /**
+     * Set the character encoding and sync up Struts and JSTL locales.  This filter should
normally be first (and last)
+     * in the chain.
+     */
+    public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
+        throws IOException, ServletException
+    {
+        if (mLogger.isDebugEnabled()) mLogger.debug("Processing CharEncodingFilter");
+        try
+        {
+            req.setCharacterEncoding("UTF-8");
+            if (mLogger.isDebugEnabled()) mLogger.debug("Set request character encoding to
UTF-8");
+        }
+        catch (UnsupportedEncodingException e)
+        {
+            // This should never happen since UTF-8 is a Java-specified required encoding.
+            throw new ServletException("Can't set incoming encoding to UTF-8");
+        }
+
+        // Keep JSTL and Struts Locale's in sync
+        // NOTE: The session here will get created if it is not present.  This code was taken
from its
+        // earlier incarnation in RequestFilter, which also caused the session to be created.
+        HttpSession session = ((HttpServletRequest) req).getSession();
+        if (mLogger.isDebugEnabled()) mLogger.debug("Synchronizing JSTL and Struts locales");
+        Locale locale = (Locale) session.getAttribute(Globals.LOCALE_KEY);
+        if (locale == null)
+        {
+            locale = req.getLocale();
+        }
+        if (req.getParameter("locale") != null)
+        {
+            locale = new Locale(req.getParameter("locale"));
+        }
+        session.setAttribute(Globals.LOCALE_KEY, locale);
+        Config.set(session, Config.FMT_LOCALE, locale);
+
+        chain.doFilter(req, res);
+    }
+
+}

Propchange: incubator/roller/trunk/src/org/roller/presentation/filters/CharEncodingFilter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/roller/trunk/src/org/roller/presentation/filters/RequestFilter.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/filters/RequestFilter.java?rev=219427&r1=219426&r2=219427&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/filters/RequestFilter.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/filters/RequestFilter.java Sun Jul
17 16:38:42 2005
@@ -49,40 +49,15 @@
     }
 
     /**
-     * As the first and last filter in the chain, it is necessary that
-     * RequestFilter releases its Roller resources before it returns.
+     * Request filter.
      */
     public void doFilter(
         ServletRequest req, ServletResponse res, FilterChain chain)
         throws IOException, ServletException
     {
-        try
-        {
-            // insure that incoming data is parsed as UTF-8
-            req.setCharacterEncoding("UTF-8");
-        }
-        catch (UnsupportedEncodingException e)
-        {
-            throw new ServletException("Can't set incoming encoding to UTF-8");
-        }
-
-        // keep JSTL and Struts Locale's in sync
+        // NOTE: Setting character encoding and JSTL/Struts locale sync has been moved to
+        // CharEncodingFilter, which is mapped for all URIs in the context.
         HttpSession session = ((HttpServletRequest)req).getSession();
-        if (null != session)
-        {
-            Locale locale = (Locale)session.getAttribute(Globals.LOCALE_KEY);
-            if (locale == null)
-            {
-                locale = req.getLocale();
-            }
-            if (req.getParameter("locale") != null)
-            {
-                locale = new Locale(req.getParameter("locale"));
-            }
-            session.setAttribute(Globals.LOCALE_KEY, locale);
-            Config.set(session, Config.FMT_LOCALE, locale);
-        }
-
         HttpServletRequest request = (HttpServletRequest)req;
         HttpServletResponse response = (HttpServletResponse)res;
         Roller roller = RollerContext.getRoller( request );

Modified: incubator/roller/trunk/src/org/roller/presentation/velocity/SearchServlet.java
URL: http://svn.apache.org/viewcvs/incubator/roller/trunk/src/org/roller/presentation/velocity/SearchServlet.java?rev=219427&r1=219426&r2=219427&view=diff
==============================================================================
--- incubator/roller/trunk/src/org/roller/presentation/velocity/SearchServlet.java (original)
+++ incubator/roller/trunk/src/org/roller/presentation/velocity/SearchServlet.java Sun Jul
17 16:38:42 2005
@@ -1,14 +1,11 @@
 package org.roller.presentation.velocity;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.util.Date;
 import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
-
-import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.jsp.JspFactory;
@@ -39,6 +36,7 @@
 import org.roller.util.StringUtils;
 
 
+
 /**
  * This servlet retrieves (and displays) search results.
  *
@@ -69,6 +67,9 @@
     public Template handleRequest(HttpServletRequest request,
                         HttpServletResponse response, Context ctx) throws Exception
     {
+        // Note: Removed request character encoding here; was too late; it is now set uniformly
in CharEncodingFilter.
+        // See ROL-760.
+
         String enabled = RollerConfig.getProperty("search.enabled");
         if("false".equalsIgnoreCase(enabled))
             this.searchEnabled = false;
@@ -91,20 +92,7 @@
             }
             return outty;
         }
-        
-         // set request Charcter Encoding here, because the SearchServlet
-         // is not preceeded by the RequestFilter
-         mLogger.debug("handleRequest()");
-		try
-		{
-			// insure that incoming data is parsed as UTF-8
-			request.setCharacterEncoding("UTF-8");
-		}
-		catch (UnsupportedEncodingException e)
-		{
-			throw new ServletException("Can't set incoming encoding to UTF-8");
-		}
-    	        
+
         ctx.put("term", "");
         ctx.put("hits", new Integer(0));
         ctx.put("searchResults", new TreeMap());          



Mime
View raw message