From: markt Date: Sat, 15 May 2010 22:40:16 +0000 (+0000) Subject: Fix auto-deploy issues caused by Lifecycle refactoring. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=92d61ad9d108e129bc8c426546e4dc22309906fb;p=tomcat7.0 Fix auto-deploy issues caused by Lifecycle refactoring. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@944738 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index 7fd3b722f..dd8ee2f6a 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -70,6 +70,20 @@ public interface Context extends Container { */ public static final String RELOAD_EVENT = "reload"; + /** + * Container event for adding a welcome file. + */ + public static final String ADD_WELCOME_FILE_EVENT = "addWelcomeFile"; + + /** + * Container event for removing a wrapper. + */ + public static final String REMOVE_WELCOME_FILE_EVENT = "removeWelcomeFile"; + + /** + * Container event for clearing welcome files. + */ + public static final String CLEAR_WELCOME_FILES_EVENT = "clearWelcomeFiles"; // ------------------------------------------------------------- Properties diff --git a/java/org/apache/catalina/Wrapper.java b/java/org/apache/catalina/Wrapper.java index 5fb007263..72df8db5d 100644 --- a/java/org/apache/catalina/Wrapper.java +++ b/java/org/apache/catalina/Wrapper.java @@ -50,6 +50,15 @@ import javax.servlet.UnavailableException; public interface Wrapper extends Container { + /** + * Container event for adding a wrapper. + */ + public static final String ADD_MAPPING_EVENT = "addMapping"; + + /** + * Container event for removing a wrapper. + */ + public static final String REMOVE_MAPPING_EVENT = "removeMapping"; // ------------------------------------------------------------- Properties diff --git a/java/org/apache/catalina/connector/MapperListener.java b/java/org/apache/catalina/connector/MapperListener.java index 5f07c6ad3..bb7137fce 100644 --- a/java/org/apache/catalina/connector/MapperListener.java +++ b/java/org/apache/catalina/connector/MapperListener.java @@ -254,6 +254,69 @@ public class MapperListener event.getData().toString()); } else if (event.getType() == Host.REMOVE_ALIAS_EVENT) { mapper.removeHostAlias(event.getData().toString()); + } else if (event.getType() == Wrapper.ADD_MAPPING_EVENT) { + Wrapper wrapper = (Wrapper) event.getSource(); + + String contextName = wrapper.getParent().getName(); + if ("/".equals(contextName)) { + contextName = ""; + } + String hostName = wrapper.getParent().getParent().getName(); + + String mapping = (String) event.getData(); + boolean jspWildCard = ("jsp".equals(wrapper.getName()) + && mapping.endsWith("/*")); + mapper.addWrapper(hostName, contextName, mapping, wrapper, + jspWildCard); + } else if (event.getType() == Wrapper.REMOVE_MAPPING_EVENT) { + Wrapper wrapper = (Wrapper) event.getSource(); + + String contextName = wrapper.getParent().getName(); + if ("/".equals(contextName)) { + contextName = ""; + } + String hostName = wrapper.getParent().getParent().getName(); + + String mapping = (String) event.getData(); + + mapper.removeWrapper(hostName, contextName, mapping); + } else if (event.getType() == Context.ADD_WELCOME_FILE_EVENT) { + Context context = (Context) event.getSource(); + + String hostName = context.getParent().getName(); + + String contextName = context.getName(); + if ("/".equals(contextName)) { + contextName = ""; + } + + String welcomeFile = (String) event.getData(); + + mapper.addWelcomeFile(hostName, contextName, welcomeFile); + } else if (event.getType() == Context.REMOVE_WELCOME_FILE_EVENT) { + Context context = (Context) event.getSource(); + + String hostName = context.getParent().getName(); + + String contextName = context.getName(); + if ("/".equals(contextName)) { + contextName = ""; + } + + String welcomeFile = (String) event.getData(); + + mapper.removeWelcomeFile(hostName, contextName, welcomeFile); + } else if (event.getType() == Context.CLEAR_WELCOME_FILES_EVENT) { + Context context = (Context) event.getSource(); + + String hostName = context.getParent().getName(); + + String contextName = context.getName(); + if ("/".equals(contextName)) { + contextName = ""; + } + + mapper.clearWelcomeFiles(hostName, contextName); } } @@ -303,6 +366,9 @@ public class MapperListener String[] aliases = host.findAliases(); mapper.addHost(host.getName(), aliases, host.getObjectName()); + + host.addContainerListener(this); + if(log.isDebugEnabled()) { log.debug(sm.getString ("mapperListener.registerHost", host.getName(), domain)); @@ -315,6 +381,8 @@ public class MapperListener */ private void unregisterHost(Host host) { + host.removeContainerListener(this); + String hostname = host.getName(); mapper.removeHost(hostname); @@ -330,6 +398,8 @@ public class MapperListener */ private void unregisterWrapper(Wrapper wrapper) { + wrapper.removeContainerListener(this); + String contextName = wrapper.getParent().getName(); if ("/".equals(contextName)) { contextName = ""; @@ -361,6 +431,8 @@ public class MapperListener mapper.addContext(hostName, contextName, context, welcomeFiles, resources); + context.addContainerListener(this); + if(log.isDebugEnabled()) { log.debug(sm.getString ("mapperListener.registerContext", contextName)); @@ -377,6 +449,8 @@ public class MapperListener if (context.getPaused()){ return; } + + context.removeContainerListener(this); String contextName = context.getName(); if ("/".equals(contextName)) { @@ -413,6 +487,9 @@ public class MapperListener jspWildCard); } + // Also want to watch for any changes to the mappings for this wrapper + wrapper.addContainerListener(this); + if(log.isDebugEnabled()) { log.debug(sm.getString("mapperListener.registerWrapper", wrapperName, contextName)); @@ -422,7 +499,7 @@ public class MapperListener @Override public void lifecycleEvent(LifecycleEvent event) { - if (event.getType() == Lifecycle.AFTER_START_EVENT) { + if (event.getType() == Lifecycle.BEFORE_START_EVENT) { Object obj = event.getSource(); if (obj instanceof Wrapper) { registerWrapper((Wrapper) obj); diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 8e72e70ef..e77f0ba02 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -2840,6 +2840,7 @@ public class StandardContext extends ContainerBase // Welcome files from the application deployment descriptor // completely replace those from the default conf/web.xml file if (replaceWelcomeFiles) { + fireContainerEvent(CLEAR_WELCOME_FILES_EVENT, null); welcomeFiles = new String[0]; setReplaceWelcomeFiles(false); } @@ -2850,7 +2851,7 @@ public class StandardContext extends ContainerBase welcomeFiles = results; } postWelcomeFiles(); - fireContainerEvent("addWelcomeFile", name); + fireContainerEvent(ADD_WELCOME_FILE_EVENT, name); } @@ -3903,7 +3904,7 @@ public class StandardContext extends ContainerBase // Inform interested listeners postWelcomeFiles(); - fireContainerEvent("removeWelcomeFile", name); + fireContainerEvent(REMOVE_WELCOME_FILE_EVENT, name); } diff --git a/java/org/apache/catalina/core/StandardWrapper.java b/java/org/apache/catalina/core/StandardWrapper.java index 7c899c7e5..690ade006 100644 --- a/java/org/apache/catalina/core/StandardWrapper.java +++ b/java/org/apache/catalina/core/StandardWrapper.java @@ -759,7 +759,7 @@ public class StandardWrapper extends ContainerBase synchronized (mappings) { mappings.add(mapping); } - fireContainerEvent("addMapping", mapping); + fireContainerEvent(ADD_MAPPING_EVENT, mapping); } @@ -1246,7 +1246,7 @@ public class StandardWrapper extends ContainerBase synchronized (mappings) { mappings.remove(mapping); } - fireContainerEvent("removeMapping", mapping); + fireContainerEvent(REMOVE_MAPPING_EVENT, mapping); } diff --git a/java/org/apache/tomcat/util/http/mapper/Mapper.java b/java/org/apache/tomcat/util/http/mapper/Mapper.java index 0f93a815d..38a22fe24 100644 --- a/java/org/apache/tomcat/util/http/mapper/Mapper.java +++ b/java/org/apache/tomcat/util/http/mapper/Mapper.java @@ -547,7 +547,116 @@ public final class Mapper { } - + /** + * Add a welcome file to the given context. + * + * @param hostName + * @param contextPath + * @param welcomeFile + */ + public void addWelcomeFile(String hostName, String contextPath, + String welcomeFile) { + Host[] hosts = this.hosts; + int pos = find(hosts, hostName); + if (pos < 0) { + return; + } + Host host = hosts[pos]; + if (host.name.equals(hostName)) { + Context[] contexts = host.contextList.contexts; + int pos2 = find(contexts, contextPath); + if( pos2<0 ) { + log.error("No context found: " + contextPath ); + return; + } + Context context = contexts[pos2]; + if (context.name.equals(contextPath)) { + int len = context.welcomeResources.length + 1; + String[] newWelcomeResources = new String[len]; + System.arraycopy(context.welcomeResources, 0, + newWelcomeResources, 0, len - 1); + newWelcomeResources[len - 1] = welcomeFile; + context.welcomeResources = newWelcomeResources; + } + } + } + + + /** + * Remove a welcome file from the given context. + * + * @param hostName + * @param contextPath + * @param welcomeFile + */ + public void removeWelcomeFile(String hostName, String contextPath, + String welcomeFile) { + Host[] hosts = this.hosts; + int pos = find(hosts, hostName); + if (pos < 0) { + return; + } + Host host = hosts[pos]; + if (host.name.equals(hostName)) { + Context[] contexts = host.contextList.contexts; + int pos2 = find(contexts, contextPath); + if( pos2<0 ) { + log.error("No context found: " + contextPath ); + return; + } + Context context = contexts[pos2]; + if (context.name.equals(contextPath)) { + int match = -1; + for (int i = 0; i < context.welcomeResources.length; i++) { + if (welcomeFile.equals(context.welcomeResources[i])) { + match = i; + break; + } + } + if (match > -1) { + int len = context.welcomeResources.length - 1; + String[] newWelcomeResources = new String[len]; + System.arraycopy(context.welcomeResources, 0, + newWelcomeResources, 0, match); + if (match < len) { + System.arraycopy(context.welcomeResources, match + 1, + newWelcomeResources, match, len - match); + } + context.welcomeResources = newWelcomeResources; + } + } + } + } + + + /** + * Clear the welcome files for the given context. + * + * @param hostName + * @param contextPath + */ + public void clearWelcomeFiles(String hostName, String contextPath) { + Host[] hosts = this.hosts; + int pos = find(hosts, hostName); + if (pos < 0) { + return; + } + Host host = hosts[pos]; + if (host.name.equals(hostName)) { + Context[] contexts = host.contextList.contexts; + int pos2 = find(contexts, contextPath); + if( pos2<0 ) { + log.error("No context found: " + contextPath ); + return; + } + Context context = contexts[pos2]; + if (context.name.equals(contextPath)) { + context.welcomeResources = new String[0]; + } + } + } + + /** * Map the specified host name and URI, mutating the given mapping data. *