cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] cxf git commit: [CXF-6887] Handle multiple busses and avoid NPE
Date Mon, 02 May 2016 08:38:20 GMT
Repository: cxf
Updated Branches:
  refs/heads/origin/3.1.x-fixes [created] 695f567c2


[CXF-6887] Handle multiple busses and avoid NPE


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/5d1d478f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/5d1d478f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/5d1d478f

Branch: refs/heads/origin/3.1.x-fixes
Commit: 5d1d478f03b726dde95550f91eb40a9af1db06b1
Parents: ea6a524
Author: Christian Schneider <chris@die-schneider.net>
Authored: Fri Apr 29 15:45:42 2016 +0200
Committer: Christian Schneider <chris@die-schneider.net>
Committed: Mon May 2 09:25:40 2016 +0200

----------------------------------------------------------------------
 .../transport/http/asyncclient/Activator.java   | 56 +++++++++++---------
 1 file changed, 30 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/5d1d478f/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
----------------------------------------------------------------------
diff --git a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
index 32f4321..13d1f52 100644
--- a/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
+++ b/rt/transports/http-hc/src/main/java/org/apache/cxf/transport/http/asyncclient/Activator.java
@@ -25,47 +25,36 @@ import java.util.Hashtable;
 import java.util.Map;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.transport.http.HTTPConduitFactory;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
+import org.osgi.framework.ServiceReference;
 import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.util.tracker.ServiceTracker;
 
 public class Activator implements BundleActivator {
-
-    private ServiceTracker tracker;
+    private ConduitConfigurer conduitConfigurer;
 
     @Override
     public void start(BundleContext context) throws Exception {
-        tracker = new ServiceTracker(context, Bus.class.getName(), null);
-        tracker.open();
-        ConduitConfigurer conduitConfigurer = new ConduitConfigurer(context, tracker);
-        registerManagedService(context, conduitConfigurer, "org.apache.cxf.transport.http.async");
-    }
-
-    private void registerManagedService(BundleContext context, ConduitConfigurer conduitConfigurer,
String servicePid) {
+        conduitConfigurer = new ConduitConfigurer(context);
+        conduitConfigurer.open();
         Dictionary<String, Object> properties = new Hashtable<String, Object>();
-        properties.put(Constants.SERVICE_PID, servicePid);
+        properties.put(Constants.SERVICE_PID, "org.apache.cxf.transport.http.async");
         context.registerService(ManagedService.class.getName(), conduitConfigurer, properties);
     }
 
     @Override
     public void stop(BundleContext context) throws Exception {
-        tracker.close();
+        conduitConfigurer.close();
     }
 
-    class ConduitConfigurer implements ManagedService {
-        private AsyncHTTPConduitFactory conduitFactory;
-        private ServiceTracker busTracker;
-        private BundleContext context;
-        private ServiceRegistration reg;
+    public class ConduitConfigurer extends ServiceTracker implements ManagedService {
+        private Map<String, Object> currentConfig;
         
-        ConduitConfigurer(BundleContext context, ServiceTracker busTracker) {
-            this.context = context;
-            this.busTracker = busTracker;
+        public ConduitConfigurer(BundleContext context) {
+            super(context, Bus.class.getName(), null);
         }
 
         @SuppressWarnings({
@@ -73,12 +62,21 @@ public class Activator implements BundleActivator {
         })
         @Override
         public void updated(Dictionary properties) throws ConfigurationException {
-            if (reg != null) {
-                reg.unregister();
+            this.currentConfig = toMap(properties);
+            Bus[] buses = (Bus[])getServices();
+            if (buses == null) {
+                return;
             }
-            conduitFactory = new AsyncHTTPConduitFactory((Bus)this.busTracker.getService());
-            conduitFactory.update(toMap(properties));
-            reg = context.registerService(HTTPConduitFactory.class.getName(), conduitFactory,
null);
+            for (Bus bus : buses) {
+                configureConduitFactory(bus);
+            }
+        }
+        
+        @Override
+        public Object addingService(ServiceReference reference) {
+            Bus bus = (Bus)super.addingService(reference);
+            configureConduitFactory(bus);
+            return bus;
         }
         
         private Map<String, Object> toMap(Dictionary<String, ?> properties) {
@@ -94,5 +92,11 @@ public class Activator implements BundleActivator {
             return props;
         }
         
+        private void configureConduitFactory(Bus bus) {
+            AsyncHTTPConduitFactory conduitFactory = bus.getExtension(AsyncHTTPConduitFactory.class);
+            conduitFactory.update(this.currentConfig);
+        }
+
+        
     }
 }


Mime
View raw message