You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by cr...@locus.apache.org on 2000/01/22 20:45:30 UTC
cvs commit: jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security SecurityInterceptor.java
craigmcc 00/01/22 11:45:30
Modified: proposals/catalina/src/share/org/apache/tomcat
Interceptor.java
proposals/catalina/src/share/org/apache/tomcat/core
ContainerBase.java
proposals/catalina/src/share/org/apache/tomcat/security
SecurityInterceptor.java
Log:
Change the Interceptor design pattern in Catalina, such that a
postService() method is aware when a lower-level Interceptor or
Container (or a servlet itself) has thrown an exception.
Change the invoke() method in ContainerBase -- which performs the
standard processing for Interceptors -- to always call postService() for
any Interceptor whose preService() method was called, even in the face
of exceptions. This allows Interceptors to reliably allocate per-request
resources in preService() and release them in postService(), no matter
what happens.
Change the example Interceptor (SecurityInterceptor) to match the new
calling sequence. NOTE: component configuration design pattern
adjustments will be handled separately.
Revision Changes Path
1.2 +21 -11 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Interceptor.java
Index: Interceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Interceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Interceptor.java 2000/01/20 06:32:51 1.1
+++ Interceptor.java 2000/01/22 19:45:29 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Interceptor.java,v 1.1 2000/01/20 06:32:51 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/01/20 06:32:51 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/Interceptor.java,v 1.2 2000/01/22 19:45:29 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/01/22 19:45:29 $
*
* ====================================================================
*
@@ -83,7 +83,7 @@
* <code>setContainer()</code> method.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/01/20 06:32:51 $
+ * @version $Revision: 1.2 $ $Date: 2000/01/22 19:45:29 $
*/
public interface Interceptor {
@@ -146,10 +146,17 @@
* such as a security implementation that needs to challenge the user
* for credentials.
* <li>Throw an <code>IOException</code> if encountered when processing the
- * specified Request or Response. This will abort all further
- * processing of this request.
+ * specified Request or Response. This will cause calls to the
+ * <code>preService()</code> method of any remaining Interceptors
+ * (and the <code>service()</code> method of the Container itself)
+ * to be skipped. The <code>postService()</code> method of this
+ * Interceptor, and any superior ones, will be called with the thrown
+ * exception as a non-null parameter.
* <li>Throw a <code>ServletException</code> if an unacceptable condition
- * is encountered. This will abort all further processing of this
+ * is encountered. Such exceptions will be handled as described for
+ * the IOException case, above. <b>DESIGN NOTE</b>: It is bad form
+ * for a server component to throw a <code>ServletException</code>,
+ * which should be reserved for application-level exceptions.
* request.
* </ul>
*
@@ -174,24 +181,27 @@
* <code>postService()</code> method of all Interceptors associated with
* a Container, where the <code>preService()</code> method was actually
* called (i.e. for those Interceptors up to and including the one whose
- * <code>preService()</code> method returned <code>false</code>, if any),
- * starting with the least recently added one.
+ * <code>preService()</code> method returned <code>false</code> or
+ * threw an exception, if any), starting with the least recently added one.
* <p>
* The <code>postService()</code> method may examine, but not modify, the
* properties of the specified Request and Response. <b>FIXME: Is this
* requirement too restrictive?</b>. It may, however, throw an exception,
- * which bypasses the call to <code>postService()</code> for any
- * remaining Interceptor associated with this Container.
+ * which will be visible to any remaining Interceptors whose
+ * <code>postService()</code> method has not yet been called.
*
* @param request Request that was processed
* @param response Response that was produced
+ * @param throwable Exception thrown by a lower-level Interceptor,
+ * Container, or user servlet (if any); else <code>null</code>
*
* @exception IOException if an input/output error occurred while
* processing this request
* @exception ServletException if a ServletException was thrown
* while processing this request
*/
- public void postService(Request request, Response response)
+ public void postService(Request request, Response response,
+ Throwable throwable)
throws IOException, ServletException;
1.2 +21 -7 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java
Index: ContainerBase.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ContainerBase.java 2000/01/20 06:34:49 1.1
+++ ContainerBase.java 2000/01/22 19:45:30 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v 1.1 2000/01/20 06:34:49 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/01/20 06:34:49 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/core/ContainerBase.java,v 1.2 2000/01/22 19:45:30 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/01/22 19:45:30 $
*
* ====================================================================
*
@@ -96,7 +96,7 @@
* and <code>service()</code>.
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/01/20 06:34:49 $
+ * @version $Revision: 1.2 $ $Date: 2000/01/22 19:45:30 $
*/
public abstract class ContainerBase {
@@ -520,21 +520,35 @@
}
// Call the preService() methods of all defined Interceptors
+ boolean done = false;
int last = -1;
+ Throwable t = null;
for (int i = 0; i < list.length; i++) {
last = i;
- if (!list[i].preService(request, response))
+ try {
+ if (!list[i].preService(request, response))
+ done = true;
+ } catch (Throwable e) {
+ t = e;
+ done = true;
+ }
+ if (done)
break;
}
- // Call the service() method of this Container
- service(request, response);
+ // Call the service() method of this Container if necessary
+ if (!done && (t == null))
+ service(request, response);
// Call the postService() methods of all defined Interceptors
for (int i = list.length - 1; i >= 0; i--) {
if (i > last)
continue;
- list[i].postService(request, response);
+ try {
+ list[i].postService(request, response, t);
+ } catch (Throwable e) {
+ t = e;
+ }
}
1.2 +9 -6 jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityInterceptor.java
Index: SecurityInterceptor.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityInterceptor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SecurityInterceptor.java 2000/01/20 06:38:07 1.1
+++ SecurityInterceptor.java 2000/01/22 19:45:30 1.2
@@ -1,7 +1,7 @@
/*
- * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityInterceptor.java,v 1.1 2000/01/20 06:38:07 craigmcc Exp $
- * $Revision: 1.1 $
- * $Date: 2000/01/20 06:38:07 $
+ * $Header: /home/cvs/jakarta-tomcat/proposals/catalina/src/share/org/apache/tomcat/security/SecurityInterceptor.java,v 1.2 2000/01/22 19:45:30 craigmcc Exp $
+ * $Revision: 1.2 $
+ * $Date: 2000/01/22 19:45:30 $
*
* ====================================================================
*
@@ -114,7 +114,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.1 $ $Date: 2000/01/20 06:38:07 $
+ * @version $Revision: 1.2 $ $Date: 2000/01/22 19:45:30 $
*/
@@ -250,14 +250,17 @@
*
* @param request Request to be processed
* @param response Response to be processed
+ * @param throwable Exception thrown by subordinate Interceptor or
+ * Container, if any
*
* @exception IOException if an input/output error occurs
* @exception ServletException if thrown by a processing element
*/
- public void postService(Request request, Response response)
+ public void postService(Request request, Response response,
+ Throwable throwable)
throws IOException, ServletException {
- ; // No post-processing is required
+ ; // No post-processing required
}