From 1ab88841c867917c5671dc4deeb5a7783dd706a9 Mon Sep 17 00:00:00 2001 From: Hugues Malphettes Date: Sat, 20 Nov 2010 02:54:48 +0000 Subject: [PATCH] fix bug 330098 The AppProvider was not indexing the ContextHandler that was deployed well enough git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2544 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../jetty/osgi/boot/OSGiAppProvider.java | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java index acaa1ab7f92..cf31174c980 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/boot/OSGiAppProvider.java @@ -17,6 +17,7 @@ package org.eclipse.jetty.osgi.boot; import java.io.File; import java.io.FilenameFilter; import java.io.IOException; +import java.util.Map.Entry; import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.AppProvider; @@ -49,7 +50,7 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider private boolean _parentLoaderPriority = false; private String _defaultsDescriptor; private String _tldBundles; - + /** * When a context file corresponds to a deployed bundle and is changed we * reload the corresponding bundle. @@ -90,6 +91,29 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider return null; } + /** + * Reading the display name of a webapp is really not sufficient for indexing the various + * deployed ContextHandlers. + * + * @param context + * @return + */ + private String getContextHandlerAppName(ContextHandler context) { + String appName = context.getDisplayName(); + if (appName == null || appName.length() == 0 || getDeployedApps().containsKey(appName)) { + if (context instanceof WebAppContext) + { + appName = ((WebAppContext)context).getContextPath(); + if (getDeployedApps().containsKey(appName)) { + appName = "noDisplayName"+context.getClass().getSimpleName()+context.hashCode(); + } + } else { + appName = "noDisplayName"+context.getClass().getSimpleName()+context.hashCode(); + } + } + return appName; + } + /** * Default OSGiAppProvider consutructed when none are defined in the * jetty.xml configuration. @@ -168,7 +192,8 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider // wrap context as an App App app = new App(getDeploymentManager(),this,originId,context); - getDeployedApps().put(context.getDisplayName(),app); + String appName = getContextHandlerAppName(context); + getDeployedApps().put(appName,app); getDeploymentManager().addApp(app); } @@ -199,7 +224,23 @@ public class OSGiAppProvider extends ScanningAppProvider implements AppProvider public void removeContext(ContextHandler context) throws Exception { + String appName = getContextHandlerAppName(context); App app = getDeployedApps().remove(context.getDisplayName()); + if (app == null) { + //try harder to undeploy this context handler. + //see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=330098 + appName = null; + for (Entry deployedApp : getDeployedApps().entrySet()) { + if (deployedApp.getValue().getContextHandler() == context) { + app = deployedApp.getValue(); + appName = deployedApp.getKey(); + break; + } + } + if (appName != null) { + getDeployedApps().remove(appName); + } + } if (app != null) { getDeploymentManager().removeApp(app);