larryi 00/12/17 14:16:36
Modified: src/facade22/org/apache/tomcat/facade ServletHandler.java
src/share/org/apache/tomcat/core Handler.java Request.java
Log:
More fixes for exception handling.
It now works correctly when an included serlvet catches an exception and
either handles it or rethrows a different exception.
It also works correctly when an included servlet throws an permanent
UnavailableException. If "includers" do not handle the exception, they are
not made permanently unavailable too!
The idea of saving the original exception on Response and not overwriting it
doesn't work when exceptions are caught and handled or a different
exception is thrown. As a result, Handler.saveError() now always saves new
exceptions on the Response, not updating the information if the exception
is the same as the one already set.
Removing the errorException property from Request since it is no longer
needed.
Revision Changes Path
1.8 +24 -16
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java
Index: ServletHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/ServletHandler.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ServletHandler.java 2000/12/16 19:04:26 1.7
+++ ServletHandler.java 2000/12/17 22:16:35 1.8
@@ -447,7 +447,7 @@
// if unavailable
if( ! checkAvailable( req, res ) ) {
- handleServiceError( req, res, req.getErrorException());
+ handleServiceError( req, res, res.getErrorException());
return; // we can't handle it
}
@@ -479,26 +479,34 @@
} else {
servlet.service(reqF, resF);
}
+ // catch just UnavailableException, so we can set a timer if needed
+ // other exceptions will be thrown
} catch ( UnavailableException ex ) {
- if ( ex.isPermanent() ) {
- setState( STATE_DISABLED );
- // XXX spec says we must destroy the servlet
- }
- if ( null == getErrorException() ) {
- synchronized(this) {
- if ( null == getErrorException() ) {
- if ( state == STATE_DISABLED )
- // servlet exception state
- setErrorException( ex );
- else
- // set expiration
- setServletUnavailable((UnavailableException)ex );
+ // if new exception, save and set timer if necessary
+ if ( res.getErrorException() != ex ) {
+ saveError( req, res, ex );
+ if ( ex.isPermanent() ) {
+ setState( STATE_DISABLED );
+ // XXX spec says we must destroy the servlet
+ }
+ if ( null == getErrorException() ) {
+ synchronized(this) {
+ if ( null == getErrorException() ) {
+ if ( state == STATE_DISABLED )
+ // set the permanet exception for future use
+ setErrorException( ex );
+ else
+ // set expiration
+ setServletUnavailable((UnavailableException)ex );
+ }
}
}
}
- throw ex;
+ handleServiceError( req, res, ex );
+ return;
}
- // other exceptions will be thrown
+ // clear any error exceptions, since none were thrown
+ saveError( req, res, null);
}
protected void handleInitError( Request req, Response res, Throwable t )
1.32 +3 -5 jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java
Index: Handler.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Handler.java,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- Handler.java 2000/12/16 19:04:27 1.31
+++ Handler.java 2000/12/17 22:16:36 1.32
@@ -294,15 +294,13 @@
// --------------- Error Handling ----------------
/** If an error happens during init or service it will be saved in
- * request and response.
+ * the response.
*/
// XXX error handling in Handler shouldn't be exposed to childs, need
// simplifications
protected final void saveError( Request req, Response res, Exception ex ) {
- // save current exception on the request
- req.setErrorException( ex );
- // if the first exception, save info on the response
- if ( ! res.isExceptionPresent() ) {
+ // if a new exception
+ if ( res.getErrorException() != ex ) {
res.setErrorException( ex );
res.setErrorURI( (String)req.
getAttribute("javax.servlet.include.request_uri"));
1.81 +0 -20 jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java
Index: Request.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/src/share/org/apache/tomcat/core/Request.java,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- Request.java 2000/12/07 18:40:54 1.80
+++ Request.java 2000/12/17 22:16:36 1.81
@@ -820,26 +820,6 @@
//return ((int)b[0]) & 0x000000FF;
}
- // ----------------- Error State -----------------
-
- /** Set most recent exception that occurred while handling
- this request.
- */
- public void setErrorException( Exception ex ) {
- errorException = ex;
- }
-
- /** Get most recent exception that occurred while handling
- this request.
- */
- public Exception getErrorException() {
- return errorException;
- }
-
- public boolean isExceptionPresent() {
- return ( errorException != null );
- }
-
// -------------------- debug --------------------
public String toString() {