tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1600580 - in /tomcat/trunk/java/org/apache/catalina: connector/Response.java core/StandardWrapperValve.java valves/ErrorReportValve.java
Date Thu, 05 Jun 2014 10:04:46 GMT
Author: markt
Date: Thu Jun  5 10:04:45 2014
New Revision: 1600580

URL: http://svn.apache.org/r1600580
Log:
Fix further regressions in the error handling changes
(r1600449 and r1600495)

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/Response.java
    tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java
    tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java

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=1600580&r1=1600579&r2=1600580&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Thu Jun  5 10:04:45 2014
@@ -198,6 +198,7 @@ public class Response
      * The error flag.
      */
     protected boolean error = false;
+    private boolean errorAfterCommit = false;
 
 
     /**
@@ -239,6 +240,7 @@ public class Response
         appCommitted = false;
         included = false;
         error = false;
+        errorAfterCommit = false;
         isCharacterEncodingSet = false;
 
         if (Globals.IS_SECURITY_ENABLED || Connector.RECYCLE_FACADES) {
@@ -388,6 +390,7 @@ public class Response
     public void setError() {
         if (!error) {
             error = true;
+            errorAfterCommit = coyoteResponse.isCommitted();
             Wrapper wrapper = getRequest().getWrapper();
             if (wrapper != null) {
                 wrapper.incrementErrorCount();
@@ -404,6 +407,11 @@ public class Response
     }
 
 
+    public boolean isErrorAfterCommit() {
+        return errorAfterCommit;
+    }
+
+
     /**
      * Perform whatever actions are required to flush and close the output
      * stream or writer, in a single operation.
@@ -1775,7 +1783,4 @@ public class Response
         return (sb.toString());
 
     }
-
-
 }
-

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java?rev=1600580&r1=1600579&r2=1600580&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapperValve.java Thu Jun  5 10:04:45
2014
@@ -508,7 +508,7 @@ final class StandardWrapperValve
                            Throwable exception) {
         request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, exception);
         response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-
+        response.setError();
     }
 
     public long getProcessingTime() {

Modified: tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java?rev=1600580&r1=1600579&r2=1600580&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/ErrorReportValve.java Thu Jun  5 10:04:45
2014
@@ -78,25 +78,21 @@ public class ErrorReportValve extends Va
         // Perform the request
         getNext().invoke(request, response);
 
-        // Check the response for an error
-        Throwable throwable = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
-
-        if (response.getStatus() < 400 && throwable == null && !response.isError()
||
-                request.isAsyncDispatching()) {
+        if (response.isCommitted()) {
+            if (response.isErrorAfterCommit()) {
+                // Flush any data that is still to be written to the client
+                response.flushBuffer();
+                // Close immediately to signal to the client that something went
+                // wrong
+                response.getCoyoteResponse().action(ActionCode.CLOSE_NOW, null);
+            }
             return;
         }
 
-        // If we get this far then there has been an error
+        Throwable throwable = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
 
-        if (response.isCommitted()) {
-            // Flush any data that is still to be written to the client
-            response.flushBuffer();
-            // Mark the response as in error
-            response.setError();
-            response.getCoyoteResponse().setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
-            // Close immediately to signal to the client that something went
-            // wrong
-            response.getCoyoteResponse().action(ActionCode.CLOSE_NOW, null);
+        if (request.isAsyncStarted() && ((response.getStatus() < 400 &&
+                throwable == null) || request.isAsyncDispatching())) {
             return;
         }
 
@@ -142,6 +138,12 @@ public class ErrorReportValve extends Va
 
         int statusCode = response.getStatus();
 
+        // Do nothing on a 1xx, 2xx and 3xx status
+        // Do nothing if anything has been written already
+        // Do nothing if the response hasn't been explicitly marked as in error
+        if (statusCode < 400 || response.getContentWritten() > 0 || !response.isError())
{
+            return;
+        }
         String message = RequestUtil.filter(response.getMessage());
         if (message == null) {
             if (throwable != null) {



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


Mime
View raw message