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 2017/11/06 14:03:31 UTC

[1/3] aries-jax-rs-whiteboard git commit: Do not register JSONProvider by default

Repository: aries-jax-rs-whiteboard
Updated Branches:
  refs/heads/master ec4e46977 -> b8248259c


Do not register JSONProvider by default


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/d3d92a7d
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/d3d92a7d
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/d3d92a7d

Branch: refs/heads/master
Commit: d3d92a7d415034f14e976632051dc8a3aa02ae25
Parents: ec4e469
Author: Carlos Sierra <cs...@apache.org>
Authored: Sat Nov 4 13:34:04 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Sat Nov 4 13:34:04 2017 +0100

----------------------------------------------------------------------
 .../rs/whiteboard/internal/CXFJaxRsServiceRegistrator.java   | 8 --------
 1 file changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/d3d92a7d/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 7218a5c..75c7a1e 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
@@ -210,14 +210,6 @@ public class CXFJaxRsServiceRegistrator {
 
         jaxRsServerFactoryBean.setBus(_bus);
 
-        JSONProvider<Object> jsonProvider = new JSONProvider<>();
-
-        jsonProvider.setDropCollectionWrapperElement(true);
-        jsonProvider.setDropRootElement(true);
-        jsonProvider.setSerializeAsArray(true);
-        jsonProvider.setSupportUnwrapped(true);
-
-        jaxRsServerFactoryBean.setProvider(jsonProvider);
         jaxRsServerFactoryBean.setProvider(
             (Feature) featureContext -> {
                 for (ServiceTuple<?> provider : _providers) {


[3/3] aries-jax-rs-whiteboard git commit: Keep track of application dependent services

Posted by cs...@apache.org.
Keep track of application dependent services


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/b8248259
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/b8248259
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/b8248259

Branch: refs/heads/master
Commit: b8248259c028ea63555aa50399477ee6c4264a44
Parents: 57c5985
Author: Carlos Sierra <cs...@apache.org>
Authored: Mon Nov 6 14:59:04 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Nov 6 14:59:04 2017 +0100

----------------------------------------------------------------------
 .../internal/AriesJaxRSServiceRuntime.java      | 60 +++++++++++++++++---
 .../jax/rs/whiteboard/internal/Whiteboard.java  | 20 +++++--
 2 files changed, 69 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b8248259/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 7d53b21..be3fa1a 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
@@ -67,6 +67,10 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         new CopyOnWriteArrayList<>();
     private Set<CachingServiceReference<Application>> _dependentApplications =
         ConcurrentHashMap.newKeySet();
+    private Set<CachingServiceReference<?>> _applicationDependentExtensions =
+        ConcurrentHashMap.newKeySet();
+    private Set<CachingServiceReference<?>> _applicationDependentResources =
+        ConcurrentHashMap.newKeySet();
     private Collection<CachingServiceReference<Application>> _clashingApplications =
         new CopyOnWriteArrayList<>();
     private Collection<CachingServiceReference<Application>> _erroredApplications =
@@ -83,6 +87,18 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         new CopyOnWriteArrayList<>();
     private volatile Map<String, Object> _defaultApplicationProperties;
 
+    public void addApplicationDependentExtension(
+        CachingServiceReference<?> cachingServiceReference) {
+
+        _applicationDependentExtensions.add(cachingServiceReference);
+    }
+
+    public void addApplicationDependentResource(
+        CachingServiceReference<?> cachingServiceReference) {
+
+        _applicationDependentResources.add(cachingServiceReference);
+    }
+
     public void addApplicationEndpoint(
         String applicationName, CachingServiceReference<?> endpointImmutableServiceReference) {
 
@@ -214,14 +230,18 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
                 unreferenciableEndpointsDTOStream(),
                 Stream.concat(
                     dependentServiceStreamDTO(),
-                    erroredEndpointsStreamDTO())
+                    Stream.concat(
+                        applicationDependentResourcesDTOStream(),
+                        erroredEndpointsStreamDTO()))
             ).toArray(
                 FailedResourceDTO[]::new
             );
 
         runtimeDTO.failedExtensionDTOs = Stream.concat(
                 unreferenciableExtensionsDTOStream(),
-                invalidExtensionsDTOStream()
+                Stream.concat(
+                    applicationDependentExtensionsDTOStream(),
+                    invalidExtensionsDTOStream())
             ).toArray(
                 FailedExtensionDTO[]::new
             );
@@ -229,11 +249,16 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         return runtimeDTO;
     }
 
-    private Stream<FailedResourceDTO> erroredEndpointsStreamDTO() {
-        return _erroredEndpoints.stream().map(
-            sr -> buildFailedResourceDTO(
-                DTOConstants.FAILURE_REASON_UNKNOWN, sr)
-        );
+    public void removeApplicationDependentExtension(
+        CachingServiceReference<?> cachingServiceReference) {
+
+        _applicationDependentExtensions.remove(cachingServiceReference);
+    }
+
+    public void removeApplicationDependentResource(
+        CachingServiceReference<?> cachingServiceReference) {
+
+        _applicationDependentResources.remove(cachingServiceReference);
     }
 
     public void removeApplicationEndpoint(
@@ -404,6 +429,13 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         );
     }
 
+    private Stream<FailedResourceDTO> erroredEndpointsStreamDTO() {
+        return _erroredEndpoints.stream().map(
+            sr -> buildFailedResourceDTO(
+                DTOConstants.FAILURE_REASON_UNKNOWN, sr)
+        );
+    }
+
     private Stream<ResourceDTO> getApplicationEndpointsStream(String name) {
         Collection<CachingServiceReference<?>> applicationEndpoints =
             _applicationEndpoints.get(name);
@@ -441,6 +473,20 @@ public class AriesJaxRSServiceRuntime implements JaxRSServiceRuntime {
         );
     }
 
+    private Stream<FailedExtensionDTO> applicationDependentExtensionsDTOStream() {
+        return _applicationDependentExtensions.stream().map(
+            sr -> buildFailedExtensionDTO(
+                DTOConstants.FAILURE_REASON_REQUIRED_APPLICATION_UNAVAILABLE, sr)
+        );
+    }
+
+    private Stream<FailedResourceDTO> applicationDependentResourcesDTOStream() {
+        return _applicationDependentResources.stream().map(
+            sr -> buildFailedResourceDTO(
+                DTOConstants.FAILURE_REASON_REQUIRED_APPLICATION_UNAVAILABLE, sr)
+        );
+    }
+
     private Stream<FailedApplicationDTO> shadowedApplicationsDTOStream() {
         return _shadowedApplications.stream().
             map(sr -> buildFailedApplicationDTO(

http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/b8248259/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 411d60e..7d43068 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
@@ -239,7 +239,9 @@ public class Whiteboard {
                     _runtime::removeInvalidExtension).
                 flatMap(resourceReference ->
             chooseApplication(
-                    resourceReference, Whiteboard::allApplicationReferences).
+                    resourceReference, Whiteboard::allApplicationReferences,
+                    _runtime::addApplicationDependentExtension,
+                    _runtime::removeApplicationDependentExtension).
                 flatMap(registratorReference ->
             waitForExtensionDependencies(
                 resourceReference,
@@ -252,7 +254,10 @@ public class Whiteboard {
         return
             countChanges(getResourcesForWhiteboard(), _counter).
                 flatMap(resourceReference ->
-            chooseApplication(resourceReference, this::defaultApplication).
+            chooseApplication(
+                resourceReference, this::defaultApplication,
+                _runtime::addApplicationDependentResource,
+                _runtime::removeApplicationDependentResource).
                 flatMap(registratorReference ->
             waitForExtensionDependencies(
                 resourceReference,
@@ -715,7 +720,9 @@ public class Whiteboard {
         chooseApplication(
             CachingServiceReference<?> serviceReference,
             Supplier<OSGi<CachingServiceReference<CXFJaxRsServiceRegistrator>>>
-                theDefault) {
+                theDefault,
+            Consumer<CachingServiceReference<?>> onWaiting,
+            Consumer<CachingServiceReference<?>> onResolved) {
 
         Object applicationSelectProperty = serviceReference.getProperty(
             JAX_RS_APPLICATION_SELECT);
@@ -725,9 +732,14 @@ public class Whiteboard {
         }
 
         return
+            just(0).
+            effects(
+                __ -> onWaiting.accept(serviceReference),
+                __ -> onResolved.accept(serviceReference)).then(
             serviceReferences(
                 CXFJaxRsServiceRegistrator.class,
-                applicationSelectProperty.toString());
+                applicationSelectProperty.toString()).
+            effects(__ -> onResolved.accept(serviceReference), __ -> {}));
     }
 
     private static <T> OSGi<T> countChanges(


[2/3] aries-jax-rs-whiteboard git commit: Check earlier if application throws error

Posted by cs...@apache.org.
Check earlier if application throws error

If an application produces an error it is not eligible to shadow other
applications either by name or by path.

The current approach creates the application twice, first to check if
the application is healthy and, if the application is eligible for
registration, it is finally registered.

This approach is needed because it is not possible to create a bus for
the application, register the bus in a servlet and later unregister the
servlet. When the servlet is destroyed the bus is also destroyed.

Also it is not trivial for me to perform the shadowing checks and, if the
application errors, redo the checks and keep the program reusable and
untangled.


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/57c5985a
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/57c5985a
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/57c5985a

Branch: refs/heads/master
Commit: 57c5985a65d93e8d66285fc4d05d52d2cfc58c19
Parents: d3d92a7
Author: Carlos Sierra <cs...@apache.org>
Authored: Mon Nov 6 14:41:49 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Nov 6 14:41:49 2017 +0100

----------------------------------------------------------------------
 .../jax/rs/whiteboard/internal/Whiteboard.java  | 64 ++++++++++++--------
 1 file changed, 39 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/57c5985a/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 c107941..411d60e 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
@@ -179,6 +179,38 @@ public class Whiteboard {
         return new Whiteboard(bundleContext, configuration);
     }
 
+    private OSGi<ServiceTuple<Application>> filterErroringApplications(
+        OSGi<ServiceTuple<Application>> program) {
+
+        return program.flatMap(tuple -> {
+            ExtensionManagerBus bus = createBus();
+
+            try {
+                CXFJaxRsServiceRegistrator registrator =
+                    new CXFJaxRsServiceRegistrator(bus, tuple.getService());
+
+                registrator.close();
+                bus.shutdown();
+
+                return just(tuple);
+            }
+            catch (Exception e) {
+                CachingServiceReference<Application> serviceReference =
+                    tuple.getCachingServiceReference();
+
+                _runtime.addErroredApplication(serviceReference);
+
+                return onClose(
+                    () ->
+                        _runtime.removeErroredApplication(serviceReference)
+                ).then(
+                    nothing()
+                );
+            }
+        });
+
+    }
+
     public void start() {
         _osgiResult = _program.run(_bundleContext);
     }
@@ -239,6 +271,9 @@ public class Whiteboard {
                 _runtime::addNotGettableApplication,
                 _runtime::removeNotGettableApplication);
 
+        gettableAplicationForWhiteboard = filterErroringApplications(
+            gettableAplicationForWhiteboard);
+
         OSGi<ServiceTuple<Application>> highestRankedPerName = highestPer(
             APPLICATION_NAME, gettableAplicationForWhiteboard,
             t -> _runtime.addClashingApplication(t.getCachingServiceReference()),
@@ -359,32 +394,11 @@ public class Whiteboard {
         Bus bus, ServiceTuple<Application> tuple, Map<String, Object> props) {
 
         return
-            join(just(() -> {
-                try {
-                    CXFJaxRsServiceRegistrator registrator =
-                        new CXFJaxRsServiceRegistrator(bus, tuple.getService());
+            just(() -> new CXFJaxRsServiceRegistrator(bus, tuple.getService())).
+                flatMap(registrator ->
 
-                    return
-                        onClose(registrator::close).then(
-                            register(
-                                CXFJaxRsServiceRegistrator.class, registrator,
-                                props)
-                        );
-                }
-                catch (RuntimeException e) {
-                    CachingServiceReference<Application> serviceReference =
-                        tuple.getCachingServiceReference();
-
-                    _runtime.addErroredApplication(serviceReference);
-
-                    return onClose(
-                        () ->
-                            _runtime.removeErroredApplication(serviceReference)
-                    ).then(
-                        nothing()
-                    );
-                }
-            }));
+            onClose(registrator::close).then(
+            register(CXFJaxRsServiceRegistrator.class, registrator, props)));
     }
 
     private OSGi<CachingServiceReference<Object>>