aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csie...@apache.org
Subject [1/8] aries-jax-rs-whiteboard git commit: Refactor to reuse logic and generate DTOs
Date Fri, 25 Aug 2017 15:25:42 GMT
Repository: aries-jax-rs-whiteboard
Updated Branches:
  refs/heads/master 31bf73834 -> 432486ac7


Refactor to reuse logic and generate DTOs


Project: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/repo
Commit: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/commit/216070bb
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/216070bb
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/216070bb

Branch: refs/heads/master
Commit: 216070bb24dc179e406af6c6043218f2259a8265
Parents: 31bf738
Author: Carlos Sierra <csierra@apache.org>
Authored: Tue Aug 22 14:02:40 2017 +0200
Committer: Carlos Sierra <csierra@apache.org>
Committed: Tue Aug 22 14:22:23 2017 +0200

----------------------------------------------------------------------
 jax-rs.itests/itest.bndrun                      |   2 +-
 jax-rs.itests/src/main/java/test/JaxrsTest.java |  25 +-
 .../main/java/test/WhiteboardFactoryTest.java   |   2 -
 .../internal/AriesJaxRSServiceRuntime.java      | 235 +++++++++++++++++--
 .../internal/CXFJaxRsServiceRegistrator.java    |   8 +-
 .../aries/jax/rs/whiteboard/internal/Utils.java | 126 ++++++----
 .../jax/rs/whiteboard/internal/Whiteboard.java  | 102 ++++----
 7 files changed, 374 insertions(+), 126 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/216070bb/jax-rs.itests/itest.bndrun
----------------------------------------------------------------------
diff --git a/jax-rs.itests/itest.bndrun b/jax-rs.itests/itest.bndrun
index c74b820..203616a 100644
--- a/jax-rs.itests/itest.bndrun
+++ b/jax-rs.itests/itest.bndrun
@@ -43,4 +43,4 @@
 	org.osgi.service.http;version='[1.2.1,1.2.2)',\
 	org.osgi.service.http.whiteboard;version='[1.0.0,1.0.1)'
 
-#-runvm: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"
+-runvm: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005"

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/216070bb/jax-rs.itests/src/main/java/test/JaxrsTest.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/JaxrsTest.java b/jax-rs.itests/src/main/java/test/JaxrsTest.java
index 2f1439e..ecf817a 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -188,11 +188,7 @@ public class JaxrsTest extends TestHelper {
 
         ServiceRegistration<?> applicationRegistration = null;
 
-        JaxRSServiceRuntime jaxRSServiceRuntime = getJaxRSServiceRuntime();
-
         try {
-
-
             applicationRegistration = registerApplication(
                 new TestApplication());
 
@@ -306,7 +302,8 @@ public class JaxrsTest extends TestHelper {
             applicationRegistration = registerApplication(
                 new TestApplication());
 
-            filterRegistration = registerFilter(
+            filterRegistration = registerExtension(
+                "filter",
                 JAX_RS_APPLICATION_SELECT,
                 "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");
 
@@ -354,7 +351,8 @@ public class JaxrsTest extends TestHelper {
                 ServiceRegistration<?> filterRegistration = null;
 
                 try {
-                    filterRegistration = registerFilter(
+                    filterRegistration = registerExtension(
+                        "Filter",
                         JAX_RS_APPLICATION_SELECT,
                         "(" + JAX_RS_APPLICATION_BASE + "=/test-application)");
 
@@ -785,8 +783,8 @@ public class JaxrsTest extends TestHelper {
         try {
             serviceRegistration = registerAddon(new TestAddon());
 
-            filterRegistration = registerFilter(
-                JAX_RS_EXTENSION, "test-filter");
+            filterRegistration = registerExtension(
+                "Filter", JAX_RS_EXTENSION, "test-filter");
 
             Response response = webTarget.request().get();
 
@@ -830,8 +828,8 @@ public class JaxrsTest extends TestHelper {
 
                     assertNull(response.getHeaders().getFirst("Filtered"));
 
-                    filterRegistration = registerFilter(
-                        JAX_RS_EXTENSION, "test-filter");
+                    filterRegistration = registerExtension(
+                        "Filter", JAX_RS_EXTENSION, "test-filter");
 
                     response = webTarget.request().get();
 
@@ -955,7 +953,8 @@ public class JaxrsTest extends TestHelper {
 
         Dictionary<String, Object> properties = new Hashtable<>();
 
-        properties.put(JAX_RS_EXTENSION, name);
+        properties.put(JAX_RS_EXTENSION, true);
+        properties.put(JAX_RS_NAME, name);
 
         for (int i = 0; i < keyValues.length; i = i + 2) {
             properties.put(keyValues[i].toString(), keyValues[i + 1]);
@@ -965,7 +964,7 @@ public class JaxrsTest extends TestHelper {
             Object.class, testFilter, properties);
     }
 
-    private ServiceRegistration<?> registerFilter(Object... keyValues) {
+    /*private ServiceRegistration<?> registerFilter(Object... keyValues) {
 
         TestFilter testFilter = new TestFilter();
 
@@ -977,7 +976,7 @@ public class JaxrsTest extends TestHelper {
 
         return bundleContext.registerService(
             Object.class, testFilter, properties);
-    }
+    }*/
 
     private ServiceRegistration<Application> registerUngettableApplication(
         Object... keyValues) {

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/216070bb/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
----------------------------------------------------------------------
diff --git a/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java b/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
index 1534fb9..2c74292 100644
--- a/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
+++ b/jax-rs.itests/src/main/java/test/WhiteboardFactoryTest.java
@@ -22,9 +22,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN;
 import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.JAX_RS_APPLICATION_BASE;
-import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.JAX_RS_RESOURCE;
 
-import java.util.Arrays;
 import java.util.Dictionary;
 import java.util.Hashtable;
 

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/216070bb/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/AriesJaxRSServiceRuntime.java
----------------------------------------------------------------------
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 67166b0..140e82e 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
@@ -17,18 +17,20 @@
 
 package org.apache.aries.jax.rs.whiteboard.internal;
 
-import org.osgi.framework.BundleContext;
 import org.osgi.framework.ServiceReference;
 import org.osgi.service.jaxrs.runtime.JaxRSServiceRuntime;
 import org.osgi.service.jaxrs.runtime.dto.ApplicationDTO;
 import org.osgi.service.jaxrs.runtime.dto.DTOConstants;
+import org.osgi.service.jaxrs.runtime.dto.ExtensionDTO;
 import org.osgi.service.jaxrs.runtime.dto.FailedApplicationDTO;
+import org.osgi.service.jaxrs.runtime.dto.FailedExtensionDTO;
+import org.osgi.service.jaxrs.runtime.dto.FailedResourceDTO;
 import org.osgi.service.jaxrs.runtime.dto.RequestInfoDTO;
+import org.osgi.service.jaxrs.runtime.dto.ResourceDTO;
 import org.osgi.service.jaxrs.runtime.dto.RuntimeDTO;
 import org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants;
 
 import javax.ws.rs.core.Application;
-import java.util.Comparator;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.concurrent.ConcurrentHashMap;
@@ -43,28 +45,57 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
     private ConcurrentHashMap<String, ServiceReference<Application>>
         _applications = new ConcurrentHashMap<>();
 
+    private ConcurrentHashMap<String, Set<ServiceReference<?>>>
+        _applicationEndpoints = new ConcurrentHashMap<>();
+
+    private ConcurrentHashMap<String, Set<ServiceReference<?>>>
+        _applicationExtensions = new ConcurrentHashMap<>();
+
     private TreeSet<ServiceReference<Application>>
-        _ungettableApplications;
+        _ungettableApplications = new TreeSet<>();
 
     private Set<ServiceReference<Application>> _shadowedApplications =
         new TreeSet<>();
 
-    public AriesJaxRSServiceRuntime(BundleContext bundleContext) {
-        _ungettableApplications = new TreeSet<>(Comparator.reverseOrder());
-    }
+    private TreeSet<ServiceReference<?>> _ungettableEndpoints = new TreeSet<>();
+    private TreeSet<ServiceReference<?>> _ungettableExtensions = new TreeSet<>();
 
-    public boolean addNotGettable(
+    public boolean addNotGettableApplication(
         ServiceReference<Application> serviceReference) {
 
         return _ungettableApplications.add(serviceReference);
     }
 
-    public boolean removeNotGettable(
+    public <T> void addNotGettableExtension(
+        ServiceReference<T> serviceReference) {
+
+        _ungettableExtensions.add(serviceReference);
+    }
+
+    public boolean removeNotGettableApplication(
         ServiceReference<Application> serviceReference) {
 
         return _ungettableApplications.remove(serviceReference);
     }
 
+    public <T> boolean removeNotGettableEndpoint(
+        ServiceReference<T> serviceReference) {
+
+        return _ungettableEndpoints.remove(serviceReference);
+    }
+
+    public <T> boolean addNotGettableEndpoint(
+        ServiceReference<T> serviceReference) {
+
+        return _ungettableEndpoints.add(serviceReference);
+    }
+
+    public <T> void removeNotGettableExtension(
+        ServiceReference<T> serviceReference) {
+
+        _ungettableExtensions.remove(serviceReference);
+    }
+
     public ServiceReference<Application> setApplicationForPath(
         String path, ServiceReference<Application> serviceReference) {
 
@@ -87,6 +118,61 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         return _shadowedApplications.remove(serviceReference);
     }
 
+    public void addApplicationEndpoint(
+        String applicationName, ServiceReference<?> endpointServiceReference) {
+
+        _applicationEndpoints.computeIfAbsent(
+            applicationName, __ -> new TreeSet<>());
+
+        _applicationEndpoints.computeIfPresent(
+            applicationName,
+            (__, set) -> {
+                set.add(endpointServiceReference);
+
+                return set;
+            });
+    }
+
+    public void removeApplicationEndpoint(
+        String applicationName, ServiceReference<?> endpointServiceReference) {
+
+        _applicationEndpoints.computeIfPresent(
+            applicationName,
+            (__, set) -> {
+                set.remove(endpointServiceReference);
+
+                return set;
+            });
+    }
+
+    public void addApplicationExtension(
+        String applicationName,
+        ServiceReference<?> extensionServiceReference) {
+
+        _applicationExtensions.computeIfAbsent(
+            applicationName, __ -> new TreeSet<>());
+
+        _applicationExtensions.computeIfPresent(
+            applicationName,
+            (__, set) -> {
+                set.add(extensionServiceReference);
+
+                return set;
+            });
+    }
+
+    public void removeApplicationExtension(
+        String applicationName, ServiceReference<?> extensionServiceReference) {
+
+        _applicationExtensions.computeIfPresent(
+            applicationName,
+            (__, set) -> {
+                set.remove(extensionServiceReference);
+
+                return set;
+            });
+    }
+
     @Override
     public RequestInfoDTO calculateRequestInfoDTO(String path) {
         return null;
@@ -102,23 +188,69 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime
{
             );
 
         runtimeDTO.failedApplicationDTOs = Stream.concat(
-            shadowedApplications(),
-            unreferenciableApplications()
+            shadowedApplicationsDTOStream(),
+            unreferenciableApplicationsDTOStream()
             ).toArray(
                 FailedApplicationDTO[]::new
             );
 
+        runtimeDTO.failedResourceDTOs = unreferenciableEndpointsDTOStream().map(
+            sr -> buildFailedResourceDTO(
+                DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE, sr)
+        ).toArray(
+            FailedResourceDTO[]::new
+        );
+
+        runtimeDTO.failedExtensionDTOs = unreferenciableExtensionsDTOStream().map(
+            sr -> buildFailedExtensionDTO(
+                DTOConstants.FAILURE_REASON_SERVICE_NOT_GETTABLE, sr)
+        ).toArray(
+            FailedExtensionDTO[]::new
+        );
+
         return runtimeDTO;
     }
 
+    private FailedExtensionDTO buildFailedExtensionDTO(
+        int reason, ServiceReference<?> serviceReference) {
+
+        FailedExtensionDTO failedExtensionDTO = new FailedExtensionDTO();
+
+        populateExtensionDTO(failedExtensionDTO, serviceReference);
+
+        failedExtensionDTO.failureReason = reason;
+
+        return failedExtensionDTO;
+    }
+
+    private Stream<ServiceReference<?>> unreferenciableExtensionsDTOStream()
{
+        return _ungettableExtensions.stream();
+    }
+
+    private FailedResourceDTO buildFailedResourceDTO(
+        int reason, ServiceReference<?> serviceReference) {
+
+        FailedResourceDTO failedResourceDTO = new FailedResourceDTO();
+
+        populateResourceDTO(failedResourceDTO, serviceReference);
+
+        failedResourceDTO.failureReason = reason;
+
+        return failedResourceDTO;
+    }
+
+    private Stream<ServiceReference<?>> unreferenciableEndpointsDTOStream() {
+        return _ungettableEndpoints.stream();
+    }
+
     private Stream<ApplicationDTO> applicationDTOStream() {
         return _applications.values().stream().
             map(
-                AriesJaxRSServiceRuntime::buildApplicationDTO
+                this::buildApplicationDTO
             );
     }
 
-    private Stream<FailedApplicationDTO> unreferenciableApplications() {
+    private Stream<FailedApplicationDTO> unreferenciableApplicationsDTOStream() {
         return _ungettableApplications.stream().
             map(
                 sr -> buildFailedApplicationDTO(
@@ -127,7 +259,7 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         );
     }
 
-    private Stream<FailedApplicationDTO> shadowedApplications() {
+    private Stream<FailedApplicationDTO> shadowedApplicationsDTOStream() {
         return _shadowedApplications.stream().
             map(sr -> buildFailedApplicationDTO(
                 DTOConstants.FAILURE_REASON_SHADOWED_BY_OTHER_SERVICE,
@@ -135,16 +267,81 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime
{
         );
     }
 
-    private static ApplicationDTO buildApplicationDTO(
+    private ApplicationDTO buildApplicationDTO(
         ServiceReference<Application> serviceReference) {
 
         ApplicationDTO applicationDTO = new ApplicationDTO(){};
 
         applicationDTO.name = getApplicationName(serviceReference);
+        applicationDTO.base = Whiteboard.getApplicationBase(serviceReference);
+        applicationDTO.serviceId = (Long)serviceReference.getProperty(
+            "service.id");
+
+        applicationDTO.resourceDTOs = getApplicationEndpointsStream(
+            applicationDTO.name).toArray(
+                ResourceDTO[]::new
+            );
+
+        applicationDTO.extensionDTOs = getApplicationExtensionsStream(
+            applicationDTO.name).toArray(
+                ExtensionDTO[]::new
+            );
 
         return applicationDTO;
     }
 
+    private Stream<ResourceDTO> getApplicationEndpointsStream(String name) {
+
+        Set<ServiceReference<?>> applicationEndpoints =
+            _applicationEndpoints.get(name);
+
+        Stream<ServiceReference<?>> applicationEndpointStream =
+            applicationEndpoints != null ?
+                applicationEndpoints.stream() :
+                Stream.empty();
+
+        return
+            applicationEndpointStream.map(
+                sr -> populateResourceDTO(new ResourceDTO(){}, sr)
+            );
+    }
+
+    private Stream<ExtensionDTO> getApplicationExtensionsStream(String name) {
+
+        Set<ServiceReference<?>> applicationExtensions =
+            _applicationEndpoints.get(name);
+
+        Stream<ServiceReference<?>> applicationExtensionStream =
+            applicationExtensions != null ?
+                applicationExtensions.stream() :
+                Stream.empty();
+
+        return
+            applicationExtensionStream.map(
+                sr -> populateExtensionDTO(new ExtensionDTO(){}, sr)
+            );
+    }
+
+    private static ResourceDTO populateResourceDTO(
+        ResourceDTO resourceDTO, ServiceReference<?> serviceReference) {
+
+        resourceDTO.name = serviceReference.getProperty(JAX_RS_NAME).toString();
+        resourceDTO.serviceId = (Long)serviceReference.getProperty(
+            "service.id");
+
+        return resourceDTO;
+    }
+
+    private static ExtensionDTO populateExtensionDTO(
+        ExtensionDTO extensionDTO, ServiceReference<?> serviceReference) {
+
+        extensionDTO.name = serviceReference.getProperty(JAX_RS_NAME).toString();
+        extensionDTO.serviceId = (Long)serviceReference.getProperty(
+            "service.id");
+
+        return extensionDTO;
+    }
+
     private static FailedApplicationDTO buildFailedApplicationDTO(
         int reason, ServiceReference<Application> serviceReference) {
 
@@ -162,8 +359,8 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         return failedApplicationDTO;
     }
 
-    private static String getApplicationName(
-        ServiceReference<Application> serviceReference) {
+    public static String getApplicationName(
+        ServiceReference<?> serviceReference) {
 
         Object property = serviceReference.getProperty(JAX_RS_NAME);
 
@@ -174,10 +371,10 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime
{
         return property.toString();
     }
 
-    private static String generateApplicationName(
-        ServiceReference<Application> serviceReference) {
+    public static String generateApplicationName(
+        ServiceReference<?> serviceReference) {
 
-        return "jax-rs-application-" +
+        return ".jax-rs-application-" +
             serviceReference.getProperty("service.id").toString();
     }
 

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/216070bb/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
index 91c70f8..a43abba 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java
@@ -80,12 +80,12 @@ public class CXFJaxRsServiceRegistrator {
         rewire();
     }
 
-    public void addProvider(Object provider) {
+    public void addProvider(Utils.ServiceTuple<?> tuple) {
         if (_closed) {
             return;
         }
 
-        _providers.add(provider);
+        _providers.add(tuple.getService());
 
         rewire();
     }
@@ -112,12 +112,12 @@ public class CXFJaxRsServiceRegistrator {
         rewire();
     }
 
-    public void removeProvider(Object provider) {
+    public void removeProvider(Utils.ServiceTuple<?> tuple) {
         if (_closed) {
             return;
         }
 
-        _providers.remove(provider);
+        _providers.remove(tuple.getService());
 
         rewire();
     }

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/216070bb/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
----------------------------------------------------------------------
diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
index 69310a4..0a343bf 100644
--- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
+++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Utils.java
@@ -27,7 +27,6 @@ import org.osgi.framework.ServiceReference;
 import org.osgi.service.jaxrs.runtime.dto.FailedApplicationDTO;
 
 import javax.ws.rs.core.Application;
-import javax.ws.rs.ext.Provider;
 import java.util.Comparator;
 import java.util.Map;
 import java.util.NavigableSet;
@@ -85,43 +84,79 @@ public class Utils {
 
     public static OSGi<?> safeRegisterGeneric(
         ServiceReference<?> serviceReference,
-        CXFJaxRsServiceRegistrator registrator) {
-
-        return bundleContext().flatMap(bundleContext -> {
-            Object service = bundleContext.getService(serviceReference);
-            Class<?> serviceClass = service.getClass();
-            bundleContext.ungetService(serviceReference);
-            if (serviceClass.isAnnotationPresent(Provider.class)) {
-                return safeRegisterExtension(serviceReference, registrator);
-            }
-            else {
-                return safeRegisterEndpoint(serviceReference, registrator);
-            }
-        });
+        String applicationName,
+        CXFJaxRsServiceRegistrator registrator,
+        AriesJaxRSServiceRuntime runtime) {
+
+        if (isExtension(serviceReference)) {
+            return safeRegisterExtension(
+                serviceReference, applicationName, registrator, runtime);
+        }
+        else {
+            return safeRegisterEndpoint(
+                serviceReference, applicationName, registrator, runtime);
+        }
+    }
+
+    private static boolean isExtension(ServiceReference<?> serviceReference) {
+        Object extensionProperty = serviceReference.getProperty(
+            "osgi.jaxrs.extension");
+
+        return
+            (extensionProperty != null) &&
+            (extensionProperty instanceof Boolean) &&
+            ((boolean) extensionProperty);
     }
 
     public static OSGi<?> safeRegisterExtension(
         ServiceReference<?> serviceReference,
-        CXFJaxRsServiceRegistrator registrator) {
+        String applicationName, CXFJaxRsServiceRegistrator registrator,
+        AriesJaxRSServiceRuntime runtime) {
 
         return
-            service(serviceReference).flatMap(extension ->
-            onClose(() -> registrator.removeProvider(extension)).
-                foreach(ign ->
-            registrator.addProvider(extension)
-        ));
+            onlyGettables(
+                just(serviceReference),
+                runtime::addNotGettableExtension,
+                runtime::removeNotGettableExtension
+            ).foreach(
+                registrator::addProvider,
+                registrator::removeProvider
+            ).foreach(
+                __ -> runtime.addApplicationExtension(
+                    applicationName, serviceReference),
+                __ -> runtime.removeApplicationExtension(
+                    applicationName, serviceReference)
+            );
     }
 
     public static <T> OSGi<?> safeRegisterEndpoint(
-        ServiceReference<T> ref, CXFJaxRsServiceRegistrator registrator) {
+        ServiceReference<T> serviceReference,
+        String applicationName,
+        CXFJaxRsServiceRegistrator registrator,
+        AriesJaxRSServiceRuntime runtime) {
 
         return
-            bundleContext().flatMap(bundleContext ->
-            serviceObjects(ref).flatMap(service ->
-            registerEndpoint(ref, registrator, service).
-                flatMap(serviceInformation ->
-            onClose(() ->
-                unregisterEndpoint(registrator, serviceInformation)))));
+            onlyGettables(
+                just(serviceReference),
+                runtime::addNotGettableEndpoint,
+                runtime::removeNotGettableEndpoint
+            ).flatMap(
+                tuple -> serviceObjects(serviceReference).flatMap(
+                    serviceObjects -> registerEndpoint(
+                        registrator, serviceObjects).flatMap(
+                            resourceProvider ->
+                                onClose(
+                                    () -> unregisterEndpoint(
+                                        registrator, resourceProvider)
+                                )
+                    )
+                )
+            ).foreach(
+                __ -> runtime.addApplicationEndpoint(
+                    applicationName, serviceReference),
+                __ -> runtime.removeApplicationEndpoint(
+                    applicationName, serviceReference)
+            );
     }
 
     public static <T extends Comparable<? super T>> OSGi<T> repeatInOrder(
@@ -130,14 +165,15 @@ public class Utils {
         return program.route(new RepeatInOrderRouter<>());
     }
 
-    public static <T> OSGi<MutableTuple<T>> onlyGettables(
-        ServiceReference<T> serviceReference,
+    public static <T> OSGi<ServiceTuple<T>> onlyGettables(
+        OSGi<ServiceReference<T>> program,
         Consumer<ServiceReference<T>> whenAddedNotGettable,
         Consumer<ServiceReference<T>> whenLeavingNotGettable) {
 
-        return bundleContext().flatMap(
-            bundleContext -> {
+        return bundleContext().flatMap(bundleContext ->
+            program.flatMap(serviceReference -> {
                 T service = null;
+
                 try {
                     service = bundleContext.getService(serviceReference);
                 }
@@ -148,7 +184,8 @@ public class Utils {
 
                     return
                         onClose(
-                            () -> whenLeavingNotGettable.accept(serviceReference)
+                            () -> whenLeavingNotGettable.accept(
+                                serviceReference)
                         ).then(
                             nothing()
                         );
@@ -157,15 +194,14 @@ public class Utils {
                     onClose(
                         () -> bundleContext.ungetService(serviceReference)
                     ).then(
-                        just(new MutableTuple<>(serviceReference, service)))
-                    ;
+                        just(new ServiceTuple<>(serviceReference, service))
+                    );
             }
-        );
+        ));
     }
 
     public static <T> OSGi<ResourceProvider>
         registerEndpoint(
-            ServiceReference<?> serviceReference,
             CXFJaxRsServiceRegistrator registrator,
             ServiceObjects<T> serviceObjects) {
 
@@ -353,18 +389,18 @@ public class Utils {
 
     }
 
-    public static class MutableTuple<T> implements Comparable<MutableTuple<T>>
{
+    public static class ServiceTuple<T> implements Comparable<ServiceTuple<T>>
{
 
         private final ServiceReference<T> _serviceReference;
-        private T _service;
+        private final T _service;
 
-        public MutableTuple(ServiceReference<T> a, T service) {
+        public ServiceTuple(ServiceReference<T> a, T service) {
             _serviceReference = a;
             _service = service;
         }
 
         @Override
-        public int compareTo(MutableTuple<T> o) {
+        public int compareTo(ServiceTuple<T> o) {
             return _serviceReference.compareTo(o._serviceReference);
         }
 
@@ -373,7 +409,7 @@ public class Utils {
             if (this == o) return true;
             if (o == null || getClass() != o.getClass()) return false;
 
-            MutableTuple<?> that = (MutableTuple<?>) o;
+            ServiceTuple<?> that = (ServiceTuple<?>) o;
 
             return _serviceReference.equals(that._serviceReference);
         }
@@ -387,13 +423,9 @@ public class Utils {
             return _serviceReference;
         }
 
-        public T getSecond() {
+        public T getService() {
             return _service;
         }
-
-        public void setService(T service) {
-            _service = service;
-        }
-
     }
+
 }

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/216070bb/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/Whiteboard.java
----------------------------------------------------------------------
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 99980bb..cb2c078 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
@@ -17,7 +17,7 @@
 
 package org.apache.aries.jax.rs.whiteboard.internal;
 
-import org.apache.aries.jax.rs.whiteboard.internal.Utils.MutableTuple;
+import org.apache.aries.jax.rs.whiteboard.internal.Utils.ServiceTuple;
 import org.apache.aries.osgi.functional.OSGi;
 import org.apache.cxf.Bus;
 import org.apache.cxf.bus.extension.ExtensionManagerBus;
@@ -50,12 +50,12 @@ import static org.apache.aries.jax.rs.whiteboard.internal.Utils.onlyGettables;
 import static org.apache.aries.jax.rs.whiteboard.internal.Utils.safeRegisterEndpoint;
 import static org.apache.aries.jax.rs.whiteboard.internal.Utils.safeRegisterExtension;
 import static org.apache.aries.jax.rs.whiteboard.internal.Utils.safeRegisterGeneric;
+import static org.apache.aries.jax.rs.whiteboard.internal.Utils.service;
 import static org.apache.aries.osgi.functional.OSGi.all;
 import static org.apache.aries.osgi.functional.OSGi.bundleContext;
 import static org.apache.aries.osgi.functional.OSGi.just;
 import static org.apache.aries.osgi.functional.OSGi.register;
 import static org.apache.aries.osgi.functional.OSGi.serviceReferences;
-import static org.apache.aries.osgi.functional.OSGi.services;
 import static org.osgi.service.http.runtime.HttpServiceRuntimeConstants.HTTP_SERVICE_ENDPOINT;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_NAME;
 import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHITEBOARD_CONTEXT_SELECT;
@@ -75,24 +75,25 @@ import static org.osgi.service.jaxrs.whiteboard.JaxRSWhiteboardConstants.JAX_RS_
  */
 public class Whiteboard {
 
-    public static final Function<MutableTuple<Application>, String> APPLICATION_BASE
= ((Function<MutableTuple<Application>, ServiceReference<Application>>)
Utils.MutableTuple::getServiceReference).andThen(Whiteboard::getApplicationBase);
+    public static final Function<ServiceTuple<Application>, String> APPLICATION_BASE
= ((Function<ServiceTuple<Application>, ServiceReference<Application>>)
ServiceTuple::getServiceReference).andThen(Whiteboard::getApplicationBase);
 
     public static OSGi<Void> createWhiteboard(Dictionary<String, ?> configuration)
{
+        AriesJaxRSServiceRuntime runtime = new AriesJaxRSServiceRuntime();
 
+        Map<String, ?> configurationMap = Maps.from(configuration);
 
         return
             bundleContext().flatMap(bundleContext ->
-            just(new AriesJaxRSServiceRuntime(bundleContext)).flatMap(runtime ->
-            registerJaxRSServiceRuntime(runtime, bundleContext, Maps.from(configuration)).flatMap(runtimeResgistration
->
-            createDefaultJaxRsServiceRegistrator(Maps.from(configuration)).flatMap(defaultServiceRegistrator
->
+            registerJaxRSServiceRuntime(runtime, bundleContext, configurationMap).flatMap(runtimeResgistration
->
+            createDefaultJaxRsServiceRegistrator(configurationMap).flatMap(defaultServiceRegistrator
->
             just(new ServiceRegistrationChangeCounter(runtimeResgistration)).flatMap(counter
->
             just(runtimeResgistration.getReference()).flatMap(runtimeRegistration ->
                 all(
                     countChanges(whiteboardApplications(runtimeRegistration, runtime, Maps.from(configuration)),
counter),
-                    countChanges(whiteBoardApplicationSingletons(runtimeRegistration), counter),
-                    countChanges(whiteboardExtensions(runtimeRegistration, defaultServiceRegistrator),
counter),
-                    countChanges(whiteboardSingletons(runtimeRegistration, defaultServiceRegistrator),
counter)
-            )))))));
+                    countChanges(whiteBoardApplicationSingletons(runtimeRegistration, runtime),
counter),
+                    countChanges(whiteboardExtensions(runtimeRegistration, defaultServiceRegistrator,
runtime), counter),
+                    countChanges(whiteboardSingletons(runtimeRegistration, defaultServiceRegistrator,
runtime), counter)
+            ))))));
     }
 
     private static OSGi<Collection<String>> bestEffortCalculationOfEnpoints(Filter
filter) {
@@ -125,23 +126,28 @@ public class Whiteboard {
         return new String[]{propertyValue.toString()};
     }
 
-    private static ExtensionManagerBus createBus(BundleContext bundleContext, Map<String,
?> configuration) {
-        BundleWiring wiring = bundleContext.getBundle().adapt(BundleWiring.class);
+    private static ExtensionManagerBus createBus(
+        BundleContext bundleContext, Map<String, ?> configuration) {
+
+        BundleWiring wiring = bundleContext.getBundle().adapt(
+            BundleWiring.class);
 
         @SuppressWarnings("unchecked")
         Map<String, Object> properties = (Map<String, Object>)configuration;
 
-        properties.put("org.apache.cxf.bus.id", configuration.get(Constants.SERVICE_PID));
+        properties.put("org.apache.cxf.bus.id", configuration.get(
+            Constants.SERVICE_PID));
 
-        ExtensionManagerBus bus = new ExtensionManagerBus(null, properties, wiring.getClassLoader());
+        ExtensionManagerBus bus = new ExtensionManagerBus(
+            null, properties, wiring.getClassLoader());
 
         bus.initialize();
 
         return bus;
     }
 
-    private static OSGi<CXFJaxRsServiceRegistrator> createDefaultJaxRsServiceRegistrator(
-        Map<String, ?> configuration) {
+    private static OSGi<CXFJaxRsServiceRegistrator>
+        createDefaultJaxRsServiceRegistrator(Map<String, ?> configuration) {
 
         Map<String, Object> properties = new HashMap<>(configuration);
         properties.put(JAX_RS_NAME, ".default");
@@ -177,7 +183,7 @@ public class Whiteboard {
         properties.putIfAbsent(
             HTTP_WHITEBOARD_TARGET, "(osgi.http.endpoint=*)");
 
-        properties.put(Constants.SERVICE_RANKING, -1);
+        properties.putIfAbsent(Constants.SERVICE_RANKING, -1);
 
         String targetFilter = (String)properties.get(HTTP_WHITEBOARD_TARGET);
 
@@ -218,17 +224,25 @@ public class Whiteboard {
         return program;
     }
 
-    private static OSGi<?> whiteBoardApplicationSingletons(ServiceReference<?>
jaxRsRuntimeServiceReference) {
+    private static OSGi<?> whiteBoardApplicationSingletons(
+        ServiceReference<?> jaxRsRuntimeServiceReference,
+        AriesJaxRSServiceRuntime runtime) {
         return
             serviceReferences(format("(%s=*)", JAX_RS_APPLICATION_SELECT)).
                 filter(new TargetFilter<>(jaxRsRuntimeServiceReference)).
                 flatMap(ref ->
             just(ref.getProperty(JAX_RS_APPLICATION_SELECT).toString()).
                 flatMap(applicationFilter ->
-            services(CXFJaxRsServiceRegistrator.class, applicationFilter).
-                flatMap(registrator ->
-            safeRegisterGeneric(ref, registrator)
-        )));
+            serviceReferences(
+                CXFJaxRsServiceRegistrator.class, applicationFilter).
+                flatMap(registratorReference ->
+            just(
+                AriesJaxRSServiceRuntime.getApplicationName(registratorReference)).
+                flatMap(applicationName ->
+            waitForExtensionDependencies(ref,
+                service(registratorReference).flatMap(registrator ->
+                safeRegisterGeneric(ref, applicationName, registrator, runtime)
+        ))))));
     }
 
     private static OSGi<?> whiteboardApplications(
@@ -236,15 +250,14 @@ public class Whiteboard {
         AriesJaxRSServiceRuntime runtime,
         Map<String, ?> configuration) {
 
-        OSGi<MutableTuple<Application>> gettableAplicationForWhiteboard =
-            getApplicationsForWhiteboard(jaxRsRuntimeServiceReference).flatMap(
-                sr -> onlyGettables(
-                    sr, runtime::addNotGettable, runtime::removeNotGettable)
-            );
+        OSGi<ServiceTuple<Application>> gettableAplicationForWhiteboard =
+            onlyGettables(
+                getApplicationsForWhiteboard(jaxRsRuntimeServiceReference),
+                runtime::addNotGettableApplication,
+                runtime::removeNotGettableApplication);
 
-        OSGi<MutableTuple<Application>> highestRankedPerPath = highestPer(
-            APPLICATION_BASE,
-            gettableAplicationForWhiteboard,
+        OSGi<ServiceTuple<Application>> highestRankedPerPath = highestPer(
+            APPLICATION_BASE, gettableAplicationForWhiteboard,
             t -> runtime.addShadowedApplication(t.getServiceReference()),
             t -> runtime.removeShadowedApplication(t.getServiceReference())
         );
@@ -254,7 +267,7 @@ public class Whiteboard {
                 bundleContext -> highestRankedPerPath.flatMap(
                     ref -> deployApplication(configuration, bundleContext, ref)
                 ).map(
-                    MutableTuple::getServiceReference).
+                    ServiceTuple::getServiceReference).
                 foreach(
                     sr -> runtime.setApplicationForPath(
                             getApplicationBase(sr), sr),
@@ -264,9 +277,9 @@ public class Whiteboard {
             );
     }
 
-    private static OSGi<MutableTuple<Application>> deployApplication(
+    private static OSGi<ServiceTuple<Application>> deployApplication(
         Map<String, ?> configuration, BundleContext bundleContext,
-        MutableTuple<Application> tuple) {
+        ServiceTuple<Application> tuple) {
 
         ExtensionManagerBus bus = createBus(bundleContext, configuration);
 
@@ -277,12 +290,16 @@ public class Whiteboard {
             CXFJaxRsServiceRegistrator.getProperties(
                 serviceReference, JAX_RS_APPLICATION_BASE);
 
+        properties.computeIfAbsent(
+            JAX_RS_NAME,
+            (__) -> AriesJaxRSServiceRuntime.generateApplicationName(
+                tuple.getServiceReference()));
+
         return
             all(
-                deployRegistrator(bus, tuple.getSecond(), properties),
+                deployRegistrator(bus, tuple.getService(), properties),
                 registerCXFServletService(
-                    bus, getApplicationBase(serviceReference),
-                    properties)).
+                    bus, getApplicationBase(serviceReference), properties)).
             then(
                 just(tuple)
             );
@@ -301,20 +318,24 @@ public class Whiteboard {
 
     private static OSGi<?> whiteboardExtensions(
         ServiceReference<?> jaxRsRuntimeServiceReference,
-        CXFJaxRsServiceRegistrator defaultServiceRegistrator) {
+        CXFJaxRsServiceRegistrator defaultServiceRegistrator,
+        AriesJaxRSServiceRuntime runtime) {
 
         return
             serviceReferences(getExtensionFilter()).
                 filter(new TargetFilter<>(jaxRsRuntimeServiceReference)).
                 flatMap(ref ->
             waitForExtensionDependencies(ref,
-                safeRegisterExtension(ref, defaultServiceRegistrator)
+                safeRegisterExtension(
+                    ref, ".default", defaultServiceRegistrator, runtime)
             )
         );
     }
 
     private static OSGi<?> whiteboardSingletons(
-        ServiceReference<?> jaxRsRuntimeServiceReference, CXFJaxRsServiceRegistrator
defaultServiceRegistrator) {
+        ServiceReference<?> jaxRsRuntimeServiceReference,
+        CXFJaxRsServiceRegistrator defaultServiceRegistrator,
+        AriesJaxRSServiceRuntime runtime) {
 
         return
             serviceReferences(getSingletonsFilter()).
@@ -322,7 +343,8 @@ public class Whiteboard {
                 flatMap(serviceReference ->
             waitForExtensionDependencies(serviceReference,
                 safeRegisterEndpoint(
-                    serviceReference, defaultServiceRegistrator)
+                    serviceReference, ".default", defaultServiceRegistrator,
+                    runtime)
             )
         );
     }


Mime
View raw message