felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r739726 - /felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
Date Sun, 01 Feb 2009 10:03:03 GMT
Author: fmeschbe
Date: Sun Feb  1 10:03:02 2009
New Revision: 739726

URL: http://svn.apache.org/viewvc?rev=739726&view=rev
Log:
FELIX-913 Fix Servlet/Resource registration and unregistration:
  * Do not unregister if not registered
  * Do not unregister from an HttpService we are not using
  * Do not try to register if already bound to an HttpService

Modified:
    felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java

Modified: felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java?rev=739726&r1=739725&r2=739726&view=diff
==============================================================================
--- felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
(original)
+++ felix/trunk/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
Sun Feb  1 10:03:02 2009
@@ -158,6 +158,12 @@
 
     private String webManagerRoot;
 
+    // true if the OsgiManager is registered as a Servlet with the HttpService
+    private boolean httpServletRegistered;
+
+    // true if the resources have been registered with the HttpService
+    private boolean httpResourcesRegistered;
+
     private Dictionary configuration;
 
 
@@ -423,12 +429,12 @@
 
         public Object addingService( ServiceReference reference )
         {
-            Object operation = super.addingService( reference );
-            if ( operation instanceof HttpService )
+            Object service = super.addingService( reference );
+            if ( service instanceof HttpService )
             {
-                osgiManager.bindHttpService( ( HttpService ) operation );
+                osgiManager.bindHttpService( ( HttpService ) service );
             }
-            return operation;
+            return service;
         }
 
 
@@ -560,6 +566,14 @@
 
     protected synchronized void bindHttpService( HttpService httpService )
     {
+        // do not bind service, when we are already bound
+        if ( this.httpService != null )
+        {
+            log.log( LogService.LOG_DEBUG,
+                "bindHttpService: Already bound to an HTTP Service, ignoring further services"
);
+            return;
+        }
+        
         Dictionary config = getConfiguration();
 
         // get authentication details
@@ -574,13 +588,18 @@
 
             Dictionary servletConfig = toStringConfig( config );
 
+            // register this servlet and take note of this
             httpService.registerServlet( this.webManagerRoot, this, servletConfig, httpContext
);
+            httpServletRegistered = true;
+
+            // register resources and take of this
             httpService.registerResources( this.webManagerRoot + "/res", "/res", httpContext
);
+            httpResourcesRegistered = true;
 
         }
         catch ( Exception e )
         {
-            log.log( LogService.LOG_ERROR, "Problem setting up", e );
+            log.log( LogService.LOG_ERROR, "bindHttpService: Problem setting up", e );
         }
 
         this.httpService = httpService;
@@ -589,12 +608,40 @@
 
     protected synchronized void unbindHttpService( HttpService httpService )
     {
-        httpService.unregister( this.webManagerRoot + "/res" );
-        httpService.unregister( this.webManagerRoot );
+        if ( this.httpService != httpService )
+        {
+            log.log( LogService.LOG_DEBUG,
+                "unbindHttpService: Ignoring unbind of an HttpService to which we are not
registered" );
+            return;
+        }
+
+        // drop the service reference
+        this.httpService = null;
 
-        if ( this.httpService == httpService )
+        if ( httpResourcesRegistered )
         {
-            this.httpService = null;
+            try
+            {
+                httpService.unregister( this.webManagerRoot + "/res" );
+            }
+            catch ( Throwable t )
+            {
+                log.log( LogService.LOG_WARNING, "unbindHttpService: Failed unregistering
Resources", t );
+            }
+            httpResourcesRegistered = false;
+        }
+
+        if ( httpServletRegistered )
+        {
+            try
+            {
+                httpService.unregister( this.webManagerRoot );
+            }
+            catch ( Throwable t )
+            {
+                log.log( LogService.LOG_WARNING, "unbindHttpService: Failed unregistering
Servlet", t );
+            }
+            httpServletRegistered = false;
         }
     }
 



Mime
View raw message