remm 01/10/04 12:27:58 Modified: catalina/src/share/org/apache/catalina/core Tag: tomcat_40_branch ApplicationDispatcher.java LocalStrings.properties LocalStrings_ja.properties StandardContextValve.java StandardHost.java StandardWrapperValve.java Log: - Merge a variety of fixes and small feature additions which have been made and debugged in the HEAD branch, including: - Removal of Jasper loader (merged with the shared loader). - Fixes a lot of spec complaince issue regarding the commit state of the response when using forwards, sendError or sendRedirect. - Fixes cache consistency issues for static resource serving. - Adds content caching for static resources (that's linked to the bugfix mentioned just above). - Merge enhanced error reporting and error page dispatching (which will be able to display error pages for most errors returned from the pipeline - like the 401 and 403 returned by the authenticator). - Merge the fixes for all the other more recent bugfixes that have been fixed in the HEAD branch. - Passes all tester and Watchdog tests. - Merge a variety of small enhancements to the build scripts which have been made in the HEAD branch. Revision Changes Path No revision No revision 1.25.2.1 +25 -18 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java Index: ApplicationDispatcher.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v retrieving revision 1.25 retrieving revision 1.25.2.1 diff -u -r1.25 -r1.25.2.1 --- ApplicationDispatcher.java 2001/08/08 00:31:54 1.25 +++ ApplicationDispatcher.java 2001/10/04 19:27:58 1.25.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v 1.25 2001/08/08 00:31:54 remm Exp $ - * $Revision: 1.25 $ - * $Date: 2001/08/08 00:31:54 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v 1.25.2.1 2001/10/04 19:27:58 remm Exp $ + * $Revision: 1.25.2.1 $ + * $Date: 2001/10/04 19:27:58 $ * * ==================================================================== * @@ -92,6 +92,7 @@ import org.apache.catalina.Request; import org.apache.catalina.Response; import org.apache.catalina.Wrapper; +import org.apache.catalina.connector.ResponseFacade; import org.apache.catalina.core.StandardWrapper; import org.apache.catalina.util.InstanceSupport; import org.apache.catalina.util.StringManager; @@ -108,7 +109,7 @@ * <code>javax.servlet.ServletResponseWrapper</code>. * * @author Craig R. McClanahan - * @version $Revision: 1.25 $ $Date: 2001/08/08 00:31:54 $ + * @version $Revision: 1.25.2.1 $ $Date: 2001/10/04 19:27:58 $ */ final class ApplicationDispatcher @@ -435,23 +436,29 @@ // Commit and close the response before we return if (debug >= 1) log(" Committing and closing response"); - response.flushBuffer(); - try { - PrintWriter writer = response.getWriter(); - writer.flush(); - writer.close(); - } catch (IllegalStateException e) { + + if (response instanceof ResponseFacade) { + ((ResponseFacade) response).finish(); + } else { + // Close anyway + response.flushBuffer(); try { - ServletOutputStream stream = response.getOutputStream(); - stream.flush(); - stream.close(); - } catch (IllegalStateException f) { - ; - } catch (IOException f) { + PrintWriter writer = response.getWriter(); + writer.flush(); + writer.close(); + } catch (IllegalStateException e) { + try { + ServletOutputStream stream = response.getOutputStream(); + stream.flush(); + stream.close(); + } catch (IllegalStateException f) { + ; + } catch (IOException f) { + ; + } + } catch (IOException e) { ; } - } catch (IOException e) { - ; } } 1.37.2.1 +0 -42 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties Index: LocalStrings.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings.properties,v retrieving revision 1.37 retrieving revision 1.37.2.1 diff -u -r1.37 -r1.37.2.1 --- LocalStrings.properties 2001/09/16 22:26:33 1.37 +++ LocalStrings.properties 2001/10/04 19:27:58 1.37.2.1 @@ -149,45 +149,3 @@ standardWrapper.unavailable=Marking servlet {0} as unavailable standardWrapper.unloadException=Servlet {0} threw unload() exception standardWrapper.unloading=Cannot allocate servlet {0} because it is being unloaded -http.100=The client may continue ({0}). -http.101=The server is switching protocols according to the "Upgrade" header ({0}). -http.201=The request succeeded and a new resource ({0}) has been created on the server. -http.202=This request was accepted for processing, but has not been completed ({0}). -http.203=The meta information presented by the client did not originate from the server ({0}). -http.204=The request succeeded but there is no information to return ({0}). -http.205=The client should reset the document view which caused this request to be sent ({0}). -http.206=The server has fulfilled a partial GET request for this resource ({0}). -http.207=Multiple status values have been returned ({0}). -http.300=The requested resource ({0}) corresponds to any one of a set of representations, each with its own specific location. -http.301=The requested resource ({0}) has moved permanently to a new location. -http.302=The requested resource ({0}) has moved temporarily to a new location. -http.303=The response to this request can be found under a different URI ({0}). -http.304=The requested resource ({0}) is available and has not been modified. -http.305=The requested resource ({0}) must be accessed through the proxy given by the "Location" header. -http.400=The request sent by the client was syntactically incorrect ({0}). -http.401=This request requires HTTP authentication ({0}). -http.402=Payment is required for access to this resource ({0}). -http.403=Access to the specified resource ({0}) has been forbidden. -http.404=The requested resource ({0}) is not available. -http.405=The specified HTTP method is not allowed for the requested resource ({0}). -http.406=The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ({0}). -http.407=The client must first authenticate itself with the proxy ({0}). -http.408=The client did not produce a request within the time that the server was prepared to wait ({0}). -http.409=The request could not be completed due to a conflict with the current state of the resource ({0}). -http.410=The requested resource ({0}) is no longer available, and no forwarding address is known. -http.411=This request cannot be handled without a defined content length ({0}). -http.412=A specified precondition has failed for this request ({0}). -http.413=The request entity is larger than the server is willing or able to process. -http.414=The server refused this request because the request URI was too long ({0}). -http.415=The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ({0}). -http.416=The requested byte range cannot be satisfied ({0}). -http.417=The expectation given in the "Expect" request header ({0}) could not be fulfilled. -http.422=The server understood the content type and syntax of the request but was unable to process the contained instructions ({0}). -http.423=The source or destination resource of a method is locked ({0}). -http.500=The server encountered an internal error ({0}) that prevented it from fulfilling this request. -http.501=The server does not support the functionality needed to fulfill this request ({0}). -http.502=This server received an invalid response from a server it consulted when acting as a proxy or gateway ({0}). -http.503=The requested service ({0}) is not currently available. -http.504=The server received a timeout from an upstream server while acting as a gateway or proxy ({0}). -http.505=The server does not support the requested HTTP protocol version ({0}). -http.507=The resource does not have sufficient space to record the state of the resource after execution of this method ({0}). 1.2.2.1 +0 -42 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings_ja.properties Index: LocalStrings_ja.properties =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/LocalStrings_ja.properties,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -r1.2 -r1.2.2.1 --- LocalStrings_ja.properties 2001/09/17 23:14:43 1.2 +++ LocalStrings_ja.properties 2001/10/04 19:27:58 1.2.2.1 @@ -149,45 +149,3 @@ standardWrapper.unavailable=\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8 {0} \u3092\u5229\u7528\u4e0d\u53ef\u80fd\u306b\u30de\u30fc\u30af\u3057\u307e\u3059 standardWrapper.unloadException=\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8 {0} \u306f\u3001unload()\u4f8b\u5916\u3092\u6295\u3052\u307e\u3057\u305f standardWrapper.unloading=\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8 {0} \u304c\u30ed\u30fc\u30c9\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067\u3001\u5272\u308a\u5f53\u3066\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u305b\u3093 -http.100=The client may continue ({0}). -http.101=The server is switching protocols according to the "Upgrade" header ({0}). -http.201=The request succeeded and a new resource ({0}) has been created on the server. -http.202=This request was accepted for processing, but has not been completed ({0}). -http.203=The meta information presented by the client did not originate from the server ({0}). -http.204=The request succeeded but there is no information to return ({0}). -http.205=The client should reset the document view which caused this request to be sent ({0}). -http.206=The server has fulfilled a partial GET request for this resource ({0}). -http.207=Multiple status values have been returned ({0}). -http.300=The requested resource ({0}) corresponds to any one of a set of representations, each with its own specific location. -http.301=The requested resource ({0}) has moved permanently to a new location. -http.302=The requested resource ({0}) has moved temporarily to a new location. -http.303=The response to this request can be found under a different URI ({0}). -http.304=The requested resource ({0}) is available and has not been modified. -http.305=The requested resource ({0}) must be accessed through the proxy given by the "Location" header. -http.400=The request sent by the client was syntactically incorrect ({0}). -http.401=This request requires HTTP authentication ({0}). -http.402=Payment is required for access to this resource ({0}). -http.403=Access to the specified resource ({0}) has been forbidden. -http.404=The requested resource ({0}) is not available. -http.405=The specified HTTP method is not allowed for the requested resource ({0}). -http.406=The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ({0}). -http.407=The client must first authenticate itself with the proxy ({0}). -http.408=The client did not produce a request within the time that the server was prepared to wait ({0}). -http.409=The request could not be completed due to a conflict with the current state of the resource ({0}). -http.410=The requested resource ({0}) is no longer available, and no forwarding address is known. -http.411=This request cannot be handled without a defined content length ({0}). -http.412=A specified precondition has failed for this request ({0}). -http.413=The request entity is larger than the server is willing or able to process. -http.414=The server refused this request because the request URI was too long ({0}). -http.415=The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ({0}). -http.416=The requested byte range cannot be satisfied ({0}). -http.417=The expectation given in the "Expect" request header ({0}) could not be fulfilled. -http.422=The server understood the content type and syntax of the request but was unable to process the contained instructions ({0}). -http.423=The source or destination resource of a method is locked ({0}). -http.500=The server encountered an internal error ({0}) that prevented it from fulfilling this request. -http.501=The server does not support the functionality needed to fulfill this request ({0}). -http.502=This server received an invalid response from a server it consulted when acting as a proxy or gateway ({0}). -http.503=The requested service ({0}) is not currently available. -http.504=The server received a timeout from an upstream server while acting as a gateway or proxy ({0}). -http.505=The server does not support the requested HTTP protocol version ({0}). -http.507=The resource does not have sufficient space to record the state of the resource after execution of this method ({0}). 1.12.2.1 +8 -49 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java Index: StandardContextValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -r1.12 -r1.12.2.1 --- StandardContextValve.java 2001/07/25 04:05:50 1.12 +++ StandardContextValve.java 2001/10/04 19:27:58 1.12.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v 1.12 2001/07/25 04:05:50 remm Exp $ - * $Revision: 1.12 $ - * $Date: 2001/07/25 04:05:50 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v 1.12.2.1 2001/10/04 19:27:58 remm Exp $ + * $Revision: 1.12.2.1 $ + * $Date: 2001/10/04 19:27:58 $ * * ==================================================================== * @@ -93,7 +93,7 @@ * when processing HTTP requests. * * @author Craig R. McClanahan - * @version $Revision: 1.12 $ $Date: 2001/07/25 04:05:50 $ + * @version $Revision: 1.12.2.1 $ $Date: 2001/10/04 19:27:58 $ */ final class StandardContextValve @@ -191,21 +191,12 @@ try { wrapper = (Wrapper) context.map(request, true); } catch (IllegalArgumentException e) { - badRequest(requestURI, (HttpServletResponse) response.getResponse()); - try { - response.finishResponse(); - } catch (IOException f) { - ; - } + badRequest(requestURI, + (HttpServletResponse) response.getResponse()); return; } if (wrapper == null) { notFound(requestURI, (HttpServletResponse) response.getResponse()); - try { - response.finishResponse(); - } catch (IOException e) { - ; - } return; } @@ -232,25 +223,9 @@ private void badRequest(String requestURI, HttpServletResponse response) { try { - requestURI = RequestUtil.filter(requestURI); - response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.setContentType("text/html"); - PrintWriter writer = response.getWriter(); - writer.println("<html>"); - writer.println("<head>"); - writer.println("<title>Tomcat Error Report</title>"); - writer.println("<body bgcolor=\"white\">"); - writer.println("<br><br>"); - writer.println("<h1>HTTP Status 400 - " + requestURI + "</h1>"); - writer.println(sm.getString("standardContext.badRequest", - requestURI)); - writer.println("</body>"); - writer.println("</html>"); - writer.flush(); + response.setStatus(HttpServletResponse.SC_BAD_REQUEST, requestURI); } catch (IllegalStateException e) { ; - } catch (IOException e) { - ; } } @@ -267,24 +242,8 @@ private void notFound(String requestURI, HttpServletResponse response) { try { - requestURI = RequestUtil.filter(requestURI); - response.setStatus(HttpServletResponse.SC_NOT_FOUND); - response.setContentType("text/html"); - PrintWriter writer = response.getWriter(); - writer.println("<html>"); - writer.println("<head>"); - writer.println("<title>Tomcat Error Report</title>"); - writer.println("<body bgcolor=\"white\">"); - writer.println("<br><br>"); - writer.println("<h1>HTTP Status 404 - " + requestURI + "</h1>"); - writer.println(sm.getString("standardContext.notFound", - requestURI)); - writer.println("</body>"); - writer.println("</html>"); - writer.flush(); + response.setStatus(HttpServletResponse.SC_NOT_FOUND, requestURI); } catch (IllegalStateException e) { - ; - } catch (IOException e) { ; } 1.18.2.1 +73 -4 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java Index: StandardHost.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v retrieving revision 1.18 retrieving revision 1.18.2.1 diff -u -r1.18 -r1.18.2.1 --- StandardHost.java 2001/08/27 19:10:25 1.18 +++ StandardHost.java 2001/10/04 19:27:58 1.18.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v 1.18 2001/08/27 19:10:25 craigmcc Exp $ - * $Revision: 1.18 $ - * $Date: 2001/08/27 19:10:25 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v 1.18.2.1 2001/10/04 19:27:58 remm Exp $ + * $Revision: 1.18.2.1 $ + * $Date: 2001/10/04 19:27:58 $ * * ==================================================================== * @@ -91,7 +91,9 @@ import org.apache.catalina.LifecycleListener; import org.apache.catalina.Request; import org.apache.catalina.Response; +import org.apache.catalina.Valve; import org.apache.catalina.core.DefaultContext; +import org.apache.catalina.valves.ErrorDispatcherValve; /** @@ -100,7 +102,8 @@ * requests directed to a particular web application. * * @author Craig R. McClanahan - * @version $Revision: 1.18 $ $Date: 2001/08/27 19:10:25 $ + * @author Remy Maucherat + * @version $Revision: 1.18.2.1 $ $Date: 2001/10/04 19:27:58 $ */ public class StandardHost @@ -154,6 +157,14 @@ /** + * The Java class name of the default error reporter implementation class + * for deployed web applications. + */ + private String errorReportValveClass = + "org.apache.catalina.valves.ErrorReportValve"; + + + /** * The descriptive information string for this implementation. */ private static final String info = @@ -304,6 +315,34 @@ /** + * Return the Java class name of the error report valve class + * for new web applications. + */ + public String getErrorReportValveClass() { + + return (this.errorReportValveClass); + + } + + + /** + * Set the Java class name of the error report valve class + * for new web applications. + * + * @param errorReportValveClass The new error report valve class + */ + public void setErrorReportValveClass(String errorReportValveClass) { + + String oldErrorReportValveClassClass = this.errorReportValveClass; + this.errorReportValveClass = errorReportValveClass; + support.firePropertyChange("errorReportValveClass", + oldErrorReportValveClassClass, + this.errorReportValveClass); + + } + + + /** * Return the canonical, fully qualified, name of the virtual host * this Container represents. */ @@ -541,6 +580,36 @@ sb.append(getName()); sb.append("]"); return (sb.toString()); + + } + + + /** + * Start this host. + * + * @exception IllegalStateException if this component has already been + * started + * @exception LifecycleException if this component detects a fatal error + * that prevents it from being started + */ + public synchronized void start() throws LifecycleException { + + // Set error report valve + if (errorReportValveClass != null) { + try { + Valve valve = (Valve) Class.forName(errorReportValveClass) + .newInstance(); + addValve(valve); + } catch (Throwable t) { + // FIXME + t.printStackTrace(); + } + } + + // Set dispatcher valve + addValve(new ErrorDispatcherValve()); + + super.start(); } 1.30.2.1 +11 -330 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java Index: StandardWrapperValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v retrieving revision 1.30 retrieving revision 1.30.2.1 diff -u -r1.30 -r1.30.2.1 --- StandardWrapperValve.java 2001/09/14 20:30:01 1.30 +++ StandardWrapperValve.java 2001/10/04 19:27:58 1.30.2.1 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v 1.30 2001/09/14 20:30:01 craigmcc Exp $ - * $Revision: 1.30 $ - * $Date: 2001/09/14 20:30:01 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v 1.30.2.1 2001/10/04 19:27:58 remm Exp $ + * $Revision: 1.30.2.1 $ + * $Date: 2001/10/04 19:27:58 $ * * ==================================================================== * @@ -103,7 +103,7 @@ * <code>StandardWrapper</code> container implementation. * * @author Craig R. McClanahan - * @version $Revision: 1.30 $ $Date: 2001/09/14 20:30:01 $ + * @version $Revision: 1.30.2.1 $ $Date: 2001/10/04 19:27:58 $ */ final class StandardWrapperValve @@ -229,7 +229,7 @@ // Create the filter chain for this request ApplicationFilterChain filterChain = - createFilterChain(request, servlet); + createFilterChain(request, servlet); // Call the filter chain for this request // NOTE: This also calls the servlet's service() method @@ -321,12 +321,6 @@ } } - - // Generate a response for the generated HTTP status and message - if (throwable == null) { - status(request, response); - } - } @@ -442,66 +436,6 @@ /** - * Handle an HTTP status code or Java exception by forwarding control - * to the location included in the specified errorPage object. It is - * assumed that the caller has already recorded any request attributes - * that are to be forwarded to this page. Return <code>true</code> if - * we successfully utilized the specified error page location, or - * <code>false</code> if the default error report should be rendered. - * - * @param request The request being processed - * @param response The response being generated - * @param errorPage The errorPage directive we are obeying - */ - private boolean custom(Request request, Response response, - ErrorPage errorPage) { - - if (debug >= 1) - log("Processing " + errorPage); - - // Validate our current environment - if (!(request instanceof HttpRequest)) { - if (debug >= 1) - log(" Not processing an HTTP request --> default handling"); - return (false); // NOTE - Nothing we can do generically - } - HttpServletRequest hreq = - (HttpServletRequest) request.getRequest(); - if (!(response instanceof HttpResponse)) { - if (debug >= 1) - log("Not processing an HTTP response --> default handling"); - return (false); // NOTE - Nothing we can do generically - } - HttpServletResponse hres = - (HttpServletResponse) response.getResponse(); - - try { - - // Reset the response if possible (else IllegalStateException) - hres.reset(); - - // Forward control to the specified location - ServletContext servletContext = - ((Context) container.getParent()).getServletContext(); - RequestDispatcher rd = - servletContext.getRequestDispatcher(errorPage.getLocation()); - rd.forward(hreq, hres); - - // Indicate that we have successfully processed this custom page - return (true); - - } catch (Throwable t) { - - // Report our failure to process this custom page - log("Exception Processing " + errorPage, t); - return (false); - - } - - } - - - /** * Handle the specified ServletException encountered while processing * the specified Request to produce the specified Response. Any * exceptions that occur during generation of the exception report are @@ -514,156 +448,14 @@ */ private void exception(Request request, Response response, Throwable exception) { - - // Handle a custom error page for this status code - if (debug >= 1) - log("Handling exception: " + exception); - Context context = (Context) container.getParent(); - Throwable realError = exception; - ErrorPage errorPage = findErrorPage(context, realError); - if ((errorPage == null) && (realError instanceof ServletException)) { - realError = ((ServletException) exception).getRootCause(); - if (realError != null) - errorPage = findErrorPage(context, realError); - else - realError = exception; - } - if (errorPage != null) { - // if (debug >= 1) - // log(" Sending to custom error page " + errorPage); - ServletRequest sreq = request.getRequest(); - sreq.setAttribute(Globals.ERROR_MESSAGE_ATTR, - exception.getMessage()); - sreq.setAttribute(Globals.EXCEPTION_ATTR, - exception); - Wrapper wrapper = (Wrapper) getContainer(); - sreq.setAttribute(Globals.SERVLET_NAME_ATTR, - wrapper.getName()); - if (sreq instanceof HttpServletRequest) - sreq.setAttribute(Globals.EXCEPTION_PAGE_ATTR, - ((HttpServletRequest) sreq).getRequestURI()); - sreq.setAttribute(Globals.EXCEPTION_TYPE_ATTR, - exception.getClass()); - if (custom(request, response, errorPage)) - return; - } - - // The response is an error - response.setError(); - - // Reset the response (if possible) - // if (debug >= 1) - // log(" Resetting response"); - try { - response.getResponse().reset(); - } catch (IllegalStateException e) { - // if (debug >= 1) - // log(" IllegalStateException: " + e.toString()); - ; - } - - // Indicate an INTERNAL SERVER ERROR status (if possible) - try { - // if (debug >= 1) - // log(" Sending INTERNAL_SERVER_ERROR"); - ServletResponse sresponse = response.getResponse(); - if (sresponse instanceof HttpServletResponse) - ((HttpServletResponse) sresponse).sendError - (HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - } catch (IllegalStateException e) { - // if (debug >= 1) - // log(" IllegalStateException: " + e.toString()); - ; - } catch (IOException e) { - // if (debug >= 1) - // log(" IOException: " + e.toString()); - ; - } - // Render a default HTML exception report page - Throwable rootCause = null; - if (exception instanceof ServletException) - rootCause = ((ServletException) exception).getRootCause(); - try { - // if (debug >= 1) - // log(" Setting content type to text/html"); - try { - response.getResponse().setContentType("text/html"); - } catch (Throwable t) { - // if (debug >= 1) - // log(" Throwable: " + t.toString()); - ; - } - // if (debug >= 1) - // log(" Getting reporter writer"); - PrintWriter writer = response.getReporter(); - // if (debug >= 1) - // log(" Writing standard error report page"); - writer.println("<html>"); - writer.println("<head>"); - writer.println("<title>" + - sm.getString("standardWrapper.exception0") + - "</title>"); - writer.println("</head>"); - writer.println("<body bgcolor=\"white\">"); - writer.println("<br><br>"); - writer.println("<h1>" + - sm.getString("standardWrapper.exception1") + - "</h1>"); - if (rootCause != null) - writer.println("<h3>" + - sm.getString("standardWrapper.exception2") + - "</h3>"); - writer.println("<pre>"); - exception.printStackTrace(writer); - writer.println("</pre>"); - if (rootCause != null) { - writer.println("<h3>" + - sm.getString("standardWrapper.exception3") + - "</h3>"); - writer.println("<pre>"); - rootCause.printStackTrace(writer); - writer.println("</pre>"); - } - writer.println("</body>"); - writer.println("</html>"); - writer.flush(); - } catch (IllegalStateException e) { - // if (debug >= 1) - // log(" IllegalStateException:", e); - ; - } - // if (debug >= 1) - // log(" Finished with exception() report"); - - } - - - /** - * Find and return the ErrorPage instance for the specified exception's - * class, or an ErrorPage instance for the closest superclass for which - * there is such a definition. If no associated ErrorPage instance is - * found, return <code>null</code>. - * - * @param context The Context in which to search - * @param exception The exception for which to find an ErrorPage - */ - private ErrorPage findErrorPage(Context context, Throwable exception) { + ServletRequest sreq = request.getRequest(); + sreq.setAttribute(Globals.EXCEPTION_ATTR, exception); - if (exception == null) - return (null); - Class clazz = exception.getClass(); - String name = clazz.getName(); - while (!"java.lang.Object".equals(clazz)) { - ErrorPage errorPage = context.findErrorPage(name); - if (errorPage != null) - return (errorPage); - clazz = clazz.getSuperclass(); - if (clazz == null) - break; - name = clazz.getName(); - } - return (null); + ServletResponse sresponse = response.getResponse(); + if (sresponse instanceof HttpServletResponse) + ((HttpServletResponse) sresponse).setStatus + (HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } @@ -796,117 +588,6 @@ // Case 4 - "Default" Match return (false); // NOTE - Not relevant for selecting filters - - } - - - /** - * Handle the HTTP status code (and corresponding message) generated - * while processing the specified Request to produce the specified - * Response. Any exceptions that occur during generation of the error - * report are logged and swallowed. - * - * @param request The request being processed - * @param response The response being generated - */ - private void status(Request request, Response response) { - - // Do nothing on non-HTTP responses - if (!(response instanceof HttpResponse)) - return; - HttpResponse hresponse = (HttpResponse) response; - if (!(response.getResponse() instanceof HttpServletResponse)) - return; - HttpServletResponse hres = - (HttpServletResponse) response.getResponse(); - int statusCode = hresponse.getStatus(); - String message = RequestUtil.filter(hresponse.getMessage()); - if (message == null) - message = ""; - - // Do nothing on a 1xx status - if (statusCode < 200) - return; - // Do nothing on an OK status - if (statusCode == HttpServletResponse.SC_OK) - return; - // Do nothing on a NO MODIFIED status - if (statusCode == HttpServletResponse.SC_NOT_MODIFIED) - return; - // Do nothing on a NO CONTENT status - if (statusCode == HttpServletResponse.SC_NO_CONTENT) - return; - - // Handle a custom error page for this status code - Context context = (Context) container.getParent(); - ErrorPage errorPage = context.findErrorPage(statusCode); - if (errorPage != null) { - ServletRequest sreq = request.getRequest(); - sreq.setAttribute(Globals.STATUS_CODE_ATTR, - new Integer(statusCode)); - sreq.setAttribute(Globals.ERROR_MESSAGE_ATTR, - message); - Wrapper wrapper = (Wrapper) getContainer(); - sreq.setAttribute(Globals.SERVLET_NAME_ATTR, - wrapper.getName()); - if (sreq instanceof HttpServletRequest) - sreq.setAttribute(Globals.EXCEPTION_PAGE_ATTR, - ((HttpServletRequest) sreq).getRequestURI()); - if (custom(request, response, errorPage)) - return; - } - - // Do nothing if there is no report for the specified status code - String report = null; - try { - report = sm.getString("http." + statusCode, message); - } catch (Throwable t) { - ; - } - if (report == null) - return; - - // Reset the response data buffer (if possible) - try { - if (hresponse.isError()) - hresponse.reset(statusCode, message); - } catch (Throwable e) { - if (debug >= 1) - log("status.reset", e); - } - - // Render a default HTML status report page - try { - try { - hres.setContentType("text/html"); - } catch (Throwable t) { - if (debug >= 1) - log("status.setContentType", t); - } - PrintWriter writer = response.getReporter(); - if (writer != null) { - writer.println("<html>"); - writer.println("<head>"); - writer.println("<title>" + - sm.getString("standardWrapper.statusTitle") + - "</title>"); - writer.println("</head>"); - writer.println("<body bgcolor=\"white\">"); - writer.println("<br><br>"); - writer.println("<h1>" + - sm.getString("standardWrapper.statusHeader", - "" + statusCode, message) + - "</h1>"); - writer.println(report); - writer.println("</body>"); - writer.println("</html>"); - writer.flush(); - } - } catch (IllegalStateException e) { - if (debug >= 1) - log("status.write", e); - } - }