You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ti...@apache.org on 2021/07/21 17:21:36 UTC

[aries-jax-rs-whiteboard] branch master updated: Avoid publishing the JAX-RS whiteboard until CXF has fully started

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

timothyjward pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/aries-jax-rs-whiteboard.git


The following commit(s) were added to refs/heads/master by this push:
     new b9e8cb2  Avoid publishing the JAX-RS whiteboard until CXF has fully started
     new e2781c0  Merge pull request #114 from timothyjward/fix/cxf-lifecycle
b9e8cb2 is described below

commit b9e8cb2c8d1aa6762804efae6de4674be179932a
Author: Tim Ward <ti...@apache.org>
AuthorDate: Wed Jul 21 18:04:00 2021 +0100

    Avoid publishing the JAX-RS whiteboard until CXF has fully started
    
    Signed-off-by: Tim Ward <ti...@apache.org>
---
 .../main/java/test/WhiteboardLifecycleTest.java    | 46 +++++++++++++++++++
 .../activator/CxfJaxrsBundleActivator.java         | 53 ++++++++++++----------
 2 files changed, 76 insertions(+), 23 deletions(-)

diff --git a/jax-rs.itests/src/main/java/test/WhiteboardLifecycleTest.java b/jax-rs.itests/src/main/java/test/WhiteboardLifecycleTest.java
new file mode 100644
index 0000000..cd0aa09
--- /dev/null
+++ b/jax-rs.itests/src/main/java/test/WhiteboardLifecycleTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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 test;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.cxf.bus.osgi.CXFActivator;
+import org.junit.Test;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.FrameworkUtil;
+
+import test.types.TestHelper;
+
+public class WhiteboardLifecycleTest extends TestHelper {
+
+    @Test
+    public void testCXFLifecycle() throws Exception {
+    	assertNotNull(_runtimeTracker.getService());
+    	
+    	Bundle cxfBundle = FrameworkUtil.getBundle(CXFActivator.class);
+		cxfBundle.stop();
+		
+		assertNull(_runtimeTracker.getService());
+		
+		cxfBundle.start();
+		
+		assertNotNull(_runtimeTracker.waitForService(5000));
+    }
+
+}
\ No newline at end of file
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CxfJaxrsBundleActivator.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CxfJaxrsBundleActivator.java
index 44ab2c2..cf81385 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CxfJaxrsBundleActivator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/activator/CxfJaxrsBundleActivator.java
@@ -33,12 +33,14 @@ import org.apache.aries.jax.rs.whiteboard.internal.client.ClientBuilderFactory;
 import org.apache.aries.jax.rs.whiteboard.internal.utils.PropertyHolder;
 import org.apache.aries.component.dsl.OSGi;
 import org.apache.aries.component.dsl.OSGiResult;
+import org.apache.cxf.bus.osgi.CXFActivator;
 import org.apache.cxf.jaxrs.impl.RuntimeDelegateImpl;
 import org.apache.cxf.jaxrs.sse.client.SseEventSourceBuilderImpl;
 import org.osgi.annotation.bundle.Header;
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
+import org.osgi.framework.FrameworkUtil;
 import org.osgi.service.http.runtime.HttpServiceRuntime;
 import org.osgi.service.jaxrs.client.SseEventSourceFactory;
 import org.slf4j.Logger;
@@ -52,6 +54,7 @@ import static org.apache.aries.jax.rs.whiteboard.internal.utils.LogUtils.debugTr
 import static org.apache.aries.jax.rs.whiteboard.internal.utils.Utils.canonicalize;
 import static org.apache.aries.jax.rs.whiteboard.internal.Whiteboard.createWhiteboard;
 import static org.apache.aries.component.dsl.OSGi.all;
+import static org.apache.aries.component.dsl.OSGi.bundles;
 import static org.apache.aries.component.dsl.OSGi.configurations;
 import static org.apache.aries.component.dsl.OSGi.effects;
 import static org.apache.aries.component.dsl.OSGi.ignore;
@@ -59,6 +62,7 @@ import static org.apache.aries.component.dsl.OSGi.just;
 import static org.apache.aries.component.dsl.OSGi.once;
 import static org.apache.aries.component.dsl.OSGi.register;
 import static org.apache.aries.component.dsl.OSGi.serviceReferences;
+import static org.osgi.framework.Bundle.ACTIVE;
 import static org.osgi.service.http.runtime.HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_TARGET;
 
@@ -86,29 +90,32 @@ public class CxfJaxrsBundleActivator implements BundleActivator {
         }
 
         OSGi<?> runWhiteboards =
-            all(
-                configurations("org.apache.aries.jax.rs.whiteboard"),
-                coalesce(
-                    configuration("org.apache.aries.jax.rs.whiteboard.default"),
-                    just(() -> {
-                        Dictionary<String, Object> properties =
-                            new Hashtable<>();
-
-                        properties.put(
-                            Constants.SERVICE_PID,
-                            "org.apache.aries.jax.rs.whiteboard.default");
-
-                        return properties;
-                    })
-            )
-        ).filter(
-            c -> !Objects.equals(c.get("enabled"), "false")
-        ).
-        effects(
-            debugTracking(_log, () -> "whiteboard configuration")
-        ).flatMap(configuration ->
-            runWhiteboard(bundleContext, configuration)
-        );
+        	bundles(ACTIVE)
+        	.filter(b -> b.equals(FrameworkUtil.getBundle(CXFActivator.class)))
+        	.then(
+	            all(
+	                configurations("org.apache.aries.jax.rs.whiteboard"),
+	                coalesce(
+	                    configuration("org.apache.aries.jax.rs.whiteboard.default"),
+	                    just(() -> {
+	                        Dictionary<String, Object> properties =
+	                            new Hashtable<>();
+	
+	                        properties.put(
+	                            Constants.SERVICE_PID,
+	                            "org.apache.aries.jax.rs.whiteboard.default");
+	
+	                        return properties;
+	                    })
+	            )
+	        ).filter(
+	            c -> !Objects.equals(c.get("enabled"), "false")
+	        ).
+	        effects(
+	            debugTracking(_log, () -> "whiteboard configuration")
+	        ).flatMap(configuration ->
+	            runWhiteboard(bundleContext, configuration)
+	        ));
 
         _defaultOSGiResult =
             all(