craigmcc 01/01/22 18:51:17 Modified: catalina/src/share/org/apache/catalina/core ContainerBase.java LocalStrings.properties StandardContext.java StandardContextValve.java StandardEngine.java StandardEngineValve.java StandardHost.java StandardHostValve.java StandardWrapper.java StandardWrapperValve.java Added: catalina/src/share/org/apache/catalina/core StandardPipeline.java Log: Second of four check-ins for the Valve API change. Add a StandardPipeline implementation of the Pipeline interface. Make ContainerBase (and therefore all containers that inherit from it) reference a Pipeline as a separate object to which valve management is delegated, rather than implementing Pipeline directly. Revision Changes Path 1.7 +43 -194 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java Index: ContainerBase.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- ContainerBase.java 2001/01/04 20:05:36 1.6 +++ ContainerBase.java 2001/01/23 02:51:14 1.7 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v 1.6 2001/01/04 20:05:36 craigmcc Exp $ - * $Revision: 1.6 $ - * $Date: 2001/01/04 20:05:36 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/ContainerBase.java,v 1.7 2001/01/23 02:51:14 craigmcc Exp $ + * $Revision: 1.7 $ + * $Date: 2001/01/23 02:51:14 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -99,11 +99,12 @@ * this base class must implement <code>getInfo()</code>, and may implement * a replacement for <code>invoke()</code>. * <p> - * If a subclass prefers to use the default version of <code>invoke()</code> - * with pipeline support, it should instantiate a Valve instance containing - * the default behavior desired, and assign it with <code>setBasic()</code> - * in a constructor. In that way, any and all configured Valves added to the - * pipeline will preceed the basic Valve. + * All subclasses of this abstract base class will include support for a + * Pipeline object that defines the processing to be performed for each request + * received by the <code>invoke()</code> method of this class, utilizig the + * "Chain of Responsibility" design pattern. A subclass should encapsulate its + * own processing functionality as a <code>Valve</code>, and configure this + * Valve into the pipeline by calling <code>setBasic()</code>. * <p> * This implementation fires property change events, per the JavaBeans design * pattern, for changes in singleton properties. In addition, it fires the @@ -150,23 +151,17 @@ * class comments of the implementation class. * * @author Craig R. McClanahan - * @version $Revision: 1.6 $ $Date: 2001/01/04 20:05:36 $ + * @version $Revision: 1.7 $ $Date: 2001/01/23 02:51:14 $ */ public abstract class ContainerBase - implements Container, Lifecycle, Pipeline { + implements Container, Lifecycle { // ----------------------------------------------------- Instance Variables /** - * The Valve that implements the basic behavior of this Container, if any. - */ - protected Valve basic = null; - - - /** * The child Containers belonging to this Container, keyed by name. */ protected HashMap children = new HashMap(); @@ -179,12 +174,6 @@ /** - * The first Valve in the pipeline associated with this Container. - */ - protected Valve first = null; - - - /** * The lifecycle event support for this component. */ protected LifecycleSupport lifecycle = new LifecycleSupport(this); @@ -246,8 +235,14 @@ /** * The parent class loader to be configured when we install a Loader. + */ + protected ClassLoader parentClassLoader = null; + + + /** + * The Pipeline object with which this Container is associated. */ - private ClassLoader parentClassLoader = null; + protected Pipeline pipeline = new StandardPipeline(this); /** @@ -285,70 +280,6 @@ /** - * Return the Valve that provides the basic functionality for this - * Container, if any. - */ - public Valve getBasic() { - - return (basic); - - } - - - /** - * Set the Valve that provides the basic functionality for this - * Container, if any. - * - * @param valve The new basic Valve - */ - public synchronized void setBasic(Valve valve) { - - // Change components if necessary - Valve oldBasic = this.basic; - if (oldBasic == valve) - return; - this.basic = valve; - - // Stop the old component if necessary and remove it from the pipeline - if (oldBasic != null) { - Valve previous = getLast(); - if (previous != null) - previous.setNext(null); - oldBasic.setContainer(null); - } - if (started && (oldBasic != null) && (oldBasic instanceof Lifecycle)) { - try { - ((Lifecycle) oldBasic).stop(); - } catch (LifecycleException e) { - log("ContainerBase.setBasic: stop: ", e); - } - } - - // Start the new component if necessary and link it into the pipeline - if (this.basic != null) { - this.basic.setContainer((Container) this); - this.basic.setNext(null); - } - if (started && (valve != null) && (valve instanceof Lifecycle)) { - try { - ((Lifecycle) valve).start(); - } catch (LifecycleException e) { - log("ContainerBase.setBasic: start: ", e); - } - } - if (this.basic != null) { - Valve previous = getLast(); - if (previous != null) - previous.setNext(this.basic); - } - - // Report this property change to interested listeners - support.firePropertyChange("basic", oldBasic, this.basic); - - } - - - /** * Return the debugging detail level for this component. */ public int getDebug() { @@ -382,23 +313,6 @@ /** - * Return the last configured Valve (other than the basic Valve, if any) - * configured in the pipeline for this Container, if any; otherwise - * return <code>null</code>. - */ - public Valve getLast() { - - if (first == null) - return (null); - Valve next = first; - while ((next.getNext() != null) && (next.getNext() != basic)) - next = next.getNext(); - return (next); - - } - - - /** * Return the Loader with which this Container is associated. If there is * no associated Loader, return the Loader associated with our parent * Container (if any); otherwise, return <code>null</code>. @@ -668,6 +582,17 @@ /** + * Return the Pipeline object that manages the Valves associated with + * this Container. + */ + public Pipeline getPipeline() { + + return (this.pipeline); + + } + + + /** * Return the Realm with which this Container is associated. If there is * no associated Realm, return the Realm associated with our parent * Container (if any); otherwise return <code>null</code>. @@ -971,13 +896,7 @@ public void invoke(Request request, Response response) throws IOException, ServletException { - if (first != null) - first.invoke(request, response); - else if (basic != null) - basic.invoke(request, response); - else - throw new IllegalStateException - (sm.getString("containerBase.notConfigured")); + pipeline.invoke(request, response); } @@ -1161,12 +1080,8 @@ } // Start the Valves in our pipeline (including the basic), if any - Valve current = first; - while (current != null) { - if (current instanceof Lifecycle) - ((Lifecycle) current).start(); - current = current.getNext(); - } + if (pipeline instanceof Lifecycle) + ((Lifecycle) pipeline).start(); // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(START_EVENT, null); @@ -1193,14 +1108,8 @@ started = false; // Stop the Valves in our pipeline (including the basic), if any - Valve current = basic; - if (current == null) - current = getLast(); - while (current != null) { - if (current instanceof Lifecycle) - ((Lifecycle) current).stop(); - current = current.getPrevious(); - } + if (pipeline instanceof Lifecycle) + ((Lifecycle) pipeline).stop(); // Stop our child containers, if any Container children[] = findChildren(); @@ -1253,53 +1162,21 @@ * associated with a different Container */ public synchronized void addValve(Valve valve) { - - // Start the new component if necessary - valve.setContainer((Container) this); - valve.setNext(basic); - if (started && (valve != null) && (valve instanceof Lifecycle)) { - try { - ((Lifecycle) valve).start(); - } catch (LifecycleException e) { - log("ContainerBase.addValve: start: ", e); - } - } - - // Link the new component into the pipeline - if (basic == null) { - Valve last = getLast(); - if (last == null) { - valve.setPrevious(null); - first = valve; - } else { - valve.setPrevious(last); - last.setNext(valve); - } - } else { - Valve previous = basic.getPrevious(); - if (previous == null) { - valve.setPrevious(null); - first = valve; - } else { - valve.setPrevious(previous); - previous.setNext(valve); - } - basic.setPrevious(valve); - } - // Report this pipeline change to interested listeners + pipeline.addValve(valve); fireContainerEvent(ADD_VALVE_EVENT, valve); } /** - * Return the first Valve in the pipeline associated with this Container. - * If there are no such Valves, <code>null</code> is returned. + * Return the set of Valves in the pipeline associated with this + * Container, including the basic Valve (if any). If there are no + * such Valves, a zero-length array is returned. */ - public Valve findValves() { + public Valve[] getValves() { - return (first); + return (pipeline.getValves()); } @@ -1312,36 +1189,8 @@ */ public synchronized void removeValve(Valve valve) { - Valve current = first; - while (current != null) { - if (current != valve) { - current = current.getNext(); - continue; - } - Valve previous = current.getPrevious(); - Valve next = current.getNext(); - if (previous == null) { - if (next == null) { - first = null; - } else { - next.setPrevious(null); - first = next; - } - } else { - previous.setNext(next); - if (next != null) - next.setPrevious(previous); - } - if (started && (valve != null) && (valve instanceof Lifecycle)) { - try { - ((Lifecycle) valve).stop(); - } catch (LifecycleException e) { - log("ContainerBase.removeValve: stop: ", e); - } - } - fireContainerEvent(REMOVE_VALVE_EVENT, valve); - break; - } + pipeline.removeValve(valve); + fireContainerEvent(REMOVE_VALVE_EVENT, valve); } 1.23 +3 -0 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.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- LocalStrings.properties 2000/12/23 19:00:31 1.22 +++ LocalStrings.properties 2001/01/23 02:51:14 1.23 @@ -95,6 +95,9 @@ standardHost.unfoundContext=Cannot find context for request URI {0} standardHost.warRequired=URL to web application archive is required standardHost.warURL=Invalid URL for web application archive: {0} +standardPipeline.alreadyStarted=Pipeline has already been started +standardPipeline.notStarted=Pipeline has not been started +standardPipeline.noValve=No more Valves in the Pipeline processing this request standardServer.addContainer.ise=No connectors available to associate this container with standardServer.start.connectors=At least one connector is not associated with any container standardServer.start.started=This server has already been started 1.34 +6 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java Index: StandardContext.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- StandardContext.java 2000/12/23 19:00:32 1.33 +++ StandardContext.java 2001/01/23 02:51:14 1.34 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.33 2000/12/23 19:00:32 craigmcc Exp $ - * $Revision: 1.33 $ - * $Date: 2000/12/23 19:00:32 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContext.java,v 1.34 2001/01/23 02:51:14 craigmcc Exp $ + * $Revision: 1.34 $ + * $Date: 2001/01/23 02:51:14 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -133,7 +133,7 @@ * * @author Craig R. McClanahan * @author Remy Maucherat - * @version $Revision: 1.33 $ $Date: 2000/12/23 19:00:32 $ + * @version $Revision: 1.34 $ $Date: 2001/01/23 02:51:14 $ */ public class StandardContext @@ -150,7 +150,7 @@ public StandardContext() { super(); - setBasic(new StandardContextValve()); + pipeline.setBasic(new StandardContextValve()); } 1.6 +9 -6 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.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StandardContextValve.java 2000/12/01 02:11:22 1.5 +++ StandardContextValve.java 2001/01/23 02:51:15 1.6 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v 1.5 2000/12/01 02:11:22 craigmcc Exp $ - * $Revision: 1.5 $ - * $Date: 2000/12/01 02:11:22 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardContextValve.java,v 1.6 2001/01/23 02:51:15 craigmcc Exp $ + * $Revision: 1.6 $ + * $Date: 2001/01/23 02:51:15 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -75,6 +75,7 @@ import org.apache.catalina.Container; import org.apache.catalina.Request; import org.apache.catalina.Response; +import org.apache.catalina.ValveContext; import org.apache.catalina.Wrapper; import org.apache.catalina.util.StringManager; import org.apache.catalina.valves.ValveBase; @@ -88,7 +89,7 @@ * when processing HTTP requests. * * @author Craig R. McClanahan - * @version $Revision: 1.5 $ $Date: 2000/12/01 02:11:22 $ + * @version $Revision: 1.6 $ $Date: 2001/01/23 02:51:15 $ */ final class StandardContextValve @@ -135,11 +136,13 @@ * * @param request Request to be processed * @param response Response to be produced + * @param valveContext Valve context used to forward to the next Valve * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ - public void invoke(Request request, Response response) + public void invoke(Request request, Response response, + ValveContext valveContext) throws IOException, ServletException { // Validate the request and response object types 1.5 +6 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngine.java Index: StandardEngine.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngine.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- StandardEngine.java 2000/12/17 02:34:25 1.4 +++ StandardEngine.java 2001/01/23 02:51:15 1.5 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngine.java,v 1.4 2000/12/17 02:34:25 craigmcc Exp $ - * $Revision: 1.4 $ - * $Date: 2000/12/17 02:34:25 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngine.java,v 1.5 2001/01/23 02:51:15 craigmcc Exp $ + * $Revision: 1.5 $ + * $Date: 2001/01/23 02:51:15 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -84,7 +84,7 @@ * fully qualified host name of that virtual host. * * @author Craig R. McClanahan - * @version $Revision: 1.4 $ $Date: 2000/12/17 02:34:25 $ + * @version $Revision: 1.5 $ $Date: 2001/01/23 02:51:15 $ */ public class StandardEngine @@ -101,7 +101,7 @@ public StandardEngine() { super(); - setBasic(new StandardEngineValve()); + pipeline.setBasic(new StandardEngineValve()); } 1.3 +10 -7 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngineValve.java Index: StandardEngineValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngineValve.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- StandardEngineValve.java 2000/09/09 03:20:50 1.2 +++ StandardEngineValve.java 2001/01/23 02:51:15 1.3 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngineValve.java,v 1.2 2000/09/09 03:20:50 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2000/09/09 03:20:50 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardEngineValve.java,v 1.3 2001/01/23 02:51:15 craigmcc Exp $ + * $Revision: 1.3 $ + * $Date: 2001/01/23 02:51:15 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -73,6 +73,7 @@ import org.apache.catalina.Host; import org.apache.catalina.Request; import org.apache.catalina.Response; +import org.apache.catalina.ValveContext; import org.apache.catalina.util.StringManager; import org.apache.catalina.valves.ValveBase; @@ -85,7 +86,7 @@ * when processing HTTP requests. * * @author Craig R. McClanahan - * @version $Revision: 1.2 $ $Date: 2000/09/09 03:20:50 $ + * @version $Revision: 1.3 $ $Date: 2001/01/23 02:51:15 $ */ final class StandardEngineValve @@ -131,12 +132,14 @@ * be found, return an appropriate HTTP error. * * @param request Request to be processed - * @param update Update request to reflect this mapping? + * @param response Response to be produced + * @param valveContext Valve context used to forward to the next Valve * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ - public void invoke(Request request, Response response) + public void invoke(Request request, Response response, + ValveContext valveContext) throws IOException, ServletException { // Validate the request and response object types 1.7 +6 -6 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.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- StandardHost.java 2000/12/07 19:37:41 1.6 +++ StandardHost.java 2001/01/23 02:51:15 1.7 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v 1.6 2000/12/07 19:37:41 pier Exp $ - * $Revision: 1.6 $ - * $Date: 2000/12/07 19:37:41 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHost.java,v 1.7 2001/01/23 02:51:15 craigmcc Exp $ + * $Revision: 1.7 $ + * $Date: 2001/01/23 02:51:15 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -97,7 +97,7 @@ * requests directed to a particular web application. * * @author Craig R. McClanahan - * @version $Revision: 1.6 $ $Date: 2000/12/07 19:37:41 $ + * @version $Revision: 1.7 $ $Date: 2001/01/23 02:51:15 $ */ public class StandardHost @@ -114,7 +114,7 @@ public StandardHost() { super(); - setBasic(new StandardHostValve()); + pipeline.setBasic(new StandardHostValve()); } 1.4 +9 -6 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHostValve.java Index: StandardHostValve.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHostValve.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- StandardHostValve.java 2000/09/09 03:20:50 1.3 +++ StandardHostValve.java 2001/01/23 02:51:15 1.4 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHostValve.java,v 1.3 2000/09/09 03:20:50 craigmcc Exp $ - * $Revision: 1.3 $ - * $Date: 2000/09/09 03:20:50 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardHostValve.java,v 1.4 2001/01/23 02:51:15 craigmcc Exp $ + * $Revision: 1.4 $ + * $Date: 2001/01/23 02:51:15 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -73,6 +73,7 @@ import org.apache.catalina.Context; import org.apache.catalina.Request; import org.apache.catalina.Response; +import org.apache.catalina.ValveContext; import org.apache.catalina.util.StringManager; import org.apache.catalina.valves.ValveBase; @@ -85,7 +86,7 @@ * when processing HTTP requests. * * @author Craig R. McClanahan - * @version $Revision: 1.3 $ $Date: 2000/09/09 03:20:50 $ + * @version $Revision: 1.4 $ $Date: 2001/01/23 02:51:15 $ */ final class StandardHostValve @@ -132,11 +133,13 @@ * * @param request Request to be processed * @param response Response to be produced + * @param valveContext Valve context used to forward to the next Valve * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ - public void invoke(Request request, Response response) + public void invoke(Request request, Response response, + ValveContext valveContext) throws IOException, ServletException { // Validate the request and response object types 1.12 +5 -5 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java Index: StandardWrapper.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- StandardWrapper.java 2000/11/25 00:57:24 1.11 +++ StandardWrapper.java 2001/01/23 02:51:15 1.12 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v 1.11 2000/11/25 00:57:24 craigmcc Exp $ - * $Revision: 1.11 $ - * $Date: 2000/11/25 00:57:24 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapper.java,v 1.12 2001/01/23 02:51:15 craigmcc Exp $ + * $Revision: 1.12 $ + * $Date: 2001/01/23 02:51:15 $ * * ==================================================================== * @@ -101,7 +101,7 @@ * make them efficient are counter-productive. * * @author Craig R. McClanahan - * @version $Revision: 1.11 $ $Date: 2000/11/25 00:57:24 $ + * @version $Revision: 1.12 $ $Date: 2001/01/23 02:51:15 $ */ public final class StandardWrapper @@ -118,7 +118,7 @@ public StandardWrapper() { super(); - setBasic(new StandardWrapperValve()); + pipeline.setBasic(new StandardWrapperValve()); } 1.16 +9 -6 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.15 retrieving revision 1.16 diff -u -r1.15 -r1.16 --- StandardWrapperValve.java 2001/01/04 19:49:22 1.15 +++ StandardWrapperValve.java 2001/01/23 02:51:16 1.16 @@ -1,13 +1,13 @@ /* - * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v 1.15 2001/01/04 19:49:22 remm Exp $ - * $Revision: 1.15 $ - * $Date: 2001/01/04 19:49:22 $ + * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardWrapperValve.java,v 1.16 2001/01/23 02:51:16 craigmcc Exp $ + * $Revision: 1.16 $ + * $Date: 2001/01/23 02:51:16 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * - * Copyright (c) 1999 The Apache Software Foundation. All rights + * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -87,6 +87,7 @@ import org.apache.catalina.Logger; import org.apache.catalina.Request; import org.apache.catalina.Response; +import org.apache.catalina.ValveContext; import org.apache.catalina.Wrapper; import org.apache.catalina.deploy.ErrorPage; import org.apache.catalina.deploy.FilterDef; @@ -101,7 +102,7 @@ * <code>StandardWrapper</code> container implementation. * * @author Craig R. McClanahan - * @version $Revision: 1.15 $ $Date: 2001/01/04 19:49:22 $ + * @version $Revision: 1.16 $ $Date: 2001/01/23 02:51:16 $ */ final class StandardWrapperValve @@ -159,11 +160,13 @@ * * @param request Request to be processed * @param response Response to be produced + * @param valveContext Valve context used to forward to the next Valve * * @exception IOException if an input/output error occurred * @exception ServletException if a servlet error occurred */ - public void invoke(Request request, Response response) + public void invoke(Request request, Response response, + ValveContext valveContext) throws IOException, ServletException { // Initialize local variables we may need 1.1 jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardPipeline.java Index: StandardPipeline.java =================================================================== /* * $Header: /home/cvs/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardPipeline.java,v 1.1 2001/01/23 02:51:15 craigmcc Exp $ * $Revision: 1.1 $ * $Date: 2001/01/23 02:51:15 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 1999-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * [Additional notices, if required by prior licensing conditions] * */ package org.apache.catalina.core; import java.io.IOException; import javax.servlet.ServletException; import org.apache.catalina.Contained; import org.apache.catalina.Container; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleEvent; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleListener; import org.apache.catalina.Logger; import org.apache.catalina.Pipeline; import org.apache.catalina.Request; import org.apache.catalina.Response; import org.apache.catalina.Valve; import org.apache.catalina.ValveContext; import org.apache.catalina.util.LifecycleSupport; import org.apache.catalina.util.StringManager; /** * Standard implementation of a processing <b>Pipeline</b> that will invoke * a series of Valves that have been configured to be called in order. This * implementation can be used for any type of Container. * * <b>IMPLEMENTATION WARNING</b> - This implementation assumes that no * calls to <code>addValve()</code> or <code>removeValve</code> are allowed * while a request is currently being processed. Otherwise, the mechanism * by which per-thread state is maintained will need to be modified. * * @author Craig R. McClanahan */ public class StandardPipeline implements Pipeline, Contained, Lifecycle, ValveContext { // ----------------------------------------------------------- Constructors /** * Construct a new StandardPipeline instance with no associated Container. */ public StandardPipeline() { this(null); } /** * Construct a new StandardPipeline instance that is associated with the * specified Container. * * @param container The container we should be associated with */ public StandardPipeline(Container container) { super(); setContainer(container); } // ----------------------------------------------------- Instance Variables /** * The basic Valve (if any) associated with this Pipeline. */ protected Valve basic = null; /** * The Container with which this Pipeline is associated. */ protected Container container = null; /** * The debugging detail level for this component. */ protected int debug = 0; /** * Descriptive information about this implementation. */ protected String info = "org.apache.catalina.core.StandardPipeline/1.0"; /** * The lifecycle event support for this component. */ protected LifecycleSupport lifecycle = new LifecycleSupport(this); /** * The string manager for this package. */ protected static StringManager sm = StringManager.getManager(Constants.Package); /** * Has this component been started yet? */ protected boolean started = false; /** * The per-thread execution state for processing through this pipeline. * The actual value is a java.lang.Integer object containing the subscript * into the <code>values</code> array, or a subscript equal to * <code>values.length</code> if the basic Valve is currently being * processed. */ protected ThreadLocal state = new ThreadLocal(); /** * The set of Valves (not including the Basic one, if any) associated with * this Pipeline. */ protected Valve valves[] = new Valve[0]; // --------------------------------------------------------- Public Methods /** * Return descriptive information about this implementation class. */ public String getInfo() { return (this.info); } // ------------------------------------------------------ Contained Methods /** * Return the Container with which this Pipeline is associated. */ public Container getContainer() { return (this.container); } /** * Set the Container with which this Pipeline is associated. * * @param container The new associated container */ public void setContainer(Container container) { this.container = container; } // ------------------------------------------------------ Lifecycle Methods /** * Add a lifecycle event listener to this component. * * @param listener The listener to add */ public void addLifecycleListener(LifecycleListener listener) { lifecycle.addLifecycleListener(listener); } /** * Remove a lifecycle event listener from this component. * * @param listener The listener to remove */ public void removeLifecycleListener(LifecycleListener listener) { lifecycle.removeLifecycleListener(listener); } /** * Prepare for active use of the public methods of this Component. * * @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 { // Validate and update our current component state if (started) throw new LifecycleException (sm.getString("standardPipeline.alreadyStarted")); started = true; // Start the Valves in our pipeline (including the basic), if any for (int i = 0; i < valves.length; i++) { if (valves[i] instanceof Lifecycle) ((Lifecycle) valves[i]).start(); } if ((basic != null) && (basic instanceof Lifecycle)) ((Lifecycle) basic).start(); // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(START_EVENT, null); } /** * Gracefully shut down active use of the public methods of this Component. * * @exception IllegalStateException if this component has not been started * @exception LifecycleException if this component detects a fatal error * that needs to be reported */ public synchronized void stop() throws LifecycleException { // Validate and update our current component state if (!started) throw new LifecycleException (sm.getString("standardPipeline.notStarted")); // Notify our interested LifecycleListeners lifecycle.fireLifecycleEvent(STOP_EVENT, null); started = false; // Stop the Valves in our pipeline (including the basic), if any if ((basic != null) && (basic instanceof Lifecycle)) ((Lifecycle) basic).stop(); for (int i = 0; i < valves.length; i++) { if (valves[i] instanceof Lifecycle) ((Lifecycle) valves[i]).stop(); } } // ------------------------------------------------------- Pipeline Methods /** * <p>Return the Valve instance that has been distinguished as the basic * Valve for this Pipeline (if any). */ public Valve getBasic() { return (this.basic); } /** * <p>Set the Valve instance that has been distinguished as the basic * Valve for this Pipeline (if any). Prioer to setting the basic Valve, * the Valve's <code>setContainer()</code> will be called, if it * implements <code>Contained</code>, with the owning Container as an * argument. The method may throw an <code>IllegalArgumentException</code> * if this Valve chooses not to be associated with this Container, or * <code>IllegalStateException</code> if it is already associated with * a different Container.</p> * * @param valve Valve to be distinguished as the basic Valve */ public void setBasic(Valve valve) { // Change components if necessary Valve oldBasic = this.basic; if (oldBasic == valve) return; // Stop the old component if necessary if (oldBasic != null) { if (started && (oldBasic instanceof Lifecycle)) { try { ((Lifecycle) oldBasic).stop(); } catch (LifecycleException e) { log("StandardPipeline.setBasic: stop", e); } } if (oldBasic instanceof Contained) { try { ((Contained) oldBasic).setContainer(null); } catch (Throwable t) { ; } } } // Start the new component if necessary if (valve == null) return; if (valve instanceof Contained) { ((Contained) valve).setContainer(this.container); } if (valve instanceof Lifecycle) { try { ((Lifecycle) valve).start(); } catch (LifecycleException e) { log("StandardPipeline.setBasic: start", e); return; } } this.basic = valve; } /** * <p>Add a new Valve to the end of the pipeline associated with this * Container. Prior to adding the Valve, the Valve's * <code>setContainer()</code> method will be called, if it implements * <code>Contained</code>, with the owning Container as an argument. * The method may throw an * <code>IllegalArgumentException</code> if this Valve chooses not to * be associated with this Container, or <code>IllegalStateException</code> * if it is already associated with a different Container.</p> * * @param valve Valve to be added * * @exception IllegalArgumentException if this Container refused to * accept the specified Valve * @exception IllegalArgumentException if the specifie Valve refuses to be * associated with this Container * @exception IllegalStateException if the specified Valve is already * associated with a different Container */ public void addValve(Valve valve) { // Validate that we can add this Valve if (valve instanceof Contained) ((Contained) valve).setContainer(this.container); // Start the new component if necessary if (started && (valve instanceof Lifecycle)) { try { ((Lifecycle) valve).start(); } catch (LifecycleException e) { log("StandardPipeline.addValve: start: ", e); } } // Add this Valve to the set associated with this Pipeline synchronized (valves) { Valve results[] = new Valve[valves.length +1]; System.arraycopy(valves, 0, results, 0, valves.length); results[valves.length] = valve; valves = results; } } /** * Return the set of Valves in the pipeline associated with this * Container, including the basic Valve (if any). If there are no * such Valves, a zero-length array is returned. */ public Valve[] getValves() { if (basic == null) return (valves); synchronized (valves) { Valve results[] = new Valve[valves.length + 1]; System.arraycopy(valves, 0, results, 0, valves.length); results[valves.length] = basic; return (results); } } /** * Cause the specified request and response to be processed by the Valves * associated with this pipeline, until one of these valves causes the * response to be created and returned. The implementation must ensure * that multiple simultaneous requests (on different threads) can be * processed through the same Pipeline without interfering with each * other's control flow. * * @param request The servlet request we are processing * @param response The servlet response we are creating * * @exception IOException if an input/output error occurs * @exception ServletException if a servlet exception is thrown */ public void invoke(Request request, Response response) throws IOException, ServletException { // Initialize the per-thread state for this thread state.set(new Integer(0)); // Invoke the first Valve in this pipeline for this request invokeNext(request, response); } /** * Remove the specified Valve from the pipeline associated with this * Container, if it is found; otherwise, do nothing. If the Valve is * found and removed, the Valve's <code>setContainer(null)</code> method * will be called if it implements <code>Contained</code>. * * @param valve Valve to be removed */ public void removeValve(Valve valve) { synchronized (valves) { // Locate this Valve in our list int j = -1; for (int i = 0; i < valves.length; i++) { if (valve == valves[i]) { j = i; break; } } if (j < 0) return; // Remove this valve from our list Valve results[] = new Valve[valves.length - 1]; int n = 0; for (int i = 0; i < valves.length; i++) { if (i == j) continue; results[n++] = valves[i]; } valves = results; try { if (valve instanceof Contained) ((Contained) valve).setContainer(null); } catch (Throwable t) { ; } } // Stop this valve if necessary if (started && (valve instanceof Lifecycle)) { try { ((Lifecycle) valve).stop(); } catch (LifecycleException e) { log("StandardPipeline.removeValve: stop: ", e); } } } // --------------------------------------------------- ValveContext Methods /** * Cause the <code>invoke()</code> method of the next Valve that is part of * the Pipeline currently being processed (if any) to be executed, passing * on the specified request and response objects plus this * <code>ValveContext</code> instance. Exceptions thrown by a subsequently * executed Valve (or a Filter or Servlet at the application level) will be * passed on to our caller. * * If there are no more Valves to be executed, an appropriate * ServletException will be thrown by this ValveContext. * * @param request The request currently being processed * @param response The response currently being created * * @exception IOException if thrown by a subsequent Valve, Filter, or * Servlet * @exception ServletException if thrown by a subsequent Valve, Filter, * or Servlet * @exception ServletException if there are no further Valves configured * in the Pipeline currently being processed */ public void invokeNext(Request request, Response response) throws IOException, ServletException { // Identify the current subscript for the current request thread Integer current = (Integer) state.get(); int subscript = current.intValue(); state.set(new Integer(subscript + 1)); // Invoke the requested Valve for the current request thread if (subscript < valves.length) { valves[subscript].invoke(request, response, this); } else if ((subscript == valves.length) && (basic != null)) { basic.invoke(request, response, this); } else { throw new ServletException (sm.getString("standardPipeline.noValve")); } } // ------------------------------------------------------ Protected Methods /** * Log a message on the Logger associated with our Container (if any). * * @param message Message to be logged */ protected void log(String message) { Logger logger = null; if (container != null) logger = container.getLogger(); if (logger != null) logger.log("StandardPipeline[" + container.getName() + "]: " + message); else System.out.println("StandardPipeline[" + container.getName() + "]: " + message); } /** * Log a message on the Logger associated with our Container (if any). * * @param message Message to be logged * @param throwable Associated exception */ protected void log(String message, Throwable throwable) { Logger logger = null; if (container != null) logger = container.getLogger(); if (logger != null) logger.log("StandardPipeline[" + container.getName() + "]: " + message, throwable); else { System.out.println("StandardPipeline[" + container.getName() + "]: " + message); throwable.printStackTrace(System.out); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]