You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wink.apache.org by bl...@apache.org on 2009/10/09 21:49:21 UTC

svn commit: r823671 - in /incubator/wink/trunk: wink-common/src/main/java/org/apache/wink/common/internal/uritemplate/UriTemplateMatcher.java wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java

Author: bluk
Date: Fri Oct  9 19:49:21 2009
New Revision: 823671

URL: http://svn.apache.org/viewvc?rev=823671&view=rev
Log:
Tolerate empty @PathParam segments

See [WINK-214]

Thanks Mike Rheinheimer for the fix and
Jaroslav Libak for reporting the issue.

Added:
    incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java   (with props)
Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/uritemplate/UriTemplateMatcher.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/uritemplate/UriTemplateMatcher.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/uritemplate/UriTemplateMatcher.java?rev=823671&r1=823670&r2=823671&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/uritemplate/UriTemplateMatcher.java (original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/uritemplate/UriTemplateMatcher.java Fri Oct  9 19:49:21 2009
@@ -442,6 +442,11 @@
                         }
                         break L1; // found all the segments of this variable
                                   // value
+                    } else if (variableValueStartIndex == pathLength) {
+                        // no PathParam was provided... only matrix params or empty
+                        // just use what we have
+                        variableSegments.add(segments.get(segmentIndex));
+                        break L1;
                     } else {
                         pathLength += 1; // to count for the '/' between the
                                          // segments

Added: 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=823671&view=auto
==============================================================================
--- incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java (added)
+++ incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java Fri Oct  9 19:49:21 2009
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * 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.wink.server.internal;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
+
+import org.apache.wink.server.internal.servlet.MockServletInvocationTest;
+import org.apache.wink.test.mock.MockRequestConstructor;
+import org.springframework.mock.web.MockHttpServletRequest;
+import org.springframework.mock.web.MockHttpServletResponse;
+
+/**
+ * Test parameter conversion.
+ */
+public class EmptyPathParamTest extends MockServletInvocationTest {
+
+    @Override
+    protected Class<?>[] getClasses() {
+        return new Class[] {PathResource.class};
+    }
+
+    @Path("/p")
+    public static class PathResource {
+
+        @GET
+        @Path("/first{firstParams:.*}/second{secondParams:.*}")
+        @Produces(MediaType.TEXT_PLAIN)
+        public String findTestRuns(@PathParam("firstParams") final PathSegment firstParams, @PathParam("secondParams") final PathSegment secondParams) {
+
+            assertEquals("first", firstParams.getPath());
+            assertEquals("bob", firstParams.getMatrixParameters().get("name").get(0));
+            assertEquals("second", secondParams.getPath());
+            assertEquals("blue", secondParams.getMatrixParameters().get("eyes").get(0));
+            return "hi";
+
+        }
+
+    }
+    
+    public void testMatrixParamsOnly() throws Exception {
+        MockHttpServletRequest getRequest =
+            MockRequestConstructor.constructMockRequest("GET", "/p/first;name=bob/second;eyes=blue", "*/*");
+        MockHttpServletResponse getResponse = invoke(getRequest);
+        assertEquals(getResponse.getContentAsString(), "hi");
+    }
+
+
+
+}

Propchange: incubator/wink/trunk/wink-server/src/test/java/org/apache/wink/server/internal/EmptyPathParamTest.java
------------------------------------------------------------------------------
    svn:eol-style = native