Hello,

I tried to build the Apache Sling project but the build always fails within the "Apache Sling Launchpad Testing" project. The reason for that failure are two tests regarding the dynamic namespace mapping NamespaceMappingTest#testNamespaceFromNamespaceMapper and NamespaceMappingTest#testNamespaceFromNamespaceMapperWithImpersonation. A closer look to the failing code it reveals that within the class org.apache.sling.jcr.jackrabbit.server.impl.SlingServerRepositoryManager the bind method for the namespace service references is accessing the ComponentContext set by the activate method but unfortunately that is incorrect because the Declarative Services Specification Version 1.1 - section 112.5.6 states that the binding happens before the activation. So the attempt to bind the TestNamespaceMapper Service to the SlingServerRepositoryManager always results in a NPE.

After I changed the service binding slightly the TestNamespaceMapper can be called. See the attached patch.

Regards,
Stefan
Index: launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/TestNamespaceMapper.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/TestNamespaceMapper.java	(date 1393419447000)
+++ launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/jcr/TestNamespaceMapper.java	(revision )
@@ -39,7 +39,7 @@
 public class TestNamespaceMapper implements NamespaceMapper {
 
     public void defineNamespacePrefixes(Session session) throws RepositoryException {
-        session.setNamespacePrefix("test2", "test2=http://sling.apache.org/test/two";);
+        session.setNamespacePrefix("test2", "http://sling.apache.org/test/two";);
     }
 
 }
Index: bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepositoryManager.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepositoryManager.java	(date 1393419447000)
+++ bundles/jcr/jackrabbit-server/src/main/java/org/apache/sling/jcr/jackrabbit/server/impl/SlingServerRepositoryManager.java	(revision )
@@ -27,8 +27,9 @@
 import java.net.URL;
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
-import java.util.TreeMap;
 import java.util.concurrent.ConcurrentHashMap;
 
 import javax.jcr.Repository;
@@ -57,7 +58,6 @@
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
 import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
@@ -137,7 +137,7 @@
 
     private Map<String, ServiceRegistration> statisticsServices = new ConcurrentHashMap<String, ServiceRegistration>();
 
-    private Map<ServiceReference, NamespaceMapper> namespaceMapperRefs = new TreeMap<ServiceReference, NamespaceMapper>();
+    private List<NamespaceMapper> namespaceMapperRefs = new LinkedList<NamespaceMapper>();
 
     // ---------- Repository Management ----------------------------------------
 
@@ -358,21 +358,20 @@
     }
 
     @SuppressWarnings("unused")
-    private void bindNamespaceMapper(final ServiceReference ref) {
+    private void bindNamespaceMapper(final NamespaceMapper namespaceMapper) {
         synchronized (this.namespaceMapperRefs) {
-            this.namespaceMapperRefs.put(ref,
-                (NamespaceMapper) this.getComponentContext().locateService("namespaceMapper", ref));
-            this.namespaceMappers = this.namespaceMapperRefs.values().toArray(
-                new NamespaceMapper[this.namespaceMapperRefs.values().size()]);
+            this.namespaceMapperRefs.add(namespaceMapper);
+            this.namespaceMappers = this.namespaceMapperRefs.toArray(
+                new NamespaceMapper[this.namespaceMapperRefs.size()]);
         }
     }
 
     @SuppressWarnings("unused")
-    private void unbindNamespaceMapper(final ServiceReference ref) {
+    private void unbindNamespaceMapper(final NamespaceMapper namespaceMapper) {
         synchronized (this.namespaceMapperRefs) {
-            this.namespaceMapperRefs.remove(ref);
-            this.namespaceMappers = this.namespaceMapperRefs.values().toArray(
-                new NamespaceMapper[this.namespaceMapperRefs.values().size()]);
+            this.namespaceMapperRefs.remove(namespaceMapper);
+            this.namespaceMappers = this.namespaceMapperRefs.toArray(
+                new NamespaceMapper[this.namespaceMapperRefs.size()]);
         }
     }
 

Reply via email to