Author: markt
Date: Wed Sep 18 13:21:08 2013
New Revision: 1524400

URL: http://svn.apache.org/r1524400
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=46727
 Refactor default servlet to make it easier to sub-class to implement finer 
grained control of the file encoding. Based on a patch by Fred Toth.

Modified:
    tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java?rev=1524400&r1=1524399&r2=1524400&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java 
(original)
+++ tomcat/trunk/java/org/apache/catalina/servlets/DefaultServlet.java Wed Sep 
18 13:21:08 2013
@@ -387,7 +387,7 @@ public class DefaultServlet
         throws IOException, ServletException {
 
         // Serve the requested resource, including the data content
-        serveResource(request, response, true);
+        serveResource(request, response, true, fileEncoding);
 
     }
 
@@ -407,7 +407,7 @@ public class DefaultServlet
         throws IOException, ServletException {
 
         // Serve the requested resource, without the data content
-        serveResource(request, response, false);
+        serveResource(request, response, false, fileEncoding);
 
     }
 
@@ -664,16 +664,19 @@ public class DefaultServlet
     /**
      * Serve the specified resource, optionally including the data content.
      *
-     * @param request The servlet request we are processing
+     * @param request  The servlet request we are processing
      * @param response The servlet response we are creating
-     * @param content Should the content be included?
+     * @param content  Should the content be included?
+     * @param encoding The encoding to use if it is necessary to access the
+     *                 source as characters rather than as bytes
      *
      * @exception IOException if an input/output error occurs
      * @exception ServletException if a servlet-specified error occurs
      */
     protected void serveResource(HttpServletRequest request,
                                  HttpServletResponse response,
-                                 boolean content)
+                                 boolean content,
+                                 String encoding)
         throws IOException, ServletException {
 
         boolean serveContent = content;
@@ -877,7 +880,7 @@ public class DefaultServlet
                             contentLength, null))
                         copy(resource, renderResult, ostream);
                 } else {
-                    copy(resource, renderResult, writer);
+                    copy(resource, renderResult, writer, encoding);
                 }
             }
 
@@ -1764,11 +1767,12 @@ public class DefaultServlet
      * @param resource  The source resource
      * @param is        The input stream to read the source resource from
      * @param writer    The writer to write to
+     * @param encoding  The encoding to use when reading the source input 
stream
      *
      * @exception IOException if an input/output error occurs
      */
-    protected void copy(WebResource resource, InputStream is, PrintWriter 
writer)
-            throws IOException {
+    protected void copy(WebResource resource, InputStream is, PrintWriter 
writer,
+            String encoding) throws IOException {
 
         IOException exception = null;
 
@@ -1780,11 +1784,10 @@ public class DefaultServlet
         }
 
         Reader reader;
-        if (fileEncoding == null) {
+        if (encoding == null) {
             reader = new InputStreamReader(resourceInputStream);
         } else {
-            reader = new InputStreamReader(resourceInputStream,
-                                           fileEncoding);
+            reader = new InputStreamReader(resourceInputStream, encoding);
         }
 
         // Copy the input stream to the output stream

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1524400&r1=1524399&r2=1524400&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Wed Sep 18 13:21:08 2013
@@ -65,6 +65,11 @@
         contributions from Nick Williams, Rossen Stoyanchev and Niki Dokovski.
         (markt)
       </add>
+      <update>
+        <bug>46727</bug>: Refactor default servlet to make it easier to
+        sub-class to implement finer grained control of the file encoding. 
Based
+        on a patch by Fred Toth. (markt)
+      </update>
       <add>
         <bug>45995</bug>: Align Tomcat with Apache httpd and perform MIME type
         mapping based on file extension in a case insensitive manner. (markt)



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to