tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1240821 - in /tomcat/trunk: java/org/apache/catalina/connector/OutputBuffer.java java/org/apache/catalina/connector/Response.java test/org/apache/catalina/connector/TestOutputBuffer.java
Date Sun, 05 Feb 2012 21:12:42 GMT
Author: markt
Date: Sun Feb  5 21:12:42 2012
New Revision: 1240821

URL: http://svn.apache.org/viewvc?rev=1240821&view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=52577
Only reset the encoder information when the 'has getWriter()' been
called flag is reset.
Includes a simple test case

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
    tomcat/trunk/java/org/apache/catalina/connector/Response.java
    tomcat/trunk/test/org/apache/catalina/connector/TestOutputBuffer.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java?rev=1240821&r1=1240820&r2=1240821&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/OutputBuffer.java Sun Feb  5 21:12:42
2012
@@ -583,6 +583,10 @@ public class OutputBuffer extends Writer
 
 
     public void reset() {
+        reset(false);
+    }
+
+    public void reset(boolean resetWriterStreamFlags) {
         // If a Writer was being used, there may be bytes in the converter
         if (gotEnc && conv != null) {
             conv.recycle();
@@ -590,8 +594,10 @@ public class OutputBuffer extends Writer
         bb.recycle();
         bytesWritten = 0;
         charsWritten = 0;
-        gotEnc = false;
-        enc = null;
+        if (resetWriterStreamFlags) {
+            gotEnc = false;
+            enc = null;
+        }
         initial = true;
     }
 

Modified: tomcat/trunk/java/org/apache/catalina/connector/Response.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Response.java?rev=1240821&r1=1240820&r2=1240821&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Sun Feb  5 21:12:42 2012
@@ -624,7 +624,7 @@ public class Response
                 (sm.getString("coyoteResponse.resetBuffer.ise"));
         }
 
-        outputBuffer.reset();
+        outputBuffer.reset(resetWriterStreamFlags);
 
         if(resetWriterStreamFlags) {
             usingOutputStream = false;

Modified: tomcat/trunk/test/org/apache/catalina/connector/TestOutputBuffer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/connector/TestOutputBuffer.java?rev=1240821&r1=1240820&r2=1240821&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/connector/TestOutputBuffer.java (original)
+++ tomcat/trunk/test/org/apache/catalina/connector/TestOutputBuffer.java Sun Feb  5 21:12:42
2012
@@ -70,6 +70,25 @@ public class TestOutputBuffer extends To
         }
     }
 
+    @Test
+    public void testBug52577() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        Context root = tomcat.addContext("", TEMP_DIR);
+
+        Bug52577Servlet bug52577 = new Bug52577Servlet();
+        Tomcat.addServlet(root, "bug52577", bug52577);
+        root.addServletMapping("/", "bug52577");
+
+        tomcat.start();
+
+        ByteChunk bc = new ByteChunk();
+
+        int rc = getUrl("http://localhost:" + getPort() + "/", bc, null, null);
+        assertEquals(HttpServletResponse.SC_OK, rc);
+        assertEquals("OK", bc.toString());
+    }
+
     private static class WritingServlet extends HttpServlet {
 
         private static final long serialVersionUID = 1L;
@@ -117,4 +136,18 @@ public class TestOutputBuffer extends To
                     ", Time: " + lastRunNano + "ns");
         }
     }
+
+    private static class Bug52577Servlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            Writer w = resp.getWriter();
+            w.write("OK");
+            resp.resetBuffer();
+            w.write("OK");
+        }
+    }
 }



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


Mime
View raw message