You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2023/01/09 22:50:46 UTC

[cxf] branch 3.4.x-fixes updated: CXF-8810: Fix http-hc osgi startup (#1046)

This is an automated email from the ASF dual-hosted git repository.

reta pushed a commit to branch 3.4.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/3.4.x-fixes by this push:
     new 465cd2c8a9 CXF-8810: Fix http-hc osgi startup (#1046)
465cd2c8a9 is described below

commit 465cd2c8a9221bf2dfdeb675d985a12d4d63d2ce
Author: jmylly <71...@users.noreply.github.com>
AuthorDate: Mon Jan 9 21:28:48 2023 +0200

    CXF-8810: Fix http-hc osgi startup (#1046)
    
    Co-authored-by: Tino Ojala <ti...@x-akseli.fi>
---
 rt/transports/http-hc/pom.xml                      |  5 ++
 .../cxf/transport/http/asyncclient/Activator.java  | 13 +++--
 .../transport/http/asyncclient/ActivatorTest.java  | 59 ++++++++++++++++++++++
 3 files changed, 70 insertions(+), 7 deletions(-)

diff --git a/rt/transports/http-hc/pom.xml b/rt/transports/http-hc/pom.xml
index f6146d68c1..194ed6917b 100644
--- a/rt/transports/http-hc/pom.xml
+++ b/rt/transports/http-hc/pom.xml
@@ -44,6 +44,11 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.core</artifactId>
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 4717570361..050a1e4ac4 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
@@ -29,7 +29,6 @@ import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.ConfigurationException;
 import org.osgi.service.cm.ManagedService;
 import org.osgi.util.tracker.ServiceTracker;
 
@@ -50,7 +49,8 @@ public class Activator implements BundleActivator {
         conduitConfigurer.close();
     }
 
-    public class ConduitConfigurer extends ServiceTracker<Bus, Bus> implements ManagedService {
+    public static class ConduitConfigurer extends ServiceTracker<Bus, Bus> implements ManagedService {
+
         private Map<String, Object> currentConfig;
 
         public ConduitConfigurer(BundleContext context) {
@@ -58,14 +58,14 @@ public class Activator implements BundleActivator {
         }
 
         @Override
-        public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
+        public void updated(Dictionary<String, ?> properties) {
             this.currentConfig = toMap(properties);
-            Bus[] buses = (Bus[])getServices();
+            Object[] buses = getServices();
             if (buses == null) {
                 return;
             }
-            for (Bus bus : buses) {
-                configureConduitFactory(bus);
+            for (Object bus : buses) {
+                configureConduitFactory((Bus) bus);
             }
         }
 
@@ -94,6 +94,5 @@ public class Activator implements BundleActivator {
             conduitFactory.update(this.currentConfig);
         }
 
-
     }
 }
diff --git a/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/ActivatorTest.java b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/ActivatorTest.java
new file mode 100644
index 0000000000..f312360bfa
--- /dev/null
+++ b/rt/transports/http-hc/src/test/java/org/apache/cxf/transport/http/asyncclient/ActivatorTest.java
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.transport.http.asyncclient;
+
+import java.util.Collections;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.osgi.framework.BundleContext;
+
+import org.easymock.EasyMock;
+import org.junit.Test;
+
+import static org.easymock.EasyMock.mock;
+
+public class ActivatorTest {
+
+    @Test
+    public void testConduitConfigurerUpdates() {
+        final Bus bus = BusFactory.getThreadDefaultBus();
+        final AsyncHTTPConduitFactory conduitFactory = mock(AsyncHTTPConduitFactory.class);
+        bus.setExtension(conduitFactory, AsyncHTTPConduitFactory.class);
+
+        final Activator.ConduitConfigurer configurer = new Activator.ConduitConfigurer(mock(BundleContext.class)) {
+            @Override
+            public Object[] getServices() {
+                return new Object[] {bus};
+            }
+        };
+
+        //Dummy service properties that are expected to be passed to conduitFactory
+        final Map<String, Object> properties = Collections.singletonMap("foo", "bar");
+        conduitFactory.update(properties);
+        EasyMock.replay(conduitFactory);
+
+        //act and verify
+        configurer.updated(new Hashtable<>(properties));
+        EasyMock.verify(conduitFactory);
+    }
+
+}