You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2015/11/23 13:40:41 UTC

svn commit: r1715792 - /sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java

Author: cziegeler
Date: Mon Nov 23 12:40:40 2015
New Revision: 1715792

URL: http://svn.apache.org/viewvc?rev=1715792&view=rev
Log:
SLING-5219 : Mounting a ResourceProvider makes it impossible to create child resources under it. Apply modified patch from Mikolaj Manski

Modified:
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java?rev=1715792&r1=1715791&r2=1715792&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java (original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/AbstractCreateOperation.java Mon Nov 23 12:40:40 2015
@@ -31,7 +31,6 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.nodetype.NodeType;
-import javax.servlet.ServletException;
 
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.request.RequestParameter;
@@ -53,7 +52,7 @@ import org.apache.sling.servlets.post.im
 
 abstract class AbstractCreateOperation extends AbstractPostOperation {
     private final Random randomCollisionIndex = new Random();
-    
+
     /**
      * The default node name generator
      */
@@ -102,9 +101,9 @@ abstract class AbstractCreateOperation e
     throws PersistenceException, RepositoryException {
 
         final String path = response.getPath();
+        final Resource resource = resolver.getResource(path);
 
-        if ( resolver.getResource(path) == null ) {
-
+        if ( resource == null || ResourceUtil.isSyntheticResource(resource) ) {
             deepGetOrCreateNode(resolver, path, reqProperties, changes, versioningConfiguration);
             response.setCreateRequest(true);
 
@@ -523,16 +522,19 @@ abstract class AbstractCreateOperation e
                 if (startingResource == null){
                 	throw new PersistenceException("Access denied for root resource, resource can't be created: " + path);
                 }
-            } else if (resolver.getResource(startingResourcePath) != null) {
-                startingResource = resolver.getResource(startingResourcePath);
-                updateNodeType(resolver, startingResourcePath, reqProperties, changes, versioningConfiguration);
-                updateMixins(resolver, startingResourcePath, reqProperties, changes, versioningConfiguration);
             } else {
-                int pos = startingResourcePath.lastIndexOf('/');
-                if (pos > 0) {
-                    startingResourcePath = startingResourcePath.substring(0, pos);
+                final Resource r = resolver.getResource(startingResourcePath);
+                if ( r != null && !ResourceUtil.isSyntheticResource(r)) {
+                    startingResource = resolver.getResource(startingResourcePath);
+                    updateNodeType(resolver, startingResourcePath, reqProperties, changes, versioningConfiguration);
+                    updateMixins(resolver, startingResourcePath, reqProperties, changes, versioningConfiguration);
                 } else {
-                    startingResourcePath = "/";
+                    int pos = startingResourcePath.lastIndexOf('/');
+                    if (pos > 0) {
+                        startingResourcePath = startingResourcePath.substring(0, pos);
+                    } else {
+                        startingResourcePath = "/";
+                    }
                 }
             }
         }
@@ -552,8 +554,9 @@ abstract class AbstractCreateOperation e
             // although the resource should not exist (according to the first test
             // above)
             // we do a sanety check.
-            if (resource.getChild(name) != null) {
-                resource = resource.getChild(name);
+            final Resource child = resource.getChild(name);
+            if (child != null && !ResourceUtil.isSyntheticResource(child)) {
+                resource = child;
                 updateNodeType(resolver, resource.getPath(), reqProperties, changes, versioningConfiguration);
                 updateMixins(resolver, resource.getPath(), reqProperties, changes, versioningConfiguration);
             } else {
@@ -693,7 +696,7 @@ abstract class AbstractCreateOperation e
 		            break;
 		        }
 		    }
-		    
+
 	        // Give up after MAX_TRIES
 	        if (resolver.getResource(jcrPath) != null ) {
 	            throw new RepositoryException(