Author: markt Date: Sat May 15 22:40:16 2010 New Revision: 944738 URL: http://svn.apache.org/viewvc?rev=944738&view=rev Log: Fix auto-deploy issues caused by Lifecycle refactoring.
Modified: tomcat/trunk/java/org/apache/catalina/Context.java tomcat/trunk/java/org/apache/catalina/Wrapper.java tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java tomcat/trunk/java/org/apache/catalina/core/StandardContext.java tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java Modified: tomcat/trunk/java/org/apache/catalina/Context.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Context.java?rev=944738&r1=944737&r2=944738&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/Context.java (original) +++ tomcat/trunk/java/org/apache/catalina/Context.java Sat May 15 22:40:16 2010 @@ -70,6 +70,20 @@ public interface Context extends Contain */ 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 Modified: tomcat/trunk/java/org/apache/catalina/Wrapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Wrapper.java?rev=944738&r1=944737&r2=944738&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/Wrapper.java (original) +++ tomcat/trunk/java/org/apache/catalina/Wrapper.java Sat May 15 22:40:16 2010 @@ -50,6 +50,15 @@ import javax.servlet.UnavailableExceptio 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 Modified: tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java?rev=944738&r1=944737&r2=944738&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java (original) +++ tomcat/trunk/java/org/apache/catalina/connector/MapperListener.java Sat May 15 22:40:16 2010 @@ -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); Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=944738&r1=944737&r2=944738&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Sat May 15 22:40:16 2010 @@ -2840,6 +2840,7 @@ public class StandardContext extends Con // 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 Con welcomeFiles = results; } postWelcomeFiles(); - fireContainerEvent("addWelcomeFile", name); + fireContainerEvent(ADD_WELCOME_FILE_EVENT, name); } @@ -3903,7 +3904,7 @@ public class StandardContext extends Con // Inform interested listeners postWelcomeFiles(); - fireContainerEvent("removeWelcomeFile", name); + fireContainerEvent(REMOVE_WELCOME_FILE_EVENT, name); } Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java?rev=944738&r1=944737&r2=944738&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java (original) +++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java Sat May 15 22:40:16 2010 @@ -759,7 +759,7 @@ public class StandardWrapper extends Con synchronized (mappings) { mappings.add(mapping); } - fireContainerEvent("addMapping", mapping); + fireContainerEvent(ADD_MAPPING_EVENT, mapping); } @@ -1246,7 +1246,7 @@ public class StandardWrapper extends Con synchronized (mappings) { mappings.remove(mapping); } - fireContainerEvent("removeMapping", mapping); + fireContainerEvent(REMOVE_MAPPING_EVENT, mapping); } Modified: tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java?rev=944738&r1=944737&r2=944738&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java Sat May 15 22:40:16 2010 @@ -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. * --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org