You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by cs...@apache.org on 2019/02/14 16:15:51 UTC

[aries-jax-rs-whiteboard] branch master updated: [ARIES-1893] Fill the serviceDTO

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

csierra 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 6bfef5f  [ARIES-1893] Fill the serviceDTO
6bfef5f is described below

commit 6bfef5f0a2971d1136b7c1152f5f2393368a4a34
Author: Carlos Sierra <cs...@apache.org>
AuthorDate: Thu Feb 14 17:14:49 2019 +0100

    [ARIES-1893] Fill the serviceDTO
---
 jax-rs.itests/src/main/java/test/JaxrsTest.java       |  8 ++++++++
 .../whiteboard/internal/AriesJaxrsServiceRuntime.java | 19 +++++++++++++++++++
 .../aries/jax/rs/whiteboard/internal/Whiteboard.java  | 13 +++++++++----
 .../aries/jax/rs/whiteboard/internal/utils/Utils.java | 11 +++++++++++
 4 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java
index f0680c0..85269e0 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -20,6 +20,7 @@ package test;
 import static javax.ws.rs.core.MediaType.TEXT_PLAIN_TYPE;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_PATH;
@@ -1918,6 +1919,13 @@ public class JaxrsTest extends TestHelper {
     }
 
     @Test
+    public void testServiceEndpointInRuntimeDTO() {
+        RuntimeDTO runtimeDTO = _runtime.getRuntimeDTO();
+
+        assertNotNull(runtimeDTO.serviceDTO);
+    }
+
+    @Test
     public void testServiceReferencePropertiesAreAvailableInConfigurationInjection() {
         registerApplication(
             new Application() {
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java
index 6a65679..319797d 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxrsServiceRuntime.java
@@ -46,9 +46,13 @@ import org.apache.aries.jax.rs.whiteboard.internal.cxf.CxfJaxrsServiceRegistrato
 import org.apache.aries.jax.rs.whiteboard.internal.utils.PropertyHolder;
 import org.apache.aries.jax.rs.whiteboard.internal.introspection.ClassIntrospector;
 import org.apache.aries.component.dsl.CachingServiceReference;
+import org.apache.aries.jax.rs.whiteboard.internal.utils.Utils;
 import org.apache.cxf.Bus;
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.ServiceReference;
+import org.osgi.framework.dto.ServiceReferenceDTO;
 import org.osgi.service.jaxrs.runtime.JaxrsServiceRuntime;
 import org.osgi.service.jaxrs.runtime.dto.ApplicationDTO;
 import org.osgi.service.jaxrs.runtime.dto.BaseDTO;
@@ -415,6 +419,21 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
                 FailedExtensionDTO[]::new
             );
 
+        ServiceReference<JaxrsServiceRuntime> serviceReference =
+            _whiteboard.getServiceReference();
+
+        ServiceReferenceDTO serviceDTO = new ServiceReferenceDTO();
+        serviceDTO.bundle = serviceReference.getBundle().getBundleId();
+        serviceDTO.id = (long)serviceReference.getProperty("service.id");
+        serviceDTO.usingBundles = Arrays.stream(
+            serviceReference.getUsingBundles()
+        ).mapToLong(
+            Bundle::getBundleId
+        ).toArray();
+        serviceDTO.properties = Utils.getProperties(serviceReference);
+
+        runtimeDTO.serviceDTO = serviceDTO;
+
         return runtimeDTO;
     }
 
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
index bdd813f..7e52f48 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
@@ -151,10 +151,11 @@ public class Whiteboard {
     private final Map<String, ?> _configurationMap;
     private volatile BundleContext _bundleContext;
     private volatile ServiceRegistrationChangeCounter _counter;
-    private volatile ServiceReference<?> _runtimeReference;
+    private volatile ServiceReference<JaxrsServiceRuntime> _runtimeReference;
     private final OSGi<Void> _program;
     private final List<Object> _endpoints;
-    private volatile ServiceRegistration<?> _runtimeRegistration;
+    private volatile ServiceRegistration<JaxrsServiceRuntime>
+        _runtimeRegistration;
     private OSGiResult _osgiResult;
 
     private Whiteboard(Dictionary<String, ?> configuration) {
@@ -205,6 +206,10 @@ public class Whiteboard {
         }
     }
 
+    public ServiceReference<JaxrsServiceRuntime> getServiceReference() {
+        return _runtimeReference;
+    }
+
     private OSGi<?> applicationExtensions(
         OSGi<CachingServiceReference<Object>> extensions) {
 
@@ -773,8 +778,8 @@ public class Whiteboard {
             });
     }
 
-    private ServiceRegistration<?> registerJaxRSServiceRuntime(
-        Map<String, Object> properties) {
+    private ServiceRegistration<JaxrsServiceRuntime>
+        registerJaxRSServiceRuntime(Map<String, Object> properties) {
 
         properties.putIfAbsent(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
 
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java
index a7cb1a1..7f20e14 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java
@@ -120,6 +120,17 @@ public class Utils {
         return properties;
     }
 
+    public static Map<String, Object> getProperties(ServiceReference<?> sref) {
+        String[] propertyKeys = sref.getPropertyKeys();
+        Map<String, Object> properties = new HashMap<>(propertyKeys.length);
+
+        for (String key : propertyKeys) {
+            properties.put(key, sref.getProperty(key));
+        }
+
+        return properties;
+    }
+
     public static <T> ResourceProvider getResourceProvider(
         ServiceTuple<T> serviceTuple) {