Author: markt Date: Fri Jan 26 12:39:52 2018 New Revision: 1822286 URL: http://svn.apache.org/viewvc?rev=1822286&view=rev Log: Refactor error handling to enable errors that occur before processing is passed to the application to be handled by the application provided error handling and/or the container provided error handling (ErrorReportValve) as appropriate.
Modified: tomcat/trunk/java/org/apache/catalina/connector/Response.java tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java tomcat/trunk/webapps/docs/changelog.xml 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=1822286&r1=1822285&r2=1822286&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/Response.java (original) +++ tomcat/trunk/java/org/apache/catalina/connector/Response.java Fri Jan 26 12:39:52 2018 @@ -879,12 +879,17 @@ public class Response implements HttpSer return; } - String charset = getContext().getCharset(locale); - if (charset != null) { - try { - getCoyoteResponse().setCharacterEncoding(charset); - } catch (UnsupportedEncodingException e) { - log.warn(sm.getString("coyoteResponse.encoding.invalid", charset), e); + // In some error handling scenarios, the context is unknown + // (e.g. a 404 when a ROOT context is not present) + Context context = getContext(); + if (context != null) { + String charset = context.getCharset(locale); + if (charset != null) { + try { + getCoyoteResponse().setCharacterEncoding(charset); + } catch (UnsupportedEncodingException e) { + log.warn(sm.getString("coyoteResponse.encoding.invalid", charset), e); + } } } } Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=1822286&r1=1822285&r2=1822286&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original) +++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Fri Jan 26 12:39:52 2018 @@ -186,7 +186,6 @@ standardEngine.jvmRouteFail=Failed to se standardEngine.noHost=No Host matches server name [{0}] standardEngine.notHost=Child of an Engine must be a Host standardEngine.notParent=Engine cannot have a parent Container -standardHost.asyncStateError=An asynchronous request was received for processing that was neither an async dispatch nor an error to process standardHost.clientAbort=Remote Client Aborted Request, IOException: [{0}] standardHost.invalidErrorReportValveClass=Couldn''t load specified error report valve class: [{0}] standardHost.noContext=No Context configured to process this request Modified: tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java?rev=1822286&r1=1822285&r2=1822286&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/StandardHostValve.java Fri Jan 26 12:39:52 2018 @@ -108,8 +108,6 @@ final class StandardHostValve extends Va // Select the Context to be used for this Request Context context = request.getContext(); if (context == null) { - response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, - sm.getString("standardHost.noContext")); return; } @@ -118,7 +116,6 @@ final class StandardHostValve extends Va } boolean asyncAtStart = request.isAsync(); - boolean asyncDispatching = request.isAsyncDispatching(); try { context.bind(Globals.IS_SECURITY_ENABLED, MY_CLASSLOADER); @@ -136,14 +133,8 @@ final class StandardHostValve extends Va // in error and have been routed here to check for application // defined error pages. try { - if (!asyncAtStart || asyncDispatching) { + if (!response.isErrorReportRequired()) { context.getPipeline().getFirst().invoke(request, response); - } else { - // Make sure this request/response is here because an error - // report is required. - if (!response.isErrorReportRequired()) { - throw new IllegalStateException(sm.getString("standardHost.asyncStateError")); - } } } catch (Throwable t) { ExceptionUtils.handleThrowable(t); Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1822286&r1=1822285&r2=1822286&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Fri Jan 26 12:39:52 2018 @@ -69,6 +69,12 @@ rather than the user facing Principal object as Tomcat requires the internal object to correctly process later authorization checks. (markt) </fix> + <add> + Refactor error handling to enable errors that occur before processing is + passed to the application to be handled by the application provided + error handling and/or the container provided error handling + (<code>ErrorReportValve</code>) as appropriate. (markt) + </add> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org