Return-Path: Delivered-To: apmail-incubator-sling-commits-archive@locus.apache.org Received: (qmail 90462 invoked from network); 10 Dec 2007 20:53:24 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Dec 2007 20:53:24 -0000 Received: (qmail 83896 invoked by uid 500); 10 Dec 2007 20:53:13 -0000 Delivered-To: apmail-incubator-sling-commits-archive@incubator.apache.org Received: (qmail 83870 invoked by uid 500); 10 Dec 2007 20:53:13 -0000 Mailing-List: contact sling-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: sling-dev@incubator.apache.org Delivered-To: mailing list sling-commits@incubator.apache.org Received: (qmail 83860 invoked by uid 99); 10 Dec 2007 20:53:13 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Dec 2007 12:53:13 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Dec 2007 20:53:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 4AEDE1A983A; Mon, 10 Dec 2007 12:53:03 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r603042 - in /incubator/sling/trunk/microsling/microsling-core/src: main/java/org/apache/sling/microsling/resource/ test/java/org/apache/sling/microsling/integration/ test/java/org/apache/sling/microsling/resource/ Date: Mon, 10 Dec 2007 20:52:47 -0000 To: sling-commits@incubator.apache.org From: bdelacretaz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071210205303.4AEDE1A983A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bdelacretaz Date: Mon Dec 10 12:52:36 2007 New Revision: 603042 URL: http://svn.apache.org/viewvc?rev=603042&view=rev Log: SLING-117 - do not go up the path when resolving Resources for GET or HEAD requests Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GetWithSuffixTest.java (with props) Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java?rev=603042&r1=603041&r2=603042&view=diff ============================================================================== --- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java (original) +++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java Mon Dec 10 12:52:36 2007 @@ -102,18 +102,22 @@ /** * Resolves the Resource from the request */ - public Resource resolve(ServletRequest request) throws SlingException { + public Resource resolve(ServletRequest servletRequest) throws SlingException { Resource result = null; String path = null; // look for a real JCR Resource - String pathInfo = SlingRequestPaths.getPathInfo((HttpServletRequest)request); + final HttpServletRequest request = (HttpServletRequest)servletRequest; + String pathInfo = SlingRequestPaths.getPathInfo(request); try { Session session = getSession(); - final ResourcePathIterator it = new ResourcePathIterator(pathInfo); + final ResourcePathIterator it = new ResourcePathIterator(pathInfo,request.getMethod()); + String resolutionPath = ""; while (it.hasNext() && result == null) { - result = getResource(session, it.next()); + resolutionPath = it.next(); + result = getResource(session, resolutionPath); } + } catch (RepositoryException re) { throw new SlingException("RepositoryException for path=" + path, re); } Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java?rev=603042&r1=603041&r2=603042&view=diff ============================================================================== --- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java (original) +++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/ResourcePathIterator.java Mon Dec 10 12:52:36 2007 @@ -39,13 +39,21 @@ * /some * * + * + * The above rules are not valid for GET or HEAD requests, where + * we do not go up the path: for those requests, the path is + * only split at dots that follow the last slash */ class ResourcePathIterator implements Iterator { private String nextPath; + private final String httpMethod; + private final int lastSlashPos; - ResourcePathIterator(String path) { + ResourcePathIterator(String path,String httpMethod) { nextPath = path; + this.httpMethod = httpMethod; + lastSlashPos = (path == null ? -1 : path.lastIndexOf('/')); } public boolean hasNext() { @@ -54,7 +62,19 @@ public String next() { final String result = nextPath; - final int pos = Math.max(result.lastIndexOf('.'),result.lastIndexOf('/')); + + int pos = -1; + if("GET".equals(httpMethod) || "HEAD".equals(httpMethod)) { + // SLING-117: for GET and POST, do not go up the path to resolve resources, + // only split at dots that follow the last slash + pos = result.lastIndexOf('.'); + if(pos < lastSlashPos) { + pos = -1; + } + } else { + pos = Math.max(result.lastIndexOf('.'),result.lastIndexOf('/')); + } + if(pos < 0) { nextPath = null; } else { Modified: incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java?rev=603042&r1=603041&r2=603042&view=diff ============================================================================== --- incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java (original) +++ incubator/sling/trunk/microsling/microsling-core/src/main/java/org/apache/sling/microsling/resource/SyntheticResourceProvider.java Mon Dec 10 12:52:36 2007 @@ -56,7 +56,9 @@ Resource getSyntheticResource(String pathInfo) { Resource result = null; - final ResourcePathIterator it = new ResourcePathIterator(pathInfo); + // for synthetic resources, the ResourcePathIterator must go up the path + // like for POST methods, even if the actual method is a GET + final ResourcePathIterator it = new ResourcePathIterator(pathInfo,"POST"); while (it.hasNext() && result == null) { final String path = it.next(); for(Pattern p : pathPattern) { Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GetWithSuffixTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GetWithSuffixTest.java?rev=603042&view=auto ============================================================================== --- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GetWithSuffixTest.java (added) +++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GetWithSuffixTest.java Mon Dec 10 12:52:36 2007 @@ -0,0 +1,80 @@ +/* + * 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.microsling.integration; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +/** GET requests with a suffix should fail with a 404, otherwise + * we get a lot of extra possible URLs which point to the same + * content. + */ +public class GetWithSuffixTest extends RenderingTestBase { + + @Override + protected void setUp() throws Exception { + super.setUp(); + + // set test values + testText = "This is a test " + System.currentTimeMillis(); + + // create the test node, under a path that's specific to this class to allow collisions + final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "." + System.currentTimeMillis(); + final Map props = new HashMap(); + props.put("text", testText); + displayUrl = testClient.createNode(url, props); + + // the rendering script goes under /sling/scripts in the repository + scriptPath = "/sling/scripts/nt/unstructured"; + testClient.mkdirs(WEBDAV_BASE_URL, scriptPath); + } + + public void testWithExactUrl() throws IOException { + final String toDelete = uploadTestScript("rendering-test.esp","html.esp"); + try { + final String content = getContent(displayUrl + ".html", CONTENT_TYPE_HTML); + assertTrue("Content includes ESP marker",content.contains("ESP template")); + assertTrue("Content contains formatted test text",content.contains("

" + testText + "

")); + } finally { + testClient.delete(toDelete); + } + } + + public void testWithExtraPathA() throws IOException { + final String toDelete = uploadTestScript("rendering-test.esp","html.esp"); + try { + assertHttpStatus(displayUrl + "/extra.html", HttpServletResponse.SC_NOT_FOUND); + } finally { + testClient.delete(toDelete); + } + } + + /** behavior seems slightly different if using GET.esp vs. html.esp for the + * script name, verify that both give a 404 + */ + public void testWithExtraPathB() throws IOException { + final String toDelete = uploadTestScript("rendering-test.esp","GET.esp"); + try { + assertHttpStatus(displayUrl + "/extra/more.a4.html", HttpServletResponse.SC_NOT_FOUND); + } finally { + testClient.delete(toDelete); + } + } +} Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GetWithSuffixTest.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/GetWithSuffixTest.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Rev URL Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java?rev=603042&r1=603041&r2=603042&view=diff ============================================================================== --- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java (original) +++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/resource/ResourcePathIteratorTest.java Mon Dec 10 12:52:36 2007 @@ -24,43 +24,46 @@ public class ResourcePathIteratorTest extends TestCase { + public final static String GET = "GET"; + public final static String POST = "POST"; + public void testNullInput() { - final Iterator it = new ResourcePathIterator(null); + final Iterator it = new ResourcePathIterator(null,POST); assertFalse(it.hasNext()); } public void testEmptyInput() { - final Iterator it = new ResourcePathIterator(""); - assertFalse(it.hasNext()); + final Iterator it = new ResourcePathIterator("",POST); + assertFalse("done iterating", it.hasNext()); } public void testNoSeparators() { - final Iterator it = new ResourcePathIterator("MickeyMouseWasHere"); + final Iterator it = new ResourcePathIterator("MickeyMouseWasHere",POST); assertTrue(it.hasNext()); assertEquals("MickeyMouseWasHere",it.next()); - assertFalse(it.hasNext()); + assertFalse("done iterating", it.hasNext()); } public void testSlashOnly() { - final Iterator it = new ResourcePathIterator("/MickeyMouseWasHere/ok"); + final Iterator it = new ResourcePathIterator("/MickeyMouseWasHere/ok",POST); assertTrue(it.hasNext()); assertEquals("/MickeyMouseWasHere/ok",it.next()); assertTrue(it.hasNext()); assertEquals("/MickeyMouseWasHere",it.next()); - assertFalse(it.hasNext()); + assertFalse("done iterating", it.hasNext()); } public void testDotOnly() { - final Iterator it = new ResourcePathIterator("MickeyMouseWasHere.ok"); + final Iterator it = new ResourcePathIterator("MickeyMouseWasHere.ok",POST); assertTrue(it.hasNext()); assertEquals("MickeyMouseWasHere.ok",it.next()); assertTrue(it.hasNext()); assertEquals("MickeyMouseWasHere",it.next()); - assertFalse(it.hasNext()); + assertFalse("done iterating", it.hasNext()); } public void testRealisticPath() { - final Iterator it = new ResourcePathIterator("/some/stuff.print.a4/more"); + final Iterator it = new ResourcePathIterator("/some/stuff.print.a4/more",POST); assertTrue(it.hasNext()); assertEquals("/some/stuff.print.a4/more",it.next()); assertTrue(it.hasNext()); @@ -71,17 +74,53 @@ assertEquals("/some/stuff",it.next()); assertTrue(it.hasNext()); assertEquals("/some",it.next()); - assertFalse(it.hasNext()); + assertFalse("done iterating", it.hasNext()); + } + + public void testGetA() { + final Iterator it = new ResourcePathIterator("/some/stuff/more.a4.html",GET); + assertTrue(it.hasNext()); + assertEquals("/some/stuff/more.a4.html",it.next()); + assertTrue(it.hasNext()); + assertEquals("/some/stuff/more.a4",it.next()); + assertTrue(it.hasNext()); + assertEquals("/some/stuff/more",it.next()); + assertFalse("done iterating", it.hasNext()); + } + + public void testGetB() { + final Iterator it = new ResourcePathIterator("/some/stuff/more.html",GET); + assertTrue(it.hasNext()); + assertEquals("/some/stuff/more.html",it.next()); + assertTrue(it.hasNext()); + assertEquals("/some/stuff/more",it.next()); + assertFalse("done iterating", it.hasNext()); + } + + public void testGetC() { + final Iterator it = new ResourcePathIterator("/some/stuff/more",GET); + assertTrue(it.hasNext()); + assertEquals("/some/stuff/more",it.next()); + assertFalse("done iterating", it.hasNext()); + } + + public void testGetD() { + final Iterator it = new ResourcePathIterator("/some/stuff.print/more.html",GET); + assertTrue(it.hasNext()); + assertEquals("/some/stuff.print/more.html",it.next()); + assertTrue(it.hasNext()); + assertEquals("/some/stuff.print/more",it.next()); + assertFalse("done iterating", it.hasNext()); } public void testRelativePath() { - final Iterator it = new ResourcePathIterator("some/stuff.print"); + final Iterator it = new ResourcePathIterator("some/stuff.print",POST); assertTrue(it.hasNext()); assertEquals("some/stuff.print",it.next()); assertTrue(it.hasNext()); assertEquals("some/stuff",it.next()); assertTrue(it.hasNext()); assertEquals("some",it.next()); - assertFalse(it.hasNext()); + assertFalse("done iterating", it.hasNext()); } }