larryi 00/12/20 07:25:51
Modified: src/facade22/org/apache/tomcat/facade
RequestDispatcherImpl.java ServletHandler.java
src/share/org/apache/tomcat/core Handler.java
Log:
Some simplification.
Removed saveError method from Handler. setErrorException() and
setErrorURI() are called directly where needed. setErrorURI() should be
called with a non-null error URI only if the URI causing the error differs from
the requestURI found on the associated request. Thus, this needs to
happen only in RequestDispatcherImpl.
Added handling to report UnavailableExceptions as 503 errors.
Revision Changes Path
1.7 +12 -0
jakarta-tomcat/src/facade22/org/apache/tomcat/facade/RequestDispatcherImpl.java
Index: RequestDispatcherImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-tomcat/src/facade22/org/apache/tomcat/facade/RequestDispatcherImpl.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- RequestDispatcherImpl.java 2000/12/06 03:59:29 1.6
+++ RequestDispatcherImpl.java 2000/12/20 15:25:50 1.7
@@ -195,6 +195,9 @@
// Rethrow original error if present
if ( realResponse.isExceptionPresent() ) {
+ // if error URI not set, set our URI
+ if ( null == realResponse.getErrorURI() )
+ realResponse.setErrorURI( context.getPath() + path );
Exception ex = realResponse.getErrorException();
if ( ex instanceof IOException )
throw (IOException) ex;
@@ -353,6 +356,9 @@
// Rethrow original error if present
if ( realResponse.isExceptionPresent() ) {
+ // if error URI not set, set our URI
+ if ( null == realResponse.getErrorURI() )
+ realResponse.setErrorURI( context.getPath() + path );
Exception ex = realResponse.getErrorException();
if ( ex instanceof IOException )
throw (IOException) ex;
@@ -393,6 +399,9 @@
// Rethrow original error if present
if ( realResponse.isExceptionPresent() ) {
+ // if error URI not set, set our URI
+ if ( null == realResponse.getErrorURI() )
+ realResponse.setErrorURI( "named servlet: " + name );
Exception ex = realResponse.getErrorException();
if ( ex instanceof IOException )
throw (IOException) ex;
@@ -429,6 +438,9 @@
// Rethrow original error if present
if ( realResponse.isExceptionPresent() ) {
+ // if error URI not set, set our URI
+ if ( null == realResponse.getErrorURI() )
+ realResponse.setErrorURI( "named servlet: " + name );
Exception ex = realResponse.getErrorException();
if ( ex instanceof IOException )
throw (IOException) ex;
1.9 +36 -10
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.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ServletHandler.java 2000/12/17 22:16:35 1.8
+++ ServletHandler.java 2000/12/20 15:25:50 1.9
@@ -418,8 +418,9 @@
if( state== STATE_DISABLED || state==STATE_DELAYED_INIT ) {
// the init failed because of an exception
Exception ex=getErrorException();
- // save error state on request and response
- saveError( req, res, ex );
+ // save error info
+ res.setErrorException(ex);
+ res.setErrorURI(null);
handleInitError( req, res, ex );
return;
}
@@ -484,7 +485,8 @@
} catch ( UnavailableException ex ) {
// if new exception, save and set timer if necessary
if ( res.getErrorException() != ex ) {
- saveError( req, res, ex );
+ res.setErrorException(ex);
+ res.setErrorURI(null);
if ( ex.isPermanent() ) {
setState( STATE_DISABLED );
// XXX spec says we must destroy the servlet
@@ -505,10 +507,33 @@
handleServiceError( req, res, ex );
return;
}
- // clear any error exceptions, since none were thrown
- saveError( req, res, null);
+ // clear any error exception since none were thrown
+ res.setErrorException(null);
+ res.setErrorURI(null);
}
+ private void handleError( Request req, Response res, Throwable t ) {
+ if (t instanceof UnavailableException) {
+ int unavailableTime = -1;
+ if ( !((UnavailableException)t).isPermanent() ) {
+ unavailableTime = ((UnavailableException)t).getUnavailableSeconds();
+ // if unavailable time not known, use 1 second
+ if ( unavailableTime <= 0 )
+ unavailableTime = 1;
+ res.setHeader("Retry-After", Integer.toString(unavailableTime));
+ }
+ String msg=t.getMessage();
+ log( "UnavailableException in: " + req +
+ ", time remaining " + unavailableTime + " seconds : " + msg,
t);
+ req.setAttribute("javax.servlet.error.message", msg );
+ req.setAttribute("tomcat.servlet.error.service.unavailableTime", new
Integer(unavailableTime));
+ contextM.handleStatus( req, res,
HttpServletResponse.SC_SERVICE_UNAVAILABLE );
+ return;
+ } else {
+ contextM.handleError( req, res, t );
+ }
+ }
+
protected void handleInitError( Request req, Response res, Throwable t )
{
// if in included, defer handling to higher level
@@ -516,14 +541,14 @@
if( t instanceof ClassNotFoundException )
contextM.handleStatus( req, res, 404 );
else
- contextM.handleError( req, res, t );
+ handleError( req, res, t );
}
protected void handleServiceError( Request req, Response res, Throwable t )
{
// if in included, defer handling to higher level
if (res.isIncluded()) return;
- contextM.handleError( req, res, t );
+ handleError( req, res, t );
}
// -------------------- Unavailable --------------------
@@ -553,7 +578,7 @@
// disable the error - it expired
unavailableTime=-1;
setErrorException(null);
- context.log(getName() +
+ log(getName() +
" unavailable time expired, trying again ");
return true;
}
@@ -587,8 +612,9 @@
int secs=1;
if( moreTime > 0 )
secs = (int)((moreTime + 999) / 1000);
- // save error state on request and response
- saveError( req, res, new UnavailableException(ex.getMessage(), secs) );
+ // save error info
+ res.setErrorException(new UnavailableException(ex.getMessage(), secs));
+ res.setErrorURI(null);
// still unavailable
return false;
}
1.33 +5 -17 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.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- Handler.java 2000/12/17 22:16:36 1.32
+++ Handler.java 2000/12/20 15:25:51 1.33
@@ -226,7 +226,11 @@
} catch( Exception ex ) {
// save error state on request and response
serviceException=ex;
- saveError( req, res, ex);
+ // if new exception, update info
+ if ( ex != res.getErrorException() ) {
+ res.setErrorException(ex);
+ res.setErrorURI(null);
+ }
}
// continue with the postService ( roll back transactions, etc )
@@ -289,22 +293,6 @@
contextM.log(s, t);
else
logger.log(s, t);
- }
-
- // --------------- Error Handling ----------------
-
- /** If an error happens during init or service it will be saved in
- * 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 ) {
- // if a new exception
- if ( res.getErrorException() != ex ) {
- res.setErrorException( ex );
- res.setErrorURI( (String)req.
- getAttribute("javax.servlet.include.request_uri"));
- }
}
// -------------------- Notes --------------------