You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2009/10/26 10:11:58 UTC
svn commit: r829733 -
/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Author: antelder
Date: Mon Oct 26 09:11:58 2009
New Revision: 829733
URL: http://svn.apache.org/viewvc?rev=829733&view=rev
Log:
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
Modified:
tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Modified: tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=829733&r1=829732&r2=829733&view=diff
==============================================================================
--- tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java (original)
+++ tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java Mon Oct 26 09:11:58 2009
@@ -25,8 +25,10 @@
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 @@
@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 @@
}
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() {