Author: tv
Date: Sat Jul 28 15:37:19 2018
New Revision: 1836928

URL: http://svn.apache.org/viewvc?rev=1836928&view=rev
Log:
Initial attempt to resolve the character encoding mess

Added:
    
turbine/core/trunk/src/java/org/apache/turbine/pipeline/DefaultSetEncodingValve.java
   (with props)
Modified:
    turbine/core/trunk/conf/turbine-classic-pipeline.xml
    turbine/core/trunk/src/java/org/apache/turbine/Turbine.java

Modified: turbine/core/trunk/conf/turbine-classic-pipeline.xml
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/conf/turbine-classic-pipeline.xml?rev=1836928&r1=1836927&r2=1836928&view=diff
==============================================================================
--- turbine/core/trunk/conf/turbine-classic-pipeline.xml (original)
+++ turbine/core/trunk/conf/turbine-classic-pipeline.xml Sat Jul 28 15:37:19 
2018
@@ -19,6 +19,7 @@
 -->
 <pipeline name="default">
   <valves>
+    <valve>org.apache.turbine.pipeline.DefaultSetEncodingValve</valve>
     <valve>org.apache.turbine.pipeline.DetermineActionValve</valve>
     <valve>org.apache.turbine.pipeline.DetermineTargetValve</valve>
     <valve>org.apache.turbine.pipeline.DefaultSessionTimeoutValve</valve>

Modified: turbine/core/trunk/src/java/org/apache/turbine/Turbine.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/Turbine.java?rev=1836928&r1=1836927&r2=1836928&view=diff
==============================================================================
--- turbine/core/trunk/src/java/org/apache/turbine/Turbine.java (original)
+++ turbine/core/trunk/src/java/org/apache/turbine/Turbine.java Sat Jul 28 
15:37:19 2018
@@ -24,7 +24,6 @@ import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -164,7 +163,7 @@ public class Turbine
     private static Configuration configuration = null;
 
     /** Default Input encoding if the servlet container does not report an 
encoding */
-    private String inputEncoding = null;
+    private static String inputEncoding = 
TurbineConstants.PARAMETER_ENCODING_DEFAULT;
 
     /** Which configuration method is being used */
     private enum ConfigurationStyle
@@ -369,7 +368,7 @@ public class Turbine
         configuration.setProperty(TurbineConstants.APPLICATION_ROOT_KEY, 
applicationRoot);
         configuration.setProperty(TurbineConstants.WEBAPP_ROOT_KEY, 
webappRoot);
 
-        // Get the default input encoding
+        // Get the default input defaultEncoding
         inputEncoding = configuration.getString(
                 TurbineConstants.PARAMETER_ENCODING_KEY,
                 TurbineConstants.PARAMETER_ENCODING_DEFAULT);
@@ -378,7 +377,7 @@ public class Turbine
         {
             log.debug("Input Encoding has been set to " + inputEncoding);
         }
-        
+
         getServiceManager().setConfiguration(configuration);
 
         // Initialize the service manager. Services
@@ -399,7 +398,7 @@ public class Turbine
             log.debug("Using descriptor path: " + descriptorPath);
         }
 
-        // context resource path has to begin with slash, cft. 
context,getResource
+        // context resource path has to begin with slash, cft. 
context.getResource
         if (!descriptorPath.startsWith( "/" )) {
                descriptorPath  = "/" + descriptorPath;
         }
@@ -786,26 +785,6 @@ public class Turbine
                 throw initFailure;
             }
 
-            //
-            // If the servlet container gives us no clear indication about the
-            // Encoding of the contents, set it to our default value.
-            if (req.getCharacterEncoding() == null)
-            {
-                if (log.isDebugEnabled())
-                {
-                    log.debug("Changing Input Encoding to " + inputEncoding);
-                }
-
-                try
-                {
-                    req.setCharacterEncoding(inputEncoding);
-                }
-                catch (UnsupportedEncodingException uee)
-                {
-                    log.warn("Could not change request encoding to " + 
inputEncoding, uee);
-                }
-            }
-
             // Get general RunData here...
             // Perform turbine specific initialization below.
             pipelineData = getRunDataService().getRunData(req, res, 
getServletConfig());
@@ -1051,7 +1030,7 @@ public class Turbine
      *
      * @return the default input encoding.
      */
-    public String getDefaultInputEncoding()
+    public static String getDefaultInputEncoding()
     {
         return inputEncoding;
     }

Added: 
turbine/core/trunk/src/java/org/apache/turbine/pipeline/DefaultSetEncodingValve.java
URL: 
http://svn.apache.org/viewvc/turbine/core/trunk/src/java/org/apache/turbine/pipeline/DefaultSetEncodingValve.java?rev=1836928&view=auto
==============================================================================
--- 
turbine/core/trunk/src/java/org/apache/turbine/pipeline/DefaultSetEncodingValve.java
 (added)
+++ 
turbine/core/trunk/src/java/org/apache/turbine/pipeline/DefaultSetEncodingValve.java
 Sat Jul 28 15:37:19 2018
@@ -0,0 +1,80 @@
+package org.apache.turbine.pipeline;
+
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.turbine.Turbine;
+import org.apache.turbine.TurbineConstants;
+import org.apache.turbine.annotation.TurbineConfiguration;
+import org.apache.turbine.util.TurbineException;
+
+/**
+ * Set defaultEncoding of the request
+ *
+ * @author <a href="mailto:[email protected]";>Thomas Vandahl</a>
+ */
+public class DefaultSetEncodingValve
+    extends AbstractValve
+{
+    private static final Log log = 
LogFactory.getLog(DefaultSetEncodingValve.class);
+
+    @TurbineConfiguration( TurbineConstants.PARAMETER_ENCODING_KEY )
+    protected String defaultEncoding = 
TurbineConstants.PARAMETER_ENCODING_DEFAULT;
+
+    /**
+     * @see org.apache.turbine.pipeline.Valve#invoke(PipelineData, 
ValveContext)
+     */
+    @Override
+    public void invoke(PipelineData pipelineData, ValveContext context)
+        throws IOException, TurbineException
+    {
+        HttpServletRequest req = pipelineData.get(Turbine.class, 
HttpServletRequest.class);
+
+        // If the servlet container gives us no clear indication about the
+        // Encoding of the contents, set it to our default value.
+        if (req.getCharacterEncoding() == null)
+        {
+            if (log.isDebugEnabled())
+            {
+                log.debug("Changing Input Encoding to " + defaultEncoding);
+            }
+
+            try
+            {
+                req.setCharacterEncoding(defaultEncoding);
+            }
+            catch (UnsupportedEncodingException uee)
+            {
+                log.warn("Could not change request defaultEncoding to " + 
defaultEncoding, uee);
+            }
+        }
+
+        // Pass control to the next Valve in the Pipeline
+        context.invokeNext(pipelineData);
+    }
+}

Propchange: 
turbine/core/trunk/src/java/org/apache/turbine/pipeline/DefaultSetEncodingValve.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to