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 2018/02/20 09:51:53 UTC
[3/3] aries-jax-rs-whiteboard git commit: Property validation in
resources
Property validation in resources
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/56dd71be
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/56dd71be
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/56dd71be
Branch: refs/heads/master
Commit: 56dd71be467b447f07992b362367e9d9e9fc69ca
Parents: 1194baf
Author: Carlos Sierra <cs...@apache.org>
Authored: Tue Feb 20 09:44:45 2018 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Tue Feb 20 09:44:45 2018 +0100
----------------------------------------------------------------------
.../internal/AriesJaxrsServiceRuntime.java | 73 +++++++++++++---
.../jax/rs/whiteboard/internal/Whiteboard.java | 91 +++++++++++++++++---
2 files changed, 139 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/56dd71be/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 33638e1..aecce6c 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
@@ -166,12 +166,24 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
_erroredExtensions.add(cachingServiceReference);
}
+ public void addInvalidApplication(
+ CachingServiceReference<?> serviceReference) {
+
+ _invalidApplications.add(serviceReference);
+ }
+
public void addInvalidExtension(
CachingServiceReference<?> serviceReference) {
_invalidExtensions.add(serviceReference);
}
+ public void addInvalidResource(
+ CachingServiceReference<?> serviceReference) {
+
+ _invalidResources.add(serviceReference);
+ }
+
public boolean addNotGettableApplication(
CachingServiceReference<Application> serviceReference) {
@@ -228,29 +240,34 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
ApplicationDTO[]::new
);
- runtimeDTO.failedApplicationDTOs = Stream.concat(
- shadowedApplicationsDTOStream(),
+ runtimeDTO.failedApplicationDTOs =
Stream.concat(
- unreferenciableApplicationsDTOStream(),
+ invalidApplicationsDTOStream(),
Stream.concat(
- clashingApplicationsDTOStream(),
+ shadowedApplicationsDTOStream(),
Stream.concat(
- dependentApplicationsDTOStream(),
- erroredApplicationsDTOStream())))
+ unreferenciableApplicationsDTOStream(),
+ Stream.concat(
+ clashingApplicationsDTOStream(),
+ Stream.concat(
+ dependentApplicationsDTOStream(),
+ erroredApplicationsDTOStream()))))
).toArray(
FailedApplicationDTO[]::new
);
runtimeDTO.failedResourceDTOs =
Stream.concat(
- clashingResourcesDTOStream(),
+ invalidResourcesDTOStream(),
Stream.concat(
- unreferenciableEndpointsDTOStream(),
+ clashingResourcesDTOStream(),
Stream.concat(
- dependentServiceStreamDTO(),
+ unreferenciableEndpointsDTOStream(),
Stream.concat(
- applicationDependentResourcesDTOStream(),
- erroredEndpointsStreamDTO())))
+ dependentServiceStreamDTO(),
+ Stream.concat(
+ applicationDependentResourcesDTOStream(),
+ erroredEndpointsStreamDTO()))))
).toArray(
FailedResourceDTO[]::new
);
@@ -357,10 +374,24 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
_erroredExtensions.remove(cachingServiceReference);
}
- public void removeInvalidExtension(CachingServiceReference<?> serviceReference) {
+ public void removeInvalidApplication(
+ CachingServiceReference<?> serviceReference) {
+
+ _invalidApplications.remove(serviceReference);
+ }
+
+ public void removeInvalidExtension(
+ CachingServiceReference<?> serviceReference) {
+
_invalidExtensions.remove(serviceReference);
}
+ public void removeInvalidResource(
+ CachingServiceReference<?> serviceReference) {
+
+ _invalidResources.remove(serviceReference);
+ }
+
public boolean removeNotGettableApplication(
CachingServiceReference<Application> serviceReference) {
@@ -439,8 +470,12 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
new CopyOnWriteArrayList<>();
private Collection<CachingServiceReference<?>> _erroredExtensions =
new CopyOnWriteArrayList<>();
+ private Collection<CachingServiceReference<?>> _invalidApplications =
+ new CopyOnWriteArrayList<>();
private Collection<CachingServiceReference<?>> _invalidExtensions =
new CopyOnWriteArrayList<>();
+ private Collection<CachingServiceReference<?>> _invalidResources =
+ new CopyOnWriteArrayList<>();
private Collection<CachingServiceReference<Application>> _shadowedApplications =
new CopyOnWriteArrayList<>();
private Collection<CachingServiceReference<Application>>
@@ -820,6 +855,20 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
);
}
+ private Stream<FailedApplicationDTO> invalidApplicationsDTOStream() {
+ return _invalidApplications.stream().
+ map(sr -> buildFailedApplicationDTO(
+ DTOConstants.FAILURE_REASON_VALIDATION_FAILED, sr)
+ );
+ }
+
+ private Stream<FailedResourceDTO> invalidResourcesDTOStream() {
+ return _invalidResources.stream().
+ map(sr -> buildFailedResourceDTO(
+ DTOConstants.FAILURE_REASON_VALIDATION_FAILED, sr)
+ );
+ }
+
private Stream<FailedApplicationDTO> shadowedApplicationsDTOStream() {
return _shadowedApplications.stream().
map(sr -> buildFailedApplicationDTO(
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/56dd71be/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 ce38529..4510075 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
@@ -95,6 +95,7 @@ import static org.osgi.service.http.whiteboard.HttpWhiteboardConstants.HTTP_WHIT
import static org.osgi.service.jaxrs.runtime.JaxrsServiceRuntimeConstants.JAX_RS_SERVICE_ENDPOINT;
import static org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_APPLICATION_BASE;
import static org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_APPLICATION_SELECT;
+import static org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_DEFAULT_APPLICATION;
import static org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_EXTENSION;
import static org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_EXTENSION_SELECT;
import static org.osgi.service.jaxrs.whiteboard.JaxrsWhiteboardConstants.JAX_RS_NAME;
@@ -180,22 +181,25 @@ public class Whiteboard {
OSGi<CachingServiceReference<Object>> extensions) {
return
- onlySupportedInterfaces(
- extensions,
+ onlyValid(
+ onlySupportedInterfaces(
+ extensions,
+ _runtime::addInvalidExtension,
+ _runtime::removeInvalidExtension),
_runtime::addInvalidExtension,
_runtime::removeInvalidExtension).
- flatMap(resourceReference ->
+ flatMap(extensionReference ->
chooseApplication(
- resourceReference, Whiteboard::allApplicationReferences,
+ extensionReference, Whiteboard::allApplicationReferences,
_runtime::addApplicationDependentExtension,
_runtime::removeApplicationDependentExtension).
flatMap(registratorReference ->
waitForExtensionDependencies(
- resourceReference, registratorReference,
+ extensionReference, registratorReference,
_runtime::addDependentExtension,
_runtime::removeDependentExtension).
then(
- safeRegisterExtension(resourceReference, registratorReference)
+ safeRegisterExtension(extensionReference, registratorReference)
)));
}
@@ -203,16 +207,19 @@ public class Whiteboard {
OSGi<CachingServiceReference<Object>> resources) {
return
- resources.flatMap(resourceReference ->
+ onlyValid(
+ resources, _runtime::addInvalidResource,
+ _runtime::removeInvalidResource).
+ flatMap(resourceReference ->
chooseApplication(
- resourceReference, this::defaultApplication,
- _runtime::addApplicationDependentResource,
- _runtime::removeApplicationDependentResource).
+ resourceReference, this::defaultApplication,
+ _runtime::addApplicationDependentResource,
+ _runtime::removeApplicationDependentResource).
flatMap(registratorReference ->
waitForExtensionDependencies(
- resourceReference, registratorReference,
- _runtime::addDependentService,
- _runtime::removeDependentService).
+ resourceReference, registratorReference,
+ _runtime::addDependentService,
+ _runtime::removeDependentService).
then(
safeRegisterEndpoint(resourceReference, registratorReference)
)));
@@ -276,12 +283,70 @@ public class Whiteboard {
}
}
+ private static <T> OSGi<CachingServiceReference<T>> onlyValid(
+ OSGi<CachingServiceReference<T>> serviceReferences,
+ Consumer<CachingServiceReference<T>> onAddingInvalid,
+ Consumer<CachingServiceReference<T>> onRemovingInvalid) {
+
+ return serviceReferences.flatMap(serviceReference -> {
+
+ OSGi<CachingServiceReference<T>> error = effects(
+ () -> onAddingInvalid.accept(serviceReference),
+ () -> onRemovingInvalid.accept(serviceReference)
+ ).then(
+ nothing()
+ );
+
+ Object propertyObject = serviceReference.getProperty(JAX_RS_NAME);
+
+ if (propertyObject != null &&
+ !propertyObject.toString().equals(JAX_RS_DEFAULT_APPLICATION) &&
+ propertyObject.toString().startsWith(".")) {
+
+ return error;
+ }
+
+ if (!testFilters(
+ serviceReference.getProperty(JAX_RS_APPLICATION_SELECT))) {
+
+ return error;
+ }
+
+ if (!testFilters(
+ serviceReference.getProperty(JAX_RS_EXTENSION_SELECT))) {
+
+ return error;
+ }
+
+ return just(serviceReference);
+ });
+ }
+
+ private static <T> boolean testFilters(Object propertyObject) {
+ if (propertyObject != null) {
+ try {
+ String[] properties = canonicalize(propertyObject);
+
+ for (String property : properties) {
+ FrameworkUtil.createFilter(property);
+ }
+ }
+ catch (InvalidSyntaxException e) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private OSGi<?> applications(
OSGi<CachingServiceReference<Application>> applications) {
OSGi<CachingServiceReference<Application>> applicationsForWhiteboard =
waitForApplicationDependencies(
+ onlyValid(
applications,
+ _runtime::addInvalidApplication,
+ _runtime::removeInvalidApplication)
);
OSGi<CachingServiceReference<Application>> highestRankedPerPath =