Author: markt Date: Wed Jan 31 15:14:25 2018 New Revision: 1822809 URL: http://svn.apache.org/viewvc?rev=1822809&view=rev Log: Push the error state tracking down to the Coyote Response so it becomes accessible to the early stages of request processing. The intention is to use this to enable those early stage errors to be handled by the standard error reporting mechanisms rather than just a status code and a blank page.
Modified: tomcat/trunk/java/org/apache/catalina/connector/Response.java tomcat/trunk/java/org/apache/coyote/Response.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=1822809&r1=1822808&r2=1822809&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original) +++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Wed Jan 31 15:14:25 2018 @@ -36,7 +36,6 @@ import java.util.Locale; import java.util.Map; import java.util.TimeZone; import java.util.Vector; -import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import javax.servlet.ServletOutputStream; @@ -179,37 +178,6 @@ public class Response implements HttpSer */ private boolean isCharacterEncodingSet = false; - /** - * With the introduction of async processing and the possibility of - * non-container threads calling sendError() tracking the current error - * state and ensuring that the correct error page is called becomes more - * complicated. This state attribute helps by tracking the current error - * state and informing callers that attempt to change state if the change - * was successful or if another thread got there first. - * - * <pre> - * The state machine is very simple: - * - * 0 - NONE - * 1 - NOT_REPORTED - * 2 - REPORTED - * - * - * -->---->-- >NONE - * | | | - * | | | setError() - * ^ ^ | - * | | \|/ - * | |-<-NOT_REPORTED - * | | - * ^ | report() - * | | - * | \|/ - * |----<----REPORTED - * </pre> - */ - private final AtomicInteger errorState = new AtomicInteger(0); - /** * Using output stream flag. @@ -258,7 +226,6 @@ public class Response implements HttpSer usingWriter = false; appCommitted = false; included = false; - errorState.set(0); isCharacterEncodingSet = false; applicationResponse = null; @@ -438,7 +405,7 @@ public class Response implements HttpSer * @return <code>false</code> if the error flag was already set */ public boolean setError() { - boolean result = errorState.compareAndSet(0, 1); + boolean result = getCoyoteResponse().setError(); if (result) { Wrapper wrapper = getRequest().getWrapper(); if (wrapper != null) { @@ -455,17 +422,17 @@ public class Response implements HttpSer * @return <code>true</code> if the response has encountered an error */ public boolean isError() { - return errorState.get() > 0; + return getCoyoteResponse().isError(); } public boolean isErrorReportRequired() { - return errorState.get() == 1; + return getCoyoteResponse().isErrorReportRequired(); } public boolean setErrorReported() { - return errorState.compareAndSet(1, 2); + return getCoyoteResponse().setErrorReported(); } Modified: tomcat/trunk/java/org/apache/coyote/Response.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/Response.java?rev=1822809&r1=1822808&r2=1822809&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/Response.java (original) +++ tomcat/trunk/java/org/apache/coyote/Response.java Wed Jan 31 15:14:25 2018 @@ -24,6 +24,7 @@ import java.nio.charset.Charset; import java.util.Locale; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import javax.servlet.WriteListener; @@ -128,8 +129,40 @@ public final class Response { */ Exception errorException = null; + /** + * With the introduction of async processing and the possibility of + * non-container threads calling sendError() tracking the current error + * state and ensuring that the correct error page is called becomes more + * complicated. This state attribute helps by tracking the current error + * state and informing callers that attempt to change state if the change + * was successful or if another thread got there first. + * + * <pre> + * The state machine is very simple: + * + * 0 - NONE + * 1 - NOT_REPORTED + * 2 - REPORTED + * + * + * -->---->-- >NONE + * | | | + * | | | setError() + * ^ ^ | + * | | \|/ + * | |-<-NOT_REPORTED + * | | + * ^ | report() + * | | + * | \|/ + * |----<----REPORTED + * </pre> + */ + private final AtomicInteger errorState = new AtomicInteger(0); + Request req; + // ------------------------------------------------------------- Properties public Request getRequest() { @@ -241,7 +274,6 @@ public final class Response { // -----------------Error State -------------------- - /** * Set the error Exception that occurred during request processing. * @@ -267,8 +299,37 @@ public final class Response { } - // -------------------- Methods -------------------- + /** + * Set the error flag. + * + * @return <code>false</code> if the error flag was already set + */ + public boolean setError() { + return errorState.compareAndSet(0, 1); + } + + + /** + * Error flag accessor. + * + * @return <code>true</code> if the response has encountered an error + */ + public boolean isError() { + return errorState.get() > 0; + } + + + public boolean isErrorReportRequired() { + return errorState.get() == 1; + } + + + public boolean setErrorReported() { + return errorState.compareAndSet(1, 2); + } + + // -------------------- Methods -------------------- public void reset() throws IllegalStateException { @@ -554,6 +615,7 @@ public final class Response { commited = false; commitTime = -1; errorException = null; + errorState.set(0); headers.clear(); trailerFieldsSupplier = null; // Servlet 3.1 non-blocking write listener --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org