You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fg...@apache.org on 2010/01/08 17:12:33 UTC

svn commit: r897245 - in /incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src: main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java

Author: fguillaume
Date: Fri Jan  8 16:12:25 2010
New Revision: 897245

URL: http://svn.apache.org/viewvc?rev=897245&view=rev
Log:
Make sure the path passed through JAX-RS is kept intact

Modified:
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
    incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java?rev=897245&r1=897244&r2=897245&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/main/java/org/apache/chemistry/atompub/server/jaxrs/AbderaResource.java Fri Jan  8 16:12:25 2010
@@ -324,7 +324,11 @@
     @Produces(AtomPub.MEDIA_TYPE_ATOM_ENTRY)
     @Path("path/{path:.*}")
     public Response doGetObjectByPath(@Encoded @PathParam("path") String path) {
-        int skipSegments = 2;
+        // don't use the path argument but refetch it from the UriInfo
+        // to ensure that an initial slash isn't swallowed, which is important
+        // for the later segments count used in getRequestContext
+        path = ui.getPathParameters(false).get("path").get(0);
+        int skipSegments = 2; //
         for (int i = 0; i < path.length(); i++) {
             if (path.charAt(i) == '/') {
                 skipSegments++;

Modified: incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java
URL: http://svn.apache.org/viewvc/incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java?rev=897245&r1=897244&r2=897245&view=diff
==============================================================================
--- incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java (original)
+++ incubator/chemistry/trunk/chemistry/chemistry-atompub-server/src/test/java/org/apache/chemistry/atompub/server/AtomPubServerTestCase.java Fri Jan  8 16:12:25 2010
@@ -276,13 +276,35 @@
     }
 
     public void testGetObjectByPath() {
-        ClientResponse resp = client.get(base + "/path/folder1/folder2/doc3");
+        String path = "/folder1/folder2/doc3";
+
+        // URL-encoded (what a compliant client using the URI template does)
+        ClientResponse resp = client.get(base + "/path/"
+                + path.replace("/", "%2F"));
         assertEquals(HttpStatus.SC_OK, resp.getStatus());
         Element ob = resp.getDocument().getRoot();
         assertNotNull(ob);
         Element id = ob.getFirstChild(new QName(AtomPub.ATOM_NS, "id"));
         assertEquals("urn:uuid:" + doc3id, id.getText());
         resp.release();
+
+        // unencoded, single slash
+        resp = client.get(base + "/path" + path);
+        assertEquals(HttpStatus.SC_OK, resp.getStatus());
+        ob = resp.getDocument().getRoot();
+        assertNotNull(ob);
+        id = ob.getFirstChild(new QName(AtomPub.ATOM_NS, "id"));
+        assertEquals("urn:uuid:" + doc3id, id.getText());
+        resp.release();
+
+        // unencoded, double slash
+        resp = client.get(base + "/path/" + path);
+        assertEquals(HttpStatus.SC_OK, resp.getStatus());
+        ob = resp.getDocument().getRoot();
+        assertNotNull(ob);
+        id = ob.getFirstChild(new QName(AtomPub.ATOM_NS, "id"));
+        assertEquals("urn:uuid:" + doc3id, id.getText());
+        resp.release();
     }
 
     public void testDelete() {