Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E005311DD5 for ; Thu, 5 Jun 2014 10:05:10 +0000 (UTC) Received: (qmail 89042 invoked by uid 500); 5 Jun 2014 10:05:10 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 88933 invoked by uid 500); 5 Jun 2014 10:05:10 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 88922 invoked by uid 99); 5 Jun 2014 10:05:10 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jun 2014 10:05:10 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jun 2014 10:05:10 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 2A900238890B for ; Thu, 5 Jun 2014 10:04:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140605100446.2A900238890B@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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