incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r654077 - in /incubator/sling/trunk: jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/ sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ sling/servlet-resolver/src/test/java/org/apache/sling/...
Date Wed, 07 May 2008 12:04:06 GMT
Author: fmeschbe
Date: Wed May  7 05:04:05 2008
New Revision: 654077

URL: http://svn.apache.org/viewvc?rev=654077&view=rev
Log:
SLING-430 Handle empty/missing sling.servlet.methods property as if it would
be set to [ "GET", "HEAD" ] and support "*" to mean "all methods".
Add sling.servlet.methods="*" setting to SlingWebDavServlet

Added:
    incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/resource/ServletResourceProviderCreateTest.java
Modified:
    incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResourceProvider.java

Modified: incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java?rev=654077&r1=654076&r2=654077&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
(original)
+++ incubator/sling/trunk/jcr/webdav/src/main/java/org/apache/sling/jcr/webdav/impl/servlets/SlingWebDavServlet.java
Wed May  7 05:04:05 2008
@@ -49,6 +49,9 @@
  * @scr.property
  *  name="sling.servlet.resourceTypes"
  *  value="sling/servlet/default"
+ * @scr.property
+ *  name="sling.servlet.methods"
+ *  value="*"
  */
 public class SlingWebDavServlet extends AbstractSlingWebDavServlet {
 

Modified: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResourceProvider.java?rev=654077&r1=654076&r2=654077&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResourceProvider.java
(original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResourceProvider.java
Wed May  7 05:04:05 2008
@@ -34,6 +34,7 @@
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.servlets.HttpConstants;
 import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.osgi.framework.ServiceReference;
@@ -46,6 +47,11 @@
      */
     public static final String SERVLET_PATH_EXTENSION = ".servlet";
     
+    private static final String[] DEFAULT_SERVLET_METHODS = {
+        HttpConstants.METHOD_GET, HttpConstants.METHOD_HEAD };
+    
+    private static final String ALL_METHODS = "*";
+    
     private final Servlet servlet;
 
     private Set<String> resourcePaths;
@@ -86,12 +92,16 @@
 
         // we have types and expect extensions and/or methods
         String[] extensions = OsgiUtil.toStringArray(ref.getProperty(SLING_SERVLET_EXTENSIONS));
+        
+        // handle the methods property specially (SLING-430)
         String[] methods = OsgiUtil.toStringArray(ref.getProperty(SLING_SERVLET_METHODS));
-        // if ((extensions == null || extensions.length == 0)
-        // && (methods == null || methods.length == 0)) {
-        // // TODO: should log, why we ignore this servlet
-        // return null;
-        // }
+        if (methods == null || methods.length == 0) {
+            // TODO: should log
+            methods = DEFAULT_SERVLET_METHODS;
+        } else if (methods.length == 1 && ALL_METHODS.equals(methods[0])) {
+            // TODO: should log
+            methods = null;
+        }
 
         Set<String> pathSet = new HashSet<String>();
         for (String type : types) {

Added: incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/resource/ServletResourceProviderCreateTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/resource/ServletResourceProviderCreateTest.java?rev=654077&view=auto
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/resource/ServletResourceProviderCreateTest.java
(added)
+++ incubator/sling/trunk/sling/servlet-resolver/src/test/java/org/apache/sling/servlet/resolver/resource/ServletResourceProviderCreateTest.java
Wed May  7 05:04:05 2008
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.servlet.resolver.resource;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.servlet.GenericServlet;
+import javax.servlet.Servlet;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import junit.framework.TestCase;
+
+import org.apache.sling.api.servlets.HttpConstants;
+import org.apache.sling.commons.testing.osgi.MockServiceReference;
+import org.apache.sling.jcr.resource.JcrResourceUtil;
+import org.apache.sling.servlet.resolver.ServletResolverConstants;
+
+public class ServletResourceProviderCreateTest extends TestCase {
+
+    private static final Servlet TEST_SERVLET = new GenericServlet() {
+        @Override
+        public void service(ServletRequest req, ServletResponse res) {
+        }
+    };
+
+    private static final String ROOT = "/apps/";
+
+    private static final String RES_TYPE = "sling:sample";
+
+    private static final String RES_TYPE_PATH = JcrResourceUtil.resourceTypeToPath(RES_TYPE);
+
+    public void testCreateMethodsDefault() {
+        MockServiceReference msr = new MockServiceReference(null);
+
+        msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES,
+            RES_TYPE);
+        // msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "*");
+
+        ServletResourceProvider srp = ServletResourceProvider.create(msr,
+            TEST_SERVLET, ROOT);
+        assertNotNull(srp);
+
+        String[] paths = srp.getSerlvetPaths();
+        assertNotNull(paths);
+        assertEquals(2, paths.length);
+
+        Set<String> checkerSet = new HashSet<String>();
+        checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_GET
+            + ServletResourceProvider.SERVLET_PATH_EXTENSION);
+        checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_HEAD
+            + ServletResourceProvider.SERVLET_PATH_EXTENSION);
+
+        for (String path : paths) {
+            assertTrue(path + " not expected", checkerSet.remove(path));
+        }
+
+        assertTrue(checkerSet.isEmpty());
+    }
+
+    public void testCreateMethodsSingle() {
+        MockServiceReference msr = new MockServiceReference(null);
+
+        msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES,
+            RES_TYPE);
+        msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "GET");
+
+        ServletResourceProvider srp = ServletResourceProvider.create(msr,
+            TEST_SERVLET, ROOT);
+        assertNotNull(srp);
+
+        String[] paths = srp.getSerlvetPaths();
+        assertNotNull(paths);
+        assertEquals(1, paths.length);
+
+        Set<String> checkerSet = new HashSet<String>();
+        checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_GET
+            + ServletResourceProvider.SERVLET_PATH_EXTENSION);
+
+        for (String path : paths) {
+            assertTrue(path + " not expected", checkerSet.remove(path));
+        }
+
+        assertTrue(checkerSet.isEmpty());
+    }
+
+    public void testCreateMethodsMultiple() {
+        MockServiceReference msr = new MockServiceReference(null);
+
+        msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES,
+            RES_TYPE);
+        msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS,
+            new String[] { "GET", "POST", "PUT" });
+
+        ServletResourceProvider srp = ServletResourceProvider.create(msr,
+            TEST_SERVLET, ROOT);
+        assertNotNull(srp);
+
+        String[] paths = srp.getSerlvetPaths();
+        assertNotNull(paths);
+        assertEquals(3, paths.length);
+
+        Set<String> checkerSet = new HashSet<String>();
+        checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_GET
+            + ServletResourceProvider.SERVLET_PATH_EXTENSION);
+        checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_POST
+            + ServletResourceProvider.SERVLET_PATH_EXTENSION);
+        checkerSet.add(ROOT + RES_TYPE_PATH + "/" + HttpConstants.METHOD_PUT
+            + ServletResourceProvider.SERVLET_PATH_EXTENSION);
+
+        for (String path : paths) {
+            assertTrue(path + " not expected", checkerSet.remove(path));
+        }
+
+        assertTrue(checkerSet.isEmpty());
+    }
+
+    public void testCreateMethodsAll() {
+        MockServiceReference msr = new MockServiceReference(null);
+
+        msr.setProperty(ServletResolverConstants.SLING_SERVLET_RESOURCE_TYPES,
+            RES_TYPE);
+        msr.setProperty(ServletResolverConstants.SLING_SERVLET_METHODS, "*");
+
+        ServletResourceProvider srp = ServletResourceProvider.create(msr,
+            TEST_SERVLET, ROOT);
+        assertNotNull(srp);
+
+        String[] paths = srp.getSerlvetPaths();
+        assertNotNull(paths);
+        assertEquals(1, paths.length);
+
+        Set<String> checkerSet = new HashSet<String>();
+        checkerSet.add(ROOT + RES_TYPE_PATH
+            + ServletResourceProvider.SERVLET_PATH_EXTENSION);
+
+        for (String path : paths) {
+            assertTrue(path + " not expected", checkerSet.remove(path));
+        }
+
+        assertTrue(checkerSet.isEmpty());
+    }
+
+}



Mime
View raw message