summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/host-webapp
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 09:11:58 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-10-26 09:11:58 +0000
commit4066aa0f54f860a8915c1ee7d6a14bef4de13e41 (patch)
tree568a09f69a59fe7685b94d1450f3b2b10e784eba /java/sca/modules/host-webapp
parent8b9b11a03827e2622647ac1cbce9a00f08d3a0a8 (diff)
Update to re-register servlets if the servelt host context path is updated. Thats necessary of servlets are registered before the context path is initialized, which can happene when extensions register servlets during startup
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@829733 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/host-webapp')
-rw-r--r--java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java20
1 files changed, 20 insertions, 0 deletions
diff --git a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
index a90674e8e7..3253e6c026 100644
--- a/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
+++ b/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
@@ -25,8 +25,10 @@ import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.net.UnknownHostException;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
@@ -229,6 +231,8 @@ public class WebAppServletHost implements ServletHost {
@SuppressWarnings("unchecked")
public void initContextPath(ServletConfig config) {
+ String oldContextPath = contextPath;
+
if (Collections.list(config.getInitParameterNames()).contains("contextPath")) {
contextPath = config.getInitParameter("contextPath");
} else {
@@ -245,6 +249,22 @@ public class WebAppServletHost implements ServletHost {
}
logger.info("ContextPath: " + contextPath);
+
+ // if the context path changes after some servlets have been registered then
+ // need to reregister them (this can happen if extensions start before webapp init)
+ if (!oldContextPath.endsWith(contextPath)) {
+ List<String> oldServletURIs = new ArrayList<String>();
+ for (String oldServletURI : servlets.keySet()) {
+ if (oldServletURI.startsWith(oldContextPath)) {
+ oldServletURIs.add(oldServletURI);
+ }
+ }
+ for (String oldURI : oldServletURIs) {
+ String ns = contextPath + "/" + oldURI.substring(oldContextPath.length());
+ servlets.put(ns, servlets.remove(oldURI));
+ }
+ }
+
}
void destroy() {