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:51 UTC
[1/3] aries-jax-rs-whiteboard git commit: Name clashing must happen
among all types of services
Repository: aries-jax-rs-whiteboard
Updated Branches:
refs/heads/master 082b64a6f -> 56dd71be4
Name clashing must happen among all types of services
Section 151.3
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/0ab8db67
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/0ab8db67
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/0ab8db67
Branch: refs/heads/master
Commit: 0ab8db67bc71d83f0581f770f656c6122874b007
Parents: 082b64a
Author: Carlos Sierra <cs...@apache.org>
Authored: Mon Feb 19 11:56:55 2018 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Mon Feb 19 11:56:55 2018 +0100
----------------------------------------------------------------------
.../internal/AriesJaxrsServiceRuntime.java | 81 +++++++---
.../jax/rs/whiteboard/internal/Whiteboard.java | 161 +++++++++++++------
2 files changed, 172 insertions(+), 70 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/0ab8db67/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 11cb1ba..b40fedc 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
@@ -117,11 +117,23 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
}
public void addClashingApplication(
- CachingServiceReference<Application> serviceReference) {
+ CachingServiceReference<?> serviceReference) {
_clashingApplications.add(serviceReference);
}
+ public void addClashingExtension(
+ CachingServiceReference<?> serviceReference) {
+
+ _clashingExtensions.add(serviceReference);
+ }
+
+ public void addClashingResource(
+ CachingServiceReference<?> serviceReference) {
+
+ _clashingResources.add(serviceReference);
+ }
+
public void addDependentApplication(
CachingServiceReference<Application> applicationReference) {
@@ -231,24 +243,29 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
runtimeDTO.failedResourceDTOs =
Stream.concat(
- unreferenciableEndpointsDTOStream(),
+ clashingResourcesDTOStream(),
Stream.concat(
- dependentServiceStreamDTO(),
+ unreferenciableEndpointsDTOStream(),
Stream.concat(
- applicationDependentResourcesDTOStream(),
- erroredEndpointsStreamDTO()))
+ dependentServiceStreamDTO(),
+ Stream.concat(
+ applicationDependentResourcesDTOStream(),
+ erroredEndpointsStreamDTO())))
).toArray(
FailedResourceDTO[]::new
);
- runtimeDTO.failedExtensionDTOs = Stream.concat(
- unreferenciableExtensionsDTOStream(),
+ runtimeDTO.failedExtensionDTOs =
+ Stream.concat(
+ clashingExtensionsDTOStream(),
Stream.concat(
- applicationDependentExtensionsDTOStream(),
+ unreferenciableExtensionsDTOStream(),
Stream.concat(
- erroredExtensionsDTOStream(),
- Stream.concat(dependentExtensionsStreamDTO(),
- invalidExtensionsDTOStream())))
+ applicationDependentExtensionsDTOStream(),
+ Stream.concat(
+ erroredExtensionsDTOStream(),
+ Stream.concat(dependentExtensionsStreamDTO(),
+ invalidExtensionsDTOStream()))))
).toArray(
FailedExtensionDTO[]::new
);
@@ -291,11 +308,17 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
}
public void removeClashingApplication(
- CachingServiceReference<Application> serviceReference) {
+ CachingServiceReference<?> serviceReference) {
_clashingApplications.remove(serviceReference);
}
+ public void removeClashingExtension(
+ CachingServiceReference<?> serviceReference) {
+
+ _clashingExtensions.remove(serviceReference);
+ }
+
public void removeClashingResource(
CachingServiceReference<?> serviceReference) {
@@ -397,7 +420,11 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
_applicationExtensions = new ConcurrentHashMap<>();
private ConcurrentHashMap<String, ApplicationRuntimeInformation>
_applications = new ConcurrentHashMap<>();
- private Collection<CachingServiceReference<Application>> _clashingApplications =
+ private Collection<CachingServiceReference<?>> _clashingApplications =
+ new CopyOnWriteArrayList<>();
+ private Collection<CachingServiceReference<?>> _clashingExtensions =
+ new CopyOnWriteArrayList<>();
+ private Collection<CachingServiceReference<?>> _clashingResources =
new CopyOnWriteArrayList<>();
private volatile ApplicationRuntimeInformation _defaultApplicationProperties;
private Set<CachingServiceReference<Application>> _dependentApplications =
@@ -424,7 +451,7 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
new CopyOnWriteArrayList<>();
private static FailedApplicationDTO buildFailedApplicationDTO(
- int reason, CachingServiceReference<Application> serviceReference) {
+ int reason, CachingServiceReference<?> serviceReference) {
FailedApplicationDTO failedApplicationDTO = new FailedApplicationDTO();
@@ -462,7 +489,7 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
baseDTO.name = getApplicationName(serviceReference::getProperty);
baseDTO.serviceId = (Long)serviceReference.getProperty(
"service.id");
-
+
return baseDTO;
}
@@ -702,6 +729,18 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
);
}
+ private Stream<FailedExtensionDTO> clashingExtensionsDTOStream() {
+ return _clashingExtensions.stream().map(
+ sr -> buildFailedExtensionDTO(
+ DTOConstants.FAILURE_REASON_DUPLICATE_NAME, sr));
+ }
+
+ private Stream<FailedResourceDTO> clashingResourcesDTOStream() {
+ return _clashingResources.stream().map(
+ sr -> buildFailedResourceDTO(
+ DTOConstants.FAILURE_REASON_DUPLICATE_NAME, sr));
+ }
+
private Stream<FailedApplicationDTO> dependentApplicationsDTOStream() {
return _dependentApplications.stream().map(
sr -> buildFailedApplicationDTO(
@@ -823,7 +862,7 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
public int hashCode() {
return _cachingServiceReference.hashCode();
}
- CachingServiceReference _cachingServiceReference; @Override
+ CachingServiceReference _cachingServiceReference; Bus _bus;@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -833,9 +872,9 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
return _cachingServiceReference.equals(
that._cachingServiceReference);
}
- Bus _bus;
Class<?> _class;
+
}
private static class ExtensionRuntimeInformation {
@@ -846,11 +885,11 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
_cachingServiceReference = cachingServiceReference;
_class = aClass;
}
- CachingServiceReference _cachingServiceReference; @Override
+ CachingServiceReference _cachingServiceReference; Class<?> _class;@Override
public int hashCode() {
return _cachingServiceReference.hashCode();
}
- Class<?> _class; @Override
+ @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -873,11 +912,11 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
_cachingServiceReference = cachingServiceReference;
_cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator;
}
- CachingServiceReference _cachingServiceReference; @Override
+ CachingServiceReference _cachingServiceReference; CxfJaxrsServiceRegistrator _cxfJaxRsServiceRegistrator;@Override
public int hashCode() {
return _cachingServiceReference.hashCode();
}
- CxfJaxrsServiceRegistrator _cxfJaxRsServiceRegistrator; @Override
+ @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/0ab8db67/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 b74faa0..b7e2433 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
@@ -29,6 +29,7 @@ import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
+import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
@@ -94,7 +95,6 @@ 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;
@@ -122,8 +122,6 @@ public class Whiteboard {
static final String DEFAULT_NAME = ".default";
private static final Function<CachingServiceReference<Application>, String>
APPLICATION_BASE = sr -> getApplicationBase(sr::getProperty);
- private static final Function<CachingServiceReference<Application>, String>
- APPLICATION_NAME = sr -> getApplicationName(sr::getProperty);
private final AriesJaxrsServiceRuntime _runtime;
private final Map<String, ?> _configurationMap;
@@ -149,10 +147,8 @@ public class Whiteboard {
_program =
all(
ignore(registerDefaultApplication()),
- ignore(applications()),
- ignore(applicationResources()),
- ignore(applicationExtensions()
- ));
+ ignore(getAllServices())
+ );
}
public static Whiteboard createWhiteboard(
@@ -180,11 +176,12 @@ public class Whiteboard {
}
}
- private OSGi<?> applicationExtensions() {
+ private OSGi<?> applicationExtensions(
+ OSGi<CachingServiceReference<Object>> extensions) {
+
return
onlySupportedInterfaces(
- countChanges(
- getApplicationExtensionsForWhiteboard(), _counter),
+ extensions,
_runtime::addInvalidExtension,
_runtime::removeInvalidExtension).
flatMap(resourceReference ->
@@ -202,10 +199,11 @@ public class Whiteboard {
)));
}
- private OSGi<?> applicationResources() {
+ private OSGi<?> applicationResources(
+ OSGi<CachingServiceReference<Object>> resources) {
+
return
- countChanges(getResourcesForWhiteboard(), _counter).
- flatMap(resourceReference ->
+ resources.flatMap(resourceReference ->
chooseApplication(
resourceReference, this::defaultApplication,
_runtime::addApplicationDependentResource,
@@ -220,22 +218,72 @@ public class Whiteboard {
)));
}
- private OSGi<?> applications() {
+ @SuppressWarnings("unchecked")
+ private OSGi<?> getAllServices() {
+ return
+ highestPer(
+ sr -> getApplicationName(sr::getProperty),
+ all(
+ countChanges(getResourcesForWhiteboard(), _counter),
+ countChanges(getApplicationExtensionsForWhiteboard(), _counter),
+ countChanges(getApplicationsForWhiteboard(), _counter)
+ ),
+ this::registerShadowedService,
+ this::unregisterShadowedService
+ ).distribute(
+ p -> ignore(applications(p.filter(this::isApplication))),
+ p -> ignore(applicationResources(p.filter(this::isResource))),
+ p -> ignore(applicationExtensions(p.filter(this::isExtension)))
+ );
+ }
+
+ private boolean isApplication(CachingServiceReference<?> sr) {
+ return _applicationsFilter.match(sr.getServiceReference());
+ }
+
+ private boolean isExtension(CachingServiceReference<?> sr) {
+ return _extensionsFilter.match(sr.getServiceReference());
+ }
+
+ private boolean isResource(CachingServiceReference<?> sr) {
+ return _resourcesFilter.match(sr.getServiceReference());
+ }
+
+ private void registerShadowedService(CachingServiceReference<?> sr) {
+ if (isApplication(sr)) {
+ _runtime.addClashingApplication(sr);
+ }
+ if (isExtension(sr)) {
+ _runtime.addClashingExtension(sr);
+ }
+ if (isResource(sr)) {
+ _runtime.addClashingResource(sr);
+ }
+ }
+
+ private void unregisterShadowedService(CachingServiceReference<?> sr) {
+ if (isApplication(sr)) {
+ _runtime.removeClashingApplication(sr);
+ }
+ if (isExtension(sr)) {
+ _runtime.removeClashingExtension(sr);
+ }
+ if (isApplication(sr)) {
+ _runtime.removeClashingResource(sr);
+ }
+ }
+
+ private OSGi<?> applications(
+ OSGi<CachingServiceReference<Object>> applications) {
+
OSGi<CachingServiceReference<Application>> applicationsForWhiteboard =
- countChanges(getApplicationsForWhiteboard(), _counter).flatMap(
+ applications.flatMap(
this::waitForApplicationDependencies
);
- OSGi<CachingServiceReference<Application>> highestRankedPerName =
- highestPer(
- APPLICATION_NAME, applicationsForWhiteboard,
- _runtime::addClashingApplication,
- _runtime::removeClashingApplication
- );
-
OSGi<CachingServiceReference<Application>> highestRankedPerPath =
highestPer(
- APPLICATION_BASE, highestRankedPerName,
+ APPLICATION_BASE, applicationsForWhiteboard,
_runtime::addShadowedApplication,
_runtime::removeShadowedApplication
);
@@ -342,20 +390,20 @@ public class Whiteboard {
private OSGi<CachingServiceReference<Object>>
getApplicationExtensionsForWhiteboard() {
- return serviceReferences(getApplicationExtensionsFilter()).
+ return serviceReferences(_applicationExtensionsFilter.toString()).
filter(new TargetFilter<>(_runtimeReference));
}
- private OSGi<CachingServiceReference<Application>>
+ private OSGi<CachingServiceReference<Object>>
getApplicationsForWhiteboard() {
return
- serviceReferences(Application.class, getApplicationFilter()).
- filter(new TargetFilter<>(_runtimeReference));
+ serviceReferences(_applicationsFilter.toString()).
+ filter(new TargetFilter<>(_runtimeReference));
}
private OSGi<CachingServiceReference<Object>> getResourcesForWhiteboard() {
- return serviceReferences(getResourcesFilter()).
+ return serviceReferences(_resourcesFilter.toString()).
filter(
new TargetFilter<>(_runtimeReference));
}
@@ -502,10 +550,13 @@ public class Whiteboard {
private OSGi<CachingServiceReference<Application>>
waitForApplicationDependencies(
- CachingServiceReference<Application> applicationReference) {
+ CachingServiceReference<?> objectReference) {
String[] extensionDependencies = canonicalize(
- applicationReference.getProperty(JAX_RS_EXTENSION_SELECT));
+ objectReference.getProperty(JAX_RS_EXTENSION_SELECT));
+
+ CachingServiceReference<Application> applicationReference =
+ (CachingServiceReference<Application>) objectReference;
OSGi<CachingServiceReference<Application>> program = just(
applicationReference);
@@ -692,25 +743,6 @@ public class Whiteboard {
return cxfNonSpringServlet;
}
- private static String getApplicationExtensionsFilter() {
- return format(
- "(&(!(objectClass=%s))(%s=%s)%s)",
- ApplicationExtensionRegistration.class.getName(),
- JAX_RS_EXTENSION, true, getExtensionsFilter());
- }
-
- private static String getApplicationFilter() {
- return format("(%s=*)", JAX_RS_APPLICATION_BASE);
- }
-
- private static String getExtensionsFilter() {
- return format("(%s=true)", JAX_RS_EXTENSION);
- }
-
- private static String getResourcesFilter() {
- return format("(%s=true)", JAX_RS_RESOURCE);
- }
-
private static OSGi<CachingServiceReference<Object>> onlySupportedInterfaces(
OSGi<CachingServiceReference<Object>> program,
Consumer<CachingServiceReference<?>> onInvalidAdded,
@@ -822,4 +854,35 @@ public class Whiteboard {
}
}
+ private static final Filter _extensionsFilter;
+
+ private static final Filter _resourcesFilter;
+
+ private static Filter _applicationsFilter;
+
+ private static Filter _applicationExtensionsFilter;
+
+ static {
+ try {
+ _applicationsFilter = FrameworkUtil.createFilter(
+ format(
+ "(&(objectClass=%s)(%s=*))", Application.class.getName(),
+ JAX_RS_APPLICATION_BASE));
+ String extensionFilterString = format(
+ "(%s=true)", JAX_RS_EXTENSION);
+ _extensionsFilter = FrameworkUtil.createFilter(
+ extensionFilterString);
+ _applicationExtensionsFilter = FrameworkUtil.createFilter(
+ format(
+ "(&(!(objectClass=%s))(%s=%s)%s)",
+ ApplicationExtensionRegistration.class.getName(),
+ JAX_RS_EXTENSION, true, extensionFilterString));
+ _resourcesFilter = FrameworkUtil.createFilter(
+ format("(%s=true)", JAX_RS_RESOURCE));
+ }
+ catch (InvalidSyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
}
[3/3] aries-jax-rs-whiteboard git commit: Property validation in
resources
Posted by cs...@apache.org.
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 =
[2/3] aries-jax-rs-whiteboard git commit: Source formatting
Posted by cs...@apache.org.
Source formatting
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/1194bafd
Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/1194bafd
Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/1194bafd
Branch: refs/heads/master
Commit: 1194bafdc75565ba499f2666dc2adc834838f248
Parents: 0ab8db6
Author: Carlos Sierra <cs...@apache.org>
Authored: Tue Feb 20 09:44:17 2018 +0100
Committer: Carlos Sierra <cs...@apache.org>
Committed: Tue Feb 20 09:44:17 2018 +0100
----------------------------------------------------------------------
.../internal/AriesJaxrsServiceRuntime.java | 33 +++--
.../jax/rs/whiteboard/internal/Whiteboard.java | 136 ++++++++++---------
2 files changed, 91 insertions(+), 78 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/1194bafd/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 b40fedc..33638e1 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
@@ -710,7 +710,7 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
return failedExtensionDTO;
}
- private FailedResourceDTO buildFailedResourceDTO(
+ private static FailedResourceDTO buildFailedResourceDTO(
int reason, CachingServiceReference<?> serviceReference) {
FailedResourceDTO failedResourceDTO = new FailedResourceDTO();
@@ -849,6 +849,7 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
}
private static class EndpointRuntimeInformation {
+
public EndpointRuntimeInformation(
CachingServiceReference cachingServiceReference, Bus bus,
Class<?> aClass) {
@@ -862,7 +863,8 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
public int hashCode() {
return _cachingServiceReference.hashCode();
}
- CachingServiceReference _cachingServiceReference; Bus _bus;@Override
+
+ @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -872,12 +874,15 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
return _cachingServiceReference.equals(
that._cachingServiceReference);
}
- Class<?> _class;
+ Bus _bus;
+ CachingServiceReference _cachingServiceReference;
+ Class<?> _class;
}
private static class ExtensionRuntimeInformation {
+
public ExtensionRuntimeInformation(
CachingServiceReference<?> cachingServiceReference,
Class<?> aClass) {
@@ -885,11 +890,13 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
_cachingServiceReference = cachingServiceReference;
_class = aClass;
}
- CachingServiceReference _cachingServiceReference; Class<?> _class;@Override
+
+ @Override
public int hashCode() {
return _cachingServiceReference.hashCode();
}
- @Override
+
+ @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -900,11 +907,13 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
that._cachingServiceReference);
}
-
+ CachingServiceReference _cachingServiceReference;
+ Class<?> _class;
}
private static class ApplicationRuntimeInformation {
+
public ApplicationRuntimeInformation(
CachingServiceReference cachingServiceReference,
CxfJaxrsServiceRegistrator cxfJaxRsServiceRegistrator) {
@@ -912,11 +921,16 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
_cachingServiceReference = cachingServiceReference;
_cxfJaxRsServiceRegistrator = cxfJaxRsServiceRegistrator;
}
- CachingServiceReference _cachingServiceReference; CxfJaxrsServiceRegistrator _cxfJaxRsServiceRegistrator;@Override
+
+ CachingServiceReference _cachingServiceReference;
+ CxfJaxrsServiceRegistrator _cxfJaxRsServiceRegistrator;
+
+ @Override
public int hashCode() {
return _cachingServiceReference.hashCode();
}
- @Override
+
+ @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -928,9 +942,6 @@ public class AriesJaxrsServiceRuntime implements JaxrsServiceRuntime {
that._cachingServiceReference);
}
-
-
-
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/1194bafd/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 b7e2433..ce38529 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
@@ -220,18 +220,21 @@ public class Whiteboard {
@SuppressWarnings("unchecked")
private OSGi<?> getAllServices() {
+ OSGi<CachingServiceReference<Object>> applicationsForWhiteboard =
+ (OSGi)getApplicationsForWhiteboard();
return
highestPer(
sr -> getApplicationName(sr::getProperty),
all(
countChanges(getResourcesForWhiteboard(), _counter),
- countChanges(getApplicationExtensionsForWhiteboard(), _counter),
- countChanges(getApplicationsForWhiteboard(), _counter)
+ countChanges(
+ getApplicationExtensionsForWhiteboard(), _counter),
+ countChanges(applicationsForWhiteboard, _counter)
),
this::registerShadowedService,
this::unregisterShadowedService
).distribute(
- p -> ignore(applications(p.filter(this::isApplication))),
+ p -> ignore(applications((OSGi)p.filter(this::isApplication))),
p -> ignore(applicationResources(p.filter(this::isResource))),
p -> ignore(applicationExtensions(p.filter(this::isExtension)))
);
@@ -274,12 +277,12 @@ public class Whiteboard {
}
private OSGi<?> applications(
- OSGi<CachingServiceReference<Object>> applications) {
+ OSGi<CachingServiceReference<Application>> applications) {
OSGi<CachingServiceReference<Application>> applicationsForWhiteboard =
- applications.flatMap(
- this::waitForApplicationDependencies
- );
+ waitForApplicationDependencies(
+ applications,
+ );
OSGi<CachingServiceReference<Application>> highestRankedPerPath =
highestPer(
@@ -394,11 +397,11 @@ public class Whiteboard {
filter(new TargetFilter<>(_runtimeReference));
}
- private OSGi<CachingServiceReference<Object>>
+ private OSGi<CachingServiceReference<Application>>
getApplicationsForWhiteboard() {
return
- serviceReferences(_applicationsFilter.toString()).
+ serviceReferences(Application.class, _applicationsFilter.toString()).
filter(new TargetFilter<>(_runtimeReference));
}
@@ -550,76 +553,75 @@ public class Whiteboard {
private OSGi<CachingServiceReference<Application>>
waitForApplicationDependencies(
- CachingServiceReference<?> objectReference) {
+ OSGi<CachingServiceReference<Application>> references) {
- String[] extensionDependencies = canonicalize(
- objectReference.getProperty(JAX_RS_EXTENSION_SELECT));
+ return references.flatMap(reference -> {
+ String[] extensionDependencies = canonicalize(
+ reference.getProperty(JAX_RS_EXTENSION_SELECT));
- CachingServiceReference<Application> applicationReference =
- (CachingServiceReference<Application>) objectReference;
+ OSGi<CachingServiceReference<Application>> program = just(
+ reference);
- OSGi<CachingServiceReference<Application>> program = just(
- applicationReference);
+ if (extensionDependencies.length > 0) {
+ program = effects(
+ () -> _runtime.addDependentApplication(reference),
+ () -> _runtime.removeDependentApplication(reference)
+ ).then(program);
+ }
+ else {
+ return program;
+ }
- if (extensionDependencies.length > 0) {
- program = effects(
- () -> _runtime.addDependentApplication(applicationReference),
- () -> _runtime.removeDependentApplication(applicationReference)
- ).then(program);
- }
- else {
- return program;
- }
+ for (String extensionDependency : extensionDependencies) {
+ extensionDependency = String.format(
+ "(&(!(objectClass=%s))%s)",
+ ApplicationExtensionRegistration.class.getName(),
+ extensionDependency);
- for (String extensionDependency : extensionDependencies) {
- extensionDependency = String.format(
- "(&(!(objectClass=%s))%s)",
- ApplicationExtensionRegistration.class.getName(),
- extensionDependency);
-
- program =
- once(serviceReferences(extensionDependency)).
- flatMap(
- sr -> {
- Object applicationSelectProperty =
- sr.getProperty(JAX_RS_APPLICATION_SELECT);
-
- if (applicationSelectProperty == null) {
- return just(applicationReference);
- }
+ program =
+ once(serviceReferences(extensionDependency)).
+ flatMap(
+ sr -> {
+ Object applicationSelectProperty =
+ sr.getProperty(JAX_RS_APPLICATION_SELECT);
- Filter filter;
+ if (applicationSelectProperty == null) {
+ return just(reference);
+ }
- try {
- filter = _bundleContext.createFilter(
- applicationSelectProperty.toString());
- }
- catch (InvalidSyntaxException e) {
- return nothing();
- }
+ Filter filter;
- if (filter.match(
- applicationReference.getServiceReference())) {
+ try {
+ filter = _bundleContext.createFilter(
+ applicationSelectProperty.toString());
+ }
+ catch (InvalidSyntaxException e) {
+ return nothing();
+ }
- return just(applicationReference);
- }
+ if (filter.match(
+ reference.getServiceReference())) {
- return nothing();
- }
- ).effects(
- __ -> {},
- __ -> _runtime.addDependentApplication(
- applicationReference)
- ).
- then(program);
- }
+ return just(reference);
+ }
- program = program.effects(
- __ -> _runtime.removeDependentApplication(applicationReference),
- __ -> {}
- );
+ return nothing();
+ }
+ ).effects(
+ __ -> {},
+ __ -> _runtime.addDependentApplication(
+ reference)
+ ).
+ then(program);
+ }
- return program;
+ program = program.effects(
+ __ -> _runtime.removeDependentApplication(reference),
+ __ -> {}
+ );
+
+ return program;
+ });
}
private OSGi<?> waitForExtensionDependencies(