FELIX-2009 ensure console servlet is rebound to the HttpService only if required and also unbound with the old location and then bound with the new location

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@903286 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index 0f2d6b8..30a6006 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -853,10 +853,10 @@
         }
 
         // get the web manager root path
-        webManagerRoot = this.getProperty( config, PROP_MANAGER_ROOT, DEFAULT_MANAGER_ROOT );
-        if ( !webManagerRoot.startsWith( "/" ) )
+        String newWebManagerRoot = this.getProperty( config, PROP_MANAGER_ROOT, DEFAULT_MANAGER_ROOT );
+        if ( !newWebManagerRoot.startsWith( "/" ) )
         {
-            webManagerRoot = "/" + webManagerRoot;
+            newWebManagerRoot = "/" + newWebManagerRoot;
         }
 
         // get enabled plugins
@@ -881,13 +881,22 @@
         }
 
         // might update http service registration
-        HttpService httpService = this.httpService;
-        if ( httpService != null )
+        if ( !newWebManagerRoot.equals( this.webManagerRoot ) )
         {
-            synchronized ( this )
+            HttpService httpService = this.httpService;
+            if ( httpService != null )
             {
-                unbindHttpService( httpService );
-                bindHttpService( httpService );
+                synchronized ( this )
+                {
+                    // unbind old location first
+                    unbindHttpService( httpService );
+
+                    // switch location
+                    this.webManagerRoot = newWebManagerRoot;
+
+                    // bind new location now
+                    bindHttpService( httpService );
+                }
             }
         }
     }