craigmcc 01/08/22 14:24:02
Modified: catalina/src/share/org/apache/catalina/core
StandardWrapperValve.java
Log:
Fix handling of UnavailableException thrown by the service() method of a
servlet, in two respects:
* The spec requires that the servlet instance throwing this exception
be taken out of service immediately (including a call to the destroy()
method). This is the Bugzilla bug report mentioned below.
* If the service() method throws UnavailableException, return HTTP status
503 (SC_SERVICE_UNAVAILABLE) rather than 500 (SC_INTERNAL_SERVER_ERROR)
to the client.
PR: Bugzilla #3209
Submitted by: James Cai <[EMAIL PROTECTED]>
Revision Changes Path
1.29 +38 -14
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.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- StandardWrapperValve.java 2001/07/22 20:25:08 1.28
+++ StandardWrapperValve.java 2001/08/22 21:24:02 1.29
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
1.28 2001/07/22 20:25:08 pier Exp $
- * $Revision: 1.28 $
- * $Date: 2001/07/22 20:25:08 $
+ * $Header:
/home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v
1.29 2001/08/22 21:24:02 craigmcc Exp $
+ * $Revision: 1.29 $
+ * $Date: 2001/08/22 21:24:02 $
*
* ====================================================================
*
@@ -103,7 +103,7 @@
* <code>StandardWrapper</code> container implementation.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.28 $ $Date: 2001/07/22 20:25:08 $
+ * @version $Revision: 1.29 $ $Date: 2001/08/22 21:24:02 $
*/
final class StandardWrapperValve
@@ -253,9 +253,17 @@
sreq.removeAttribute(Globals.JSP_FILE_ATTR);
log(sm.getString("standardWrapper.serviceException",
wrapper.getName()), e);
- throwable = e;
- exception(request, response, e);
+ // throwable = e;
+ // exception(request, response, e);
wrapper.unavailable(e);
+ long available = wrapper.getAvailable();
+ if ((available > 0L) && (available < Long.MAX_VALUE))
+ hres.setDateHeader("Retry-After", available);
+ hres.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
+ sm.getString("standardWrapper.isUnavailable",
+ wrapper.getName()));
+ // Do not save exception in 'throwable', because we
+ // do not want to do exception(request, response, e) processing
} catch (ServletException e) {
sreq.removeAttribute(Globals.JSP_FILE_ATTR);
log(sm.getString("standardWrapper.serviceException",
@@ -277,8 +285,10 @@
} catch (Throwable e) {
log(sm.getString("standardWrapper.releaseFilters",
wrapper.getName()), e);
- throwable = e;
- exception(request, response, e);
+ if (throwable == null) {
+ throwable = e;
+ exception(request, response, e);
+ }
}
// Deallocate the allocated servlet instance
@@ -286,17 +296,31 @@
if (servlet != null) {
wrapper.deallocate(servlet);
}
- } catch (ServletException e) {
+ } catch (Throwable e) {
log(sm.getString("standardWrapper.deallocateException",
wrapper.getName()), e);
- throwable = e;
- exception(request, response, e);
+ if (throwable == null) {
+ throwable = e;
+ exception(request, response, e);
+ }
+ }
+
+ // If this servlet has been marked permanently unavailable,
+ // unload it and release this instance
+ try {
+ if ((servlet != null) &&
+ (wrapper.getAvailable() == Long.MAX_VALUE)) {
+ wrapper.unload();
+ }
} catch (Throwable e) {
- log(sm.getString("standardWrapper.deallocateException",
+ log(sm.getString("standardWrapper.unloadException",
wrapper.getName()), e);
- throwable = e;
- exception(request, response, e);
+ if (throwable == null) {
+ throwable = e;
+ exception(request, response, e);
+ }
}
+
// Generate a response for the generated HTTP status and message
if (throwable == null) {