remm 2002/09/26 03:25:03 Modified: catalina/src/share/org/apache/catalina/core LocalStrings.properties StandardContext.java Log: - Fix bug 13015. - Refactor resources lifecycle handling (it should be clean this time). - Resources cannot be changed while Catalina is running. Revision Changes Path 1.46 +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.45 retrieving revision 1.46 diff -u -r1.45 -r1.46 --- LocalStrings.properties 20 Mar 2002 12:29:55 -0000 1.45 +++ LocalStrings.properties 26 Sep 2002 10:25:03 -0000 1.46 @@ -61,6 +61,9 @@ standardContext.reloadingCompleted=Reloading this Context is completed standardContext.reloadingFailed=Reloading this Context failed due to previous errors standardContext.reloadingStarted=Reloading this Context has started +standardContext.resources.started=Cannot change resources while context is started +standardContext.resourcesStart=Resources start failed: +standardContext.resourcesStop=Resources start failed: standardContext.securityConstraint.pattern=Invalid <url-pattern> {0} in security constraint standardContext.servletMap.name=Servlet mapping specifies an unknown servlet name {0} standardContext.servletMap.pattern=Invalid <url-pattern> {0} in servlet mapping 1.113 +93 -39 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.112 retrieving revision 1.113 diff -u -r1.112 -r1.113 --- StandardContext.java 9 Sep 2002 14:39:37 -0000 1.112 +++ StandardContext.java 26 Sep 2002 10:25:03 -0000 1.113 @@ -488,6 +488,12 @@ protected boolean cachingAllowed = true; + /** + * Non proxied resources. + */ + protected DirContext webappResources = null; + + // ----------------------------------------------------- Context Properties @@ -1145,15 +1151,28 @@ */ public synchronized void setResources(DirContext resources) { + if (started) { + throw new IllegalStateException + (sm.getString("standardContext.resources.started")); + } + + DirContext oldResources = this.webappResources; + if (oldResources == resources) + return; + if (resources instanceof BaseDirContext) { ((BaseDirContext) resources).setCached(isCachingAllowed()); } if (resources instanceof FileDirContext) { filesystemBased = true; } - super.setResources(resources); - if (started) - postResources(); // As a servlet context attribute + this.webappResources = resources; + + // The proxied resources will be refreshed on start + this.resources = null; + + support.firePropertyChange("resources", oldResources, + this.webappResources); } @@ -3303,6 +3322,66 @@ /** + * Allocate resources, including proxy. + * Return <code>true</code> if initialization was successfull, + * or <code>false</code> otherwise. + */ + public boolean resourcesStart() { + + boolean ok = true; + + Hashtable env = new Hashtable(); + if (getParent() != null) + env.put(ProxyDirContext.HOST, getParent().getName()); + env.put(ProxyDirContext.CONTEXT, getName()); + + try { + ProxyDirContext proxyDirContext = + new ProxyDirContext(env, webappResources); + if (webappResources instanceof BaseDirContext) { + ((BaseDirContext) webappResources).setDocBase(getBasePath()); + ((BaseDirContext) webappResources).allocate(); + } + this.resources = proxyDirContext; + } catch (Throwable t) { + log(sm.getString("standardContext.resourcesStart", t)); + ok = false; + } + + return (ok); + + } + + + /** + * Deallocate resources and destroy proxy. + */ + public boolean resourcesStop() { + + boolean ok = true; + + try { + if (resources != null) { + if (resources instanceof Lifecycle) { + ((Lifecycle) resources).stop(); + } + if (webappResources instanceof BaseDirContext) { + ((BaseDirContext) webappResources).release(); + } + } + } catch (Throwable t) { + log(sm.getString("standardContext.resourcesStop", t)); + ok = false; + } + + this.resources = null; + + return (ok); + + } + + + /** * Load and initialize all servlets marked "load on startup" in the * web application deployment descriptor. * @@ -3376,7 +3455,7 @@ boolean ok = true; // Add missing components as necessary - if (getResources() == null) { // (1) Required by Loader + if (webappResources == null) { // (1) Required by Loader if (debug >= 1) log("Configuring default Resources"); try { @@ -3389,14 +3468,9 @@ ok = false; } } - if (ok && (resources instanceof ProxyDirContext)) { - DirContext dirContext = - ((ProxyDirContext) resources).getDirContext(); - if ((dirContext != null) - && (dirContext instanceof BaseDirContext)) { - ((BaseDirContext) dirContext).setDocBase(getBasePath()); - ((BaseDirContext) dirContext).allocate(); - } + if (ok) { + if (!resourcesStart()) + ok = false; } if (getLoader() == null) { // (2) Required by Manager if (getPrivileged()) { @@ -3622,29 +3696,9 @@ // Stop our application listeners listenerStop(); - // Stop our subordinate components, if any - if (resources != null) { - if (resources instanceof Lifecycle) { - ((Lifecycle) resources).stop(); - } else if (resources instanceof ProxyDirContext) { - DirContext dirContext = - ((ProxyDirContext) resources).getDirContext(); - if (dirContext != null) { - if (debug >= 1) { - log("Releasing document base " + docBase); - } - if (dirContext instanceof BaseDirContext) { - ((BaseDirContext) dirContext).release(); - if ((dirContext instanceof WARDirContext) - || (dirContext instanceof FileDirContext)) { - resources = null; - } - } else { - log("Cannot release " + resources); - } - } - } - } + // Stop resources + resourcesStop(); + if ((realm != null) && (realm instanceof Lifecycle)) { ((Lifecycle) realm).stop(); }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>