Repository: cxf Updated Branches: refs/heads/3.1.x-fixes 4def8e9db -> 90a963f18
[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/7b1168ef Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/7b1168ef Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/7b1168ef Branch: refs/heads/3.1.x-fixes Commit: 7b1168ef760b89aa5fe92dbf2da328b1316d4ccd Parents: 4def8e9 Author: Christian Schneider <[email protected]> Authored: Fri Apr 29 15:45:42 2016 +0200 Committer: Daniel Kulp <[email protected]> Committed: Wed May 18 23:09:08 2016 -0400 ---------------------------------------------------------------------- .../transport/http/asyncclient/Activator.java | 56 +++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/7b1168ef/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); + } + + } }
