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/12/07 11:50:37 UTC
[1/4] aries-jax-rs-whiteboard git commit: Always use ServiceObjects
to honor scope
Repository: aries-jax-rs-whiteboard
Updated Branches:
refs/heads/master bab1ff399 -> 4b959b585
Always use ServiceObjects to honor scope
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/5cb59cac
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/5cb59cac
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/5cb59cac
Branch: refs/heads/master
Commit: 5cb59cac93a88a4bbe6bfe2cd4f9f6777339220d
Parents: bab1ff3
Author: Carlos Sierra <cs...@apache.org>
Authored: Tue Dec 5 16:34:57 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Thu Dec 7 11:52:27 2017 +0100
----------------------------------------------------------------------
.../aries/jax/rs/whiteboard/internal/Utils.java | 60 +++++++++++++-------
.../jax/rs/whiteboard/internal/Whiteboard.java | 7 +--
2 files changed, 44 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5cb59cac/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 624310c..745abb1 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
@@ -134,34 +134,46 @@ public class Utils {
Consumer<CachingServiceReference<T>> whenLeavingNotGettable) {
return bundleContext().flatMap(bundleContext ->
- program.flatMap(immutable -> {
- T service = null;
+ program.recoverWith(
+ (serviceReference, e) ->
+ notGettableResult(
+ whenAddedNotGettable, whenLeavingNotGettable,
+ serviceReference)
+ ).flatMap(serviceReference -> {
+ ServiceObjects<T> serviceObjects =
+ bundleContext.getServiceObjects(
+ serviceReference.getServiceReference());
+ T service = serviceObjects.getService();
- try {
- service = bundleContext.getService(
- immutable.getServiceReference());
- }
- catch (Exception e){
- }
if (service == null) {
- return
- effects(
- () -> whenAddedNotGettable.accept(immutable),
- () -> whenLeavingNotGettable.accept(immutable)
- ).then(
- nothing()
- );
+ return notGettableResult(
+ whenAddedNotGettable, whenLeavingNotGettable,
+ serviceReference);
}
+
return
onClose(
- () -> bundleContext.ungetService(
- immutable.getServiceReference())
+ () -> serviceObjects.ungetService(service)
).then(
- just(new ServiceTuple<>(immutable, service))
+ just(new ServiceTuple<>(
+ serviceReference, serviceObjects, service))
);
}));
}
+ private static <T, S> OSGi<S> notGettableResult(
+ Consumer<CachingServiceReference<T>> whenAddedNotGettable,
+ Consumer<CachingServiceReference<T>> whenLeavingNotGettable,
+ CachingServiceReference<T> immutable) {
+
+ return effects(
+ () -> whenAddedNotGettable.accept(immutable),
+ () -> whenLeavingNotGettable.accept(immutable)
+ ).then(
+ nothing()
+ );
+ }
+
public static <T> OSGi<T> service(
CachingServiceReference<T> immutableServiceReference) {
@@ -265,10 +277,16 @@ public class Utils {
public static class ServiceTuple<T> implements Comparable<ServiceTuple<T>> {
private final CachingServiceReference<T> _serviceReference;
+ private ServiceObjects<T> _serviceObjects;
private final T _service;
- ServiceTuple(CachingServiceReference<T> a, T service) {
+ ServiceTuple(
+ CachingServiceReference<T> a, ServiceObjects<T> serviceObjects,
+ T service) {
+
_serviceReference = a;
+
+ _serviceObjects = serviceObjects;
_service = service;
}
@@ -281,6 +299,10 @@ public class Utils {
return _service;
}
+ public ServiceObjects<T> getServiceObjects() {
+ return _serviceObjects;
+ }
+
@Override
public int hashCode() {
return _serviceReference.hashCode();
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/5cb59cac/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 9b36661..4fc3dfb 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
@@ -413,7 +413,8 @@ public class Whiteboard {
private <T> OSGi<?> safeRegisterEndpoint(
CachingServiceReference<T> serviceReference,
- CachingServiceReference<CXFJaxRsServiceRegistrator> registratorReference) {
+ CachingServiceReference<CXFJaxRsServiceRegistrator>
+ registratorReference) {
String applicationName = getApplicationName(
registratorReference::getProperty);
@@ -431,9 +432,7 @@ public class Whiteboard {
_runtime::removeErroredEndpoint).
then(nothing())
).map(
- ServiceTuple::getCachingServiceReference
- ).flatMap(
- Utils::serviceObjects
+ ServiceTuple::getServiceObjects
).map(
Utils::getResourceProvider
).effects(
[3/4] aries-jax-rs-whiteboard git commit: automatic update bndrun
Posted by cs...@apache.org.
automatic update bndrun
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/4b959b58
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/4b959b58
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/4b959b58
Branch: refs/heads/master
Commit: 4b959b5853bd5876772a4cccba72a7bb22ae93de
Parents: 4926d06
Author: Carlos Sierra <cs...@apache.org>
Authored: Thu Dec 7 12:48:54 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Thu Dec 7 12:49:25 2017 +0100
----------------------------------------------------------------------
jax-rs.itests/itest.bndrun | 1 -
1 file changed, 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/4b959b58/jax-rs.itests/itest.bndrun
----------------------------------------------------------------------
diff --git a/jax-rs.itests/itest.bndrun b/jax-rs.itests/itest.bndrun
index a6d8759..52fbb09 100644
--- a/jax-rs.itests/itest.bndrun
+++ b/jax-rs.itests/itest.bndrun
@@ -39,7 +39,6 @@
org.osgi.util.function;version='[1.1.0,1.1.1)',\
org.osgi.util.promise;version='[1.1.0,1.1.1)',\
slf4j.api;version='[1.7.25,1.7.26)',\
- org.osgi.service.cm;version='[1.5.0,1.5.1)',\
org.apache.felix.configadmin;version='[1.8.14,1.8.15)',\
org.osgi.service.http.whiteboard;version='[1.0.0,1.0.1)'
[2/4] aries-jax-rs-whiteboard git commit: Register service reference
properties in application
Posted by cs...@apache.org.
Register service reference properties in application
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/f3e0d515
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/f3e0d515
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/f3e0d515
Branch: refs/heads/master
Commit: f3e0d5158ec5d18721bd737fe09e239929b5e31e
Parents: 5cb59ca
Author: Carlos Sierra <cs...@apache.org>
Authored: Tue Dec 5 16:46:31 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Thu Dec 7 12:49:25 2017 +0100
----------------------------------------------------------------------
jax-rs.itests/src/main/java/test/JaxrsTest.java | 64 ++++++++++++++++++++
.../internal/CXFJaxRsServiceRegistrator.java | 12 +++-
.../jax/rs/whiteboard/internal/Whiteboard.java | 4 +-
3 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/f3e0d515/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 988d8af..5be1e74 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -25,14 +25,17 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Dictionary;
+import java.util.HashSet;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -61,6 +64,7 @@ import test.types.TestFilter;
import test.types.TestFilterAndExceptionMapper;
import test.types.TestHelper;
+import javax.ws.rs.GET;
import javax.ws.rs.client.InvocationCallback;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.container.ContainerResponseFilter;
@@ -779,6 +783,29 @@ public class JaxrsTest extends TestHelper {
}
@Test
+ public void testDefaultServiceReferencePropertiesAreAvailableInFeatures() {
+ AtomicBoolean executed = new AtomicBoolean();
+ AtomicReference<Object> propertyvalue = new AtomicReference<>();
+
+ registerExtension(
+ Feature.class, featureContext -> {
+ executed.set(true);
+
+ Map<String, Object> properties =
+ (Map<String, Object>)
+ featureContext.getConfiguration().getProperty(
+ "osgi.jaxrs.application.serviceProperties");
+ propertyvalue.set(properties.get(JAX_RS_NAME));
+
+ return false;
+ }, "Feature", JAX_RS_APPLICATION_SELECT,
+ "("+ JAX_RS_NAME + "=" + JAX_RS_DEFAULT_APPLICATION + ")");
+
+ assertTrue(executed.get());
+ assertEquals(JAX_RS_DEFAULT_APPLICATION, propertyvalue.get());
+ }
+
+ @Test
public void testEndpointsOverride() {
WebTarget webTarget = createDefaultTarget().path("conflict");
@@ -1113,6 +1140,43 @@ public class JaxrsTest extends TestHelper {
}
@Test
+ public void testServiceReferencePropertiesAreAvailableInFeatures() {
+ AtomicBoolean executed = new AtomicBoolean();
+ AtomicReference<Object> propertyvalue = new AtomicReference<>();
+
+ registerExtension(
+ Feature.class, featureContext -> {
+ executed.set(true);
+
+ Map<String, Object> properties =
+ (Map<String, Object>)
+ featureContext.getConfiguration().getProperty(
+ "osgi.jaxrs.application.serviceProperties");
+ propertyvalue.set(properties.get("property"));
+
+ return false;
+ }, "Feature", JAX_RS_APPLICATION_SELECT, "(property=true)");
+
+ registerApplication(
+ new Application() {
+ @Override
+ public Set<Object> getSingletons() {
+ return Collections.singleton(
+ new Object() {
+
+ @GET
+ public String hello() {
+ return "hello";
+ }
+ });
+ }
+ }, JAX_RS_NAME, "test", "property", true);
+
+ assertTrue(executed.get());
+ assertEquals(true, propertyvalue.get());
+ }
+
+ @Test
public void testStandaloneEndPoint() throws InterruptedException {
WebTarget webTarget = createDefaultTarget().path("test");
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/f3e0d515/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 3af691e..5789637 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
@@ -20,7 +20,9 @@ package org.apache.aries.jax.rs.whiteboard.internal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;
import java.util.stream.Collectors;
@@ -48,9 +50,12 @@ import static org.apache.aries.jax.rs.whiteboard.internal.Utils.canonicalize;
public class CXFJaxRsServiceRegistrator {
- public CXFJaxRsServiceRegistrator(Bus bus, Application application) {
+ public CXFJaxRsServiceRegistrator(
+ Bus bus, Application application, Map<String, Object> properties) {
_bus = bus;
_application = application;
+ _properties = Collections.unmodifiableMap(new HashMap<>(properties));
+
Comparator<ServiceTuple<?>> comparing = Comparator.comparing(
ServiceTuple::getCachingServiceReference);
@@ -141,6 +146,7 @@ public class CXFJaxRsServiceRegistrator {
}
private final Application _application;
+ private Map<String, Object> _properties;
private final Bus _bus;
private final Collection<ServiceTuple<?>> _providers;
private final Collection<ResourceProvider> _services = new ArrayList<>();
@@ -211,6 +217,10 @@ public class CXFJaxRsServiceRegistrator {
jaxRsServerFactoryBean.setProvider(
(Feature) featureContext -> {
+ featureContext.property(
+ "osgi.jaxrs.application.serviceProperties",
+ _properties);
+
for (ServiceTuple<?> provider : _providers) {
CachingServiceReference<?> cachingServiceReference =
provider.getCachingServiceReference();
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/f3e0d515/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 4fc3dfb..256fa4b 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
@@ -328,9 +328,9 @@ public class Whiteboard {
Bus bus, ServiceTuple<Application> tuple, Map<String, Object> props) {
return
- just(() -> new CXFJaxRsServiceRegistrator(bus, tuple.getService())).
+ just(() -> new CXFJaxRsServiceRegistrator(
+ bus, tuple.getService(), props)).
flatMap(registrator ->
-
onClose(registrator::close).then(
register(CXFJaxRsServiceRegistrator.class, registrator, props)));
}
[4/4] aries-jax-rs-whiteboard git commit: Enable Feature as an
Extension test
Posted by cs...@apache.org.
Enable Feature as an Extension test
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/4926d068
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/4926d068
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/4926d068
Branch: refs/heads/master
Commit: 4926d06875fbec305fd63f9344089fdb94eabfc1
Parents: f3e0d51
Author: Carlos Sierra <cs...@apache.org>
Authored: Thu Dec 7 09:40:03 2017 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Thu Dec 7 12:49:25 2017 +0100
----------------------------------------------------------------------
jax-rs.itests/src/main/java/test/JaxrsTest.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/4926d068/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 5be1e74..763ac47 100644
--- a/jax-rs.itests/src/main/java/test/JaxrsTest.java
+++ b/jax-rs.itests/src/main/java/test/JaxrsTest.java
@@ -902,7 +902,6 @@ public class JaxrsTest extends TestHelper {
}
- @Ignore
@Test
public void testFeatureExtension() {
WebTarget webTarget = createDefaultTarget().path("/test-application");
@@ -912,7 +911,7 @@ public class JaxrsTest extends TestHelper {
registerExtension(
Feature.class,
context -> {
- context.register(new TestAddonConflict2());
+ context.register(new TestFilter());
return true;
},