wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r935254 - in /incubator/wink/trunk/wink-server/src: main/java/org/apache/wink/server/internal/handlers/ main/java/org/apache/wink/server/internal/registry/ test/java/org/apache/wink/server/internal/
Date Sat, 17 Apr 2010 20:38:18 GMT
Author: bluk
Date: Sat Apr 17 20:38:18 2010
New Revision: 935254

URL: http://svn.apache.org/viewvc?rev=935254&view=rev
Log:
Update UriTemplateProcessor encoding

Remove the need to do multiple passes
of UriHelper.normalizeUri() since an
initial pass is made in UriInfoImpl#
buildRequestPath which is called
per request.

This should also fix [WINK-216].

Modified:
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
    incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java?rev=935254&r1=935253&r2=935254&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/handlers/FindResourceMethodHandler.java
Sat Apr 17 20:38:18 2010
@@ -31,7 +31,6 @@ import javax.ws.rs.core.Response.Status;
 
 import org.apache.wink.common.internal.registry.metadata.MethodMetadata;
 import org.apache.wink.common.internal.uritemplate.UriTemplateMatcher;
-import org.apache.wink.common.internal.uritemplate.UriTemplateProcessor;
 import org.apache.wink.server.handlers.HandlersChain;
 import org.apache.wink.server.handlers.MessageContext;
 import org.apache.wink.server.handlers.RequestHandler;
@@ -69,7 +68,13 @@ public class FindResourceMethodHandler i
 
         // sub-resource method or locator
         UriTemplateMatcher templateMatcher = resource.getMatcher();
-        String tail = UriTemplateProcessor.normalizeUri(templateMatcher.getTail(false));
+        String tail = templateMatcher.getTail(false);
+        if (tail == null) {
+            tail = ""; //$NON-NLS-1$
+        }
+        if (tail.startsWith("/")) { //$NON-NLS-1$
+            tail = tail.substring(1);
+        }
         logger.debug("Unmatched tail to the URI: {}", tail); //$NON-NLS-1$
 
         // get a sorted list of all the sub-resources (methods and locators)

Modified: incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java?rev=935254&r1=935253&r2=935254&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
(original)
+++ incubator/wink/trunk/wink-server/src/main/java/org/apache/wink/server/internal/registry/ResourceRegistry.java
Sat Apr 17 20:38:18 2010
@@ -258,9 +258,14 @@ public class ResourceRegistry {
      */
     public List<ResourceInstance> getMatchingRootResources(String uri,
                                                            boolean isContinuedSearchPolicy)
{
-        ArrayList<ResourceInstance> found = new ArrayList<ResourceInstance>(1);
-        uri = UriTemplateProcessor.normalizeUri(uri);
+        if (uri == null) {
+            uri = ""; //$NON-NLS-1$
+        }
+        if (uri.startsWith("/")) { //$NON-NLS-1$
+            uri = uri.substring(1);
+        }
 
+        ArrayList<ResourceInstance> found = new ArrayList<ResourceInstance>(1);
         ArrayList<ResourceRecord> previousMatched = null;
         /*
          * the previous matches are cached so if a previous URI used is still in

Modified: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java?rev=935254&r1=935253&r2=935254&view=diff
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java
(original)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java
Sat Apr 17 20:38:18 2010
@@ -39,7 +39,58 @@ public class EmptyPathParamTest extends 
 
     @Override
     protected Class<?>[] getClasses() {
-        return new Class[] {PathResource.class, PathResource2.class, PathResource3.class};
+        return new Class[] {PathResource.class, PathResource2.class, PathResource3.class,
+            MultipleSegmentsInRoot.class, EncodedPathSegments.class, InRootPathSegments.class};
+    }
+
+    @Path("all/in/root")
+    public static class MultipleSegmentsInRoot {
+        @GET
+        @Path("/first/{firstParams:.*}/second/{secondParams:.*}")
+        @Produces(MediaType.TEXT_PLAIN)
+        public String findTestRuns(@PathParam("firstParams") final PathSegment firstParams,
+                                   @PathParam("secondParams") final PathSegment secondParams)
{
+
+            assertEquals("", firstParams.getPath());
+            assertEquals("bob", firstParams.getMatrixParameters().get("name").get(0));
+            assertEquals("", secondParams.getPath());
+            assertEquals("blue", secondParams.getMatrixParameters().get("eyes").get(0));
+            return "hi2";
+
+        }
+    }
+
+    @Path("%21/more")
+    public static class EncodedPathSegments {
+        @GET
+        @Path("/first/{firstParams:.*}/second/{secondParams:.*}")
+        @Produces(MediaType.TEXT_PLAIN)
+        public String findTestRuns(@PathParam("firstParams") final PathSegment firstParams,
+                                   @PathParam("secondParams") final PathSegment secondParams)
{
+
+            assertEquals("", firstParams.getPath());
+            assertEquals("bob", firstParams.getMatrixParameters().get("name").get(0));
+            assertEquals("", secondParams.getPath());
+            assertEquals("blue", secondParams.getMatrixParameters().get("eyes").get(0));
+            return "hi2";
+
+        }
+    }
+
+    @Path("inroot/first/{firstParams:.*}/second/{secondParams:.*}")
+    public static class InRootPathSegments {
+        @GET
+        @Produces(MediaType.TEXT_PLAIN)
+        public String findTestRuns(@PathParam("firstParams") final PathSegment firstParams,
+                                   @PathParam("secondParams") final PathSegment secondParams)
{
+
+            assertEquals("", firstParams.getPath());
+            assertEquals("bob", firstParams.getMatrixParameters().get("name").get(0));
+            assertEquals("", secondParams.getPath());
+            assertEquals("blue", secondParams.getMatrixParameters().get("eyes").get(0));
+            return "hi2";
+
+        }
     }
 
     @Path("/p")
@@ -70,9 +121,9 @@ public class EmptyPathParamTest extends 
         public String findTestRuns(@PathParam("firstParams") final PathSegment firstParams,
                                    @PathParam("secondParams") final PathSegment secondParams)
{
 
-            assertEquals("first", firstParams.getPath());
+            assertEquals("", firstParams.getPath());
             assertEquals("bob", firstParams.getMatrixParameters().get("name").get(0));
-            assertEquals("second", secondParams.getPath());
+            assertEquals("", secondParams.getPath());
             assertEquals("blue", secondParams.getMatrixParameters().get("eyes").get(0));
             return "hi2";
 
@@ -108,10 +159,7 @@ public class EmptyPathParamTest extends 
         assertEquals("hi", getResponse.getContentAsString());
     }
 
-    public void _testEmptyPathParam2() throws Exception { // TODO: see WINK-216
-                                                          // - need to enable
-                                                          // this test AND fix
-                                                          // production code
+    public void testEmptyPathParam2() throws Exception {
         MockHttpServletRequest getRequest =
             MockRequestConstructor.constructMockRequest("GET",
                                                         "/p2/first/;name=bob/second/;eyes=blue",
@@ -119,6 +167,15 @@ public class EmptyPathParamTest extends 
         MockHttpServletResponse getResponse = invoke(getRequest);
         assertEquals(200, getResponse.getStatus());
         assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/p2/first/../first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
     }
 
     public void testEmptyPathParam3() throws Exception {
@@ -130,4 +187,126 @@ public class EmptyPathParamTest extends 
         assertEquals(200, getResponse.getStatus());
         assertEquals("hi3", getResponse.getContentAsString());
     }
+
+    public void testMultipleSegmentsInRoot() throws Exception {
+        MockHttpServletRequest getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/all/in/root/first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        MockHttpServletResponse getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/all///in////root///first///;name=bob///second///;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/all/../all/in/root/first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/all/../all/in/root/first/../first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/all/../all/in/root/first/../first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/all/../all/in/root/first%21/../first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+    }
+
+    public void testEncodedPathSegments() throws Exception {
+        MockHttpServletRequest getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/%21/more/first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        MockHttpServletResponse getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+    }
+
+    public void testInRootPathSegment() throws Exception {
+        MockHttpServletRequest getRequest =
+            MockRequestConstructor.constructMockRequest("GET",
+                                                        "inroot/first/;name=bob/second/;eyes=blue",
+                                                        MediaType.TEXT_PLAIN);
+        MockHttpServletResponse getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/inroot///first///;name=bob///second///;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/inroot/../inroot/first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/inroot///..////inroot/first/../first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/abcdefg/../inroot/first/../first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+
+        getRequest =
+            MockRequestConstructor
+                .constructMockRequest("GET",
+                                      "/inroot/../inroot/first%21/../first/;name=bob/second/;eyes=blue",
+                                      MediaType.TEXT_PLAIN);
+        getResponse = invoke(getRequest);
+        assertEquals(200, getResponse.getStatus());
+        assertEquals("hi2", getResponse.getContentAsString());
+    }
 }



Mime
View raw message