FELIX-4865 : Take service hooks into account

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1679510 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
index f288b19..2b8575e 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
@@ -437,9 +437,29 @@
     private List<ContextHandler> getMatchingContexts(final WhiteboardServiceInfo<?> info)
     {
         final List<ContextHandler> result = new ArrayList<ContextHandler>();
-        for(final List<ContextHandler> handlerList : this.contextMap.values()) {
+        for(final List<ContextHandler> handlerList : this.contextMap.values())
+        {
             final ContextHandler h = handlerList.get(0);
-            if ( info.getContextSelectionFilter().match(h.getContextInfo().getServiceReference()) )
+            // check whether the servlet context helper is visible to the whiteboard bundle
+            // see chapter 140.2
+            boolean visible = h.getContextInfo().getServiceId() < 0; // internal ones are always visible
+            if ( !visible )
+            {
+                final String filterString = "(" + Constants.SERVICE_ID + "=" + String.valueOf(h.getContextInfo().getServiceId()) + ")";
+                try
+                {
+                    final Collection<ServiceReference<ServletContextHelper>> col = info.getServiceReference().getBundle().getBundleContext().getServiceReferences(ServletContextHelper.class, filterString);
+                    if ( !col.isEmpty() )
+                    {
+                        visible = true;
+                    }
+                }
+                catch ( final InvalidSyntaxException ise )
+                {
+                    // we ignore this and treat it as an invisible service
+                }
+            }
+            if ( visible && info.getContextSelectionFilter().match(h.getContextInfo().getServiceReference()) )
             {
                 result.add(h);
             }