cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1042347 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Date Sun, 05 Dec 2010 13:20:07 GMT
Author: sergeyb
Date: Sun Dec  5 13:20:07 2010
New Revision: 1042347

URL: http://svn.apache.org/viewvc?rev=1042347&view=rev
Log:
Merged revisions 1042346 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1042346 | sergeyb | 2010-12-05 13:10:12 +0000 (Sun, 05 Dec 2010) | 1 line
  
  [CXF-3166] Ignoring empty and null values during UriTemplate matches
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Sun Dec  5 13:20:07 2010
@@ -1 +1 @@
-/cxf/trunk:1041183,1041790,1041993
+/cxf/trunk:1041183,1041790,1041993,1042346

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=1042347&r1=1042346&r2=1042347&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
Sun Dec  5 13:20:07 2010
@@ -168,16 +168,23 @@ public final class URITemplate {
         }
 
         // Assign the matched template values to template variables
+        int groupCount = m.groupCount();
+        
         int i = 1;
         for (String name : variables) {
-            String value = m.group(i++);
-            templateVariableToValue.add(name, value);
+            while (i <= groupCount) {
+                String value = m.group(i++);
+                if (value == null || value.length() == 0) {
+                    continue;
+                }
+                templateVariableToValue.add(name, value);
+                break;
+            }
         }
         // The right hand side value, might be used to further resolve
         // sub-resources.
-        int groupCount = m.groupCount();
         
-        String finalGroup = m.group(groupCount);
+        String finalGroup = i > groupCount ? "/" : m.group(groupCount);
         templateVariableToValue.putSingle(FINAL_MATCH_GROUP, finalGroup == null ? "/" : finalGroup);
 
         return true;

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=1042347&r1=1042346&r2=1042347&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Sun Dec  5 13:20:07 2010
@@ -271,6 +271,58 @@ public class URITemplateTest extends Ass
     }
 
     @Test
+    public void testExpressionWithNestedGroupAndTwoVars() throws Exception {
+        URITemplate uriTemplate = new URITemplate("/foo/{bar}/{resource:.+\\.(js|css|gif|png)}");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+
+        assertTrue(uriTemplate.match("/foo/1/script.js", values));
+        assertEquals("1", values.getFirst("bar"));
+        assertEquals("script.js", values.getFirst("resource"));
+        String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/", finalPath);
+    }
+    
+    @Test
+    public void testExpressionWithNestedGroupAndTwoVars2() throws Exception {
+        URITemplate uriTemplate = new URITemplate("/foo/{bar}{resource:(/format/[^/]+?)?}");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+
+        assertTrue(uriTemplate.match("/foo/1/format", values));
+        assertEquals("1", values.getFirst("bar"));
+        assertEquals("/format", values.getFirst("resource"));
+        String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/", finalPath);
+        values.clear();
+        
+        assertTrue(uriTemplate.match("/foo/1/format/2", values));
+        assertEquals("1", values.getFirst("bar"));
+        assertEquals("/format/2", values.getFirst("resource"));
+        finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/", finalPath);
+        values.clear();
+        
+        assertTrue(uriTemplate.match("/foo/1", values));
+        assertEquals("1", values.getFirst("bar"));
+        assertNull(values.getFirst("resource"));
+        finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/", finalPath);
+    }
+    
+    
+    @Test
+    public void testExpressionWithNestedGroupAndManySegments() throws Exception {
+        URITemplate uriTemplate = new URITemplate("/foo/{bar}{resource:(/format/[^/]+?)?}/baz");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+
+        assertTrue(uriTemplate.match("/foo/1/format/2/baz/3", values));
+        assertEquals("1", values.getFirst("bar"));
+        assertEquals("/format/2", values.getFirst("resource"));
+        String finalPath = values.getFirst(URITemplate.FINAL_MATCH_GROUP);
+        assertEquals("/3", finalPath);
+        values.clear();
+    }
+    
+    @Test
     public void testExpressionWithNestedGroup2() throws Exception {
         URITemplate uriTemplate = 
             new URITemplate("/{resource:.+\\.(js|css|gif|png)}/bar");



Mime
View raw message