Correct implementation of error handling If an application that shadows other applications produces an unknown error when it is registered, this application must be kept and signaled as errored and the shadowed applications must be signaled as shadowed.
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/61b35d0c Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/61b35d0c Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/61b35d0c Branch: refs/heads/master Commit: 61b35d0c0b138cf1da23a32567855f61db3cd9b2 Parents: 3bed8f0 Author: Carlos Sierra <[email protected]> Authored: Fri Nov 17 16:52:58 2017 +0100 Committer: Carlos Sierra <[email protected]> Committed: Fri Nov 17 16:52:58 2017 +0100 ---------------------------------------------------------------------- jax-rs.itests/src/main/java/test/JaxrsTest.java | 28 +++--------- .../jax/rs/whiteboard/internal/Whiteboard.java | 46 ++++++++------------ 2 files changed, 24 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/61b35d0c/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 845bf93..f77a60e 100644 --- a/jax-rs.itests/src/main/java/test/JaxrsTest.java +++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java @@ -599,7 +599,6 @@ public class JaxrsTest extends TestHelper { @Test public void testApplicationWithErrorAndHigherRanking() { - RuntimeDTO runtimeDTO = getRuntimeDTO(); assertEquals(0, runtimeDTO.applicationDTOs.length); @@ -625,23 +624,8 @@ public class JaxrsTest extends TestHelper { runtimeDTO = getRuntimeDTO(); - assertEquals(1, runtimeDTO.applicationDTOs.length); - assertEquals(1, runtimeDTO.failedApplicationDTOs.length); - assertEquals( - DTOConstants.FAILURE_REASON_UNKNOWN, - runtimeDTO.failedApplicationDTOs[0].failureReason); - - assertEquals( - applicationRegistration.getReference().getProperty("service.id"), - runtimeDTO.applicationDTOs[0].serviceId); - assertEquals( - erroredRegistration.getReference().getProperty("service.id"), - runtimeDTO.failedApplicationDTOs[0].serviceId); - - WebTarget webTarget = createDefaultTarget().path("/test-application"); - - assertEquals(200, webTarget.request().get().getStatus()); - assertEquals("Hello application ", webTarget.request().get(String.class)); + assertEquals(0, runtimeDTO.applicationDTOs.length); + assertEquals(2, runtimeDTO.failedApplicationDTOs.length); erroredRegistration.unregister(); @@ -649,9 +633,11 @@ public class JaxrsTest extends TestHelper { assertEquals(1, runtimeDTO.applicationDTOs.length); assertEquals(0, runtimeDTO.failedApplicationDTOs.length); - assertEquals( - applicationRegistration.getReference().getProperty("service.id"), - runtimeDTO.applicationDTOs[0].serviceId); + + WebTarget webTarget = createDefaultTarget().path("/test-application"); + + assertEquals(200, webTarget.request().get().getStatus()); + assertEquals("Hello application", webTarget.request().get(String.class)); } @Test http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/61b35d0c/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 a075901..724c838 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 @@ -76,18 +76,17 @@ import static org.apache.aries.jax.rs.whiteboard.internal.Utils.getResourceProvi import static org.apache.aries.jax.rs.whiteboard.internal.Utils.highestPer; import static org.apache.aries.jax.rs.whiteboard.internal.Utils.ignoreResult; import static org.apache.aries.jax.rs.whiteboard.internal.Utils.onlyGettables; -import static org.apache.aries.jax.rs.whiteboard.internal.Utils.highestRanked; import static org.apache.aries.jax.rs.whiteboard.internal.Utils.service; import static org.apache.aries.jax.rs.whiteboard.internal.Utils.serviceObjects; import static org.apache.aries.jax.rs.whiteboard.internal.Utils.updateProperty; import static org.apache.aries.osgi.functional.OSGi.all; -import static org.apache.aries.osgi.functional.OSGi.join; import static org.apache.aries.osgi.functional.OSGi.just; import static org.apache.aries.osgi.functional.OSGi.nothing; import static org.apache.aries.osgi.functional.OSGi.onClose; import static org.apache.aries.osgi.functional.OSGi.once; 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.Utils.highest; 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; @@ -257,7 +256,17 @@ public class Whiteboard { ); return - highestRankedPerPath.flatMap( + highestRankedPerPath.recoverWith( + (t, e) -> + just(t).map( + ServiceTuple::getCachingServiceReference + ).effects( + _runtime::addErroredApplication, + _runtime::removeErroredApplication + ).then( + nothing() + ) + ).flatMap( this::deployApplication ).map( ServiceTuple::getCachingServiceReference @@ -324,7 +333,7 @@ public class Whiteboard { defaultApplication() { return - highestRanked( + highest( serviceReferences( CXFJaxRsServiceRegistrator.class, String.format( @@ -364,32 +373,11 @@ public class Whiteboard { Bus bus, ServiceTuple<Application> tuple, Map<String, Object> props) { return - join(just(() -> { - try { - CXFJaxRsServiceRegistrator registrator = - new CXFJaxRsServiceRegistrator(bus, tuple.getService()); - - return - onClose(registrator::close).then( - register( - CXFJaxRsServiceRegistrator.class, registrator, - props) - ); - } - catch (RuntimeException e) { - CachingServiceReference<Application> serviceReference = - tuple.getCachingServiceReference(); - - _runtime.addErroredApplication(serviceReference); + just(() -> new CXFJaxRsServiceRegistrator(bus, tuple.getService())). + flatMap(registrator -> - return onClose( - () -> - _runtime.removeErroredApplication(serviceReference) - ).then( - nothing() - ); - } - })); + onClose(registrator::close).then( + register(CXFJaxRsServiceRegistrator.class, registrator, props))); } private OSGi<CachingServiceReference<Object>>
