Repository: aries-jax-rs-whiteboard Updated Branches: refs/heads/master 14d5aedb4 -> 270d10265
Propagate properties to ServletContextHelper and CXF Servlet registration 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/270d1026 Tree: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/tree/270d1026 Diff: http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/diff/270d1026 Branch: refs/heads/master Commit: 270d1026528b34e80f96316545ca067020d284ef Parents: 14d5aed Author: Carlos Sierra <csie...@apache.org> Authored: Thu May 17 17:28:59 2018 +0200 Committer: Carlos Sierra <csie...@apache.org> Committed: Thu May 17 17:28:59 2018 +0200 ---------------------------------------------------------------------- .../jax/rs/whiteboard/internal/Whiteboard.java | 36 +++++++------- .../jax/rs/whiteboard/internal/utils/Utils.java | 50 +++++++++++++------- 2 files changed, 53 insertions(+), 33 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/270d1026/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 10b0167..480c850 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 @@ -1153,22 +1153,13 @@ public class Whiteboard { }); } - private static OSGi<ServiceRegistration<Servlet>> registerCXFServletService( - Bus bus, Supplier<Map<String, ?>> configurationSup, + private OSGi<ServiceRegistration<Servlet>> registerCXFServletService( + Bus bus, Supplier<Map<String, ?>> servicePropertiesSup, CachingServiceReference<ServletContextHelper> contextReference) { - Map<String, ?> configuration = configurationSup.get(); + Map<String, ?> serviceProperties = servicePropertiesSup.get(); - Supplier<Map<String, ?>> propertiesSup = () -> { - HashMap<String, Object> properties = new HashMap<>(configuration); - - properties.putIfAbsent( - HTTP_WHITEBOARD_TARGET, "(osgi.http.endpoint=*)"); - - return properties; - }; - - String address = getApplicationBase(configuration::get); + String address = getApplicationBase(serviceProperties::get); if (!address.startsWith("/")) { address = "/" + address; @@ -1180,7 +1171,7 @@ public class Whiteboard { String finalAddress = address; - String applicationName = getServiceName(configuration::get); + String applicationName = getServiceName(serviceProperties::get); Supplier<Map<String, ?>> contextPropertiesSup; @@ -1190,6 +1181,13 @@ public class Whiteboard { contextPropertiesSup = () -> { HashMap<String, Object> contextProperties = new HashMap<>(); + Utils.mergePropertyMaps(contextProperties, serviceProperties); + + Utils.mergePropertyMaps(contextProperties, _configurationMap); + + contextProperties.putIfAbsent( + HTTP_WHITEBOARD_TARGET, "(osgi.http.endpoint=*)"); + String contextName; if ("".equals(finalAddress)) { @@ -1223,8 +1221,14 @@ public class Whiteboard { } Supplier<Map<String, ?>> servletPropertiesSup = () -> { - HashMap<String, Object> servletProperties = new HashMap<>( - propertiesSup.get()); + HashMap<String, Object> servletProperties = new HashMap<>(); + + Utils.mergePropertyMaps(servletProperties, serviceProperties); + + Utils.mergePropertyMaps(servletProperties, _configurationMap); + + servletProperties.putIfAbsent( + HTTP_WHITEBOARD_TARGET, "(osgi.http.endpoint=*)"); Map<String, ?> contextProperties = contextPropertiesSup.get(); http://git-wip-us.apache.org/repos/asf/aries-jax-rs-whiteboard/blob/270d1026/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java ---------------------------------------------------------------------- diff --git a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java index 3dff9c7..b31c780 100644 --- a/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java +++ b/jax-rs.whiteboard/src/main/java/org/apache/aries/jax/rs/whiteboard/internal/utils/Utils.java @@ -112,6 +112,22 @@ public class Utils { ); } + public static void mergePropertyMaps( + Map<String, Object> receptor, Map<String, ?> map) { + + for (Map.Entry<String, ?> entry : + map.entrySet()) { + + String key = entry.getKey(); + + if (key.startsWith(".")) { + continue; + } + + receptor.putIfAbsent(key, entry.getValue()); + } + } + public static <T> OSGi<ServiceTuple<T>> onlyGettables( OSGi<CachingServiceReference<T>> program, Consumer<CachingServiceReference<T>> whenAddedNotGettable, @@ -151,23 +167,6 @@ public class Utils { })); } - private static <T, S> OSGi<S> notGettableResult( - Consumer<CachingServiceReference<T>> whenAddedNotGettable, - Consumer<CachingServiceReference<T>> whenLeavingNotGettable, - CachingServiceReference<T> immutable, Logger log) { - - return effects( - () -> whenAddedNotGettable.accept(immutable), - () -> whenLeavingNotGettable.accept(immutable) - ).effects( - ifDebugEnabled(log, () -> "Tracked not gettable reference {}"), - ifDebugEnabled(log, () -> "Untracked not gettable reference {}") - ). - then( - nothing() - ); - } - public static <T> OSGi<T> service( CachingServiceReference<T> immutableServiceReference) { @@ -199,4 +198,21 @@ public class Utils { serviceRegistration.setProperties(properties); } + private static <T, S> OSGi<S> notGettableResult( + Consumer<CachingServiceReference<T>> whenAddedNotGettable, + Consumer<CachingServiceReference<T>> whenLeavingNotGettable, + CachingServiceReference<T> immutable, Logger log) { + + return effects( + () -> whenAddedNotGettable.accept(immutable), + () -> whenLeavingNotGettable.accept(immutable) + ).effects( + ifDebugEnabled(log, () -> "Tracked not gettable reference {}"), + ifDebugEnabled(log, () -> "Untracked not gettable reference {}") + ). + then( + nothing() + ); + } + }