cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1235544 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/ja...
Date Tue, 24 Jan 2012 23:15:27 GMT
Author: sergeyb
Date: Tue Jan 24 23:15:27 2012
New Revision: 1235544

URL: http://svn.apache.org/viewvc?rev=1235544&view=rev
Log:
[CXF-4061] Keeping some of the URI path characters unencoded

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java?rev=1235544&r1=1235543&r2=1235544&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/URITemplate.java
Tue Jan 24 23:15:27 2012
@@ -40,7 +40,7 @@ public final class URITemplate {
     public static final String LIMITED_REGEX_SUFFIX = "(/.*)?";
     public static final String FINAL_MATCH_GROUP = "FINAL_MATCH_GROUP";
     private static final String DEFAULT_PATH_VARIABLE_REGEX = "([^/]+?)";
-    private static final String CHARACTERS_TO_ESCAPE = ".*+";
+    private static final String CHARACTERS_TO_ESCAPE = ".*+$()";
     private static final String SLASH = "/";
     private static final String SLASH_QUOTE = "/;";
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1235544&r1=1235543&r2=1235544&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Tue Jan 24 23:15:27 2012
@@ -347,11 +347,16 @@ public class WadlGenerator implements Re
     }
 
     private String getPath(String path) {
+        String thePath = null;
         if (ignoreForwardSlash && path.startsWith("/") && path.length() >
0) {
-            return path.substring(1);
+            thePath = path.substring(1);
         } else {
-            return path;
+            thePath = path;
         }
+        if (thePath.contains("&")) {
+            thePath = thePath.replace("&", "&");
+        }
+        return thePath;
     }
     
     private void startMethodTag(StringBuilder sb, OperationResourceInfo ori) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1235544&r1=1235543&r2=1235544&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Tue
Jan 24 23:15:27 2012
@@ -63,7 +63,7 @@ public final class HttpUtils {
     private static final String CHARSET_PARAMETER = "charset";
     
     // there are more of such characters, ex, '*' but '*' is not affected by UrlEncode
-    private static final String PATH_RESERVED_CHARACTERS = "=@/:";
+    private static final String PATH_RESERVED_CHARACTERS = "=@/:!$&\'(),;~";
     private static final String QUERY_RESERVED_CHARACTERS = "?/";
     
     private HttpUtils() {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java?rev=1235544&r1=1235543&r2=1235544&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.java
Tue Jan 24 23:15:27 2012
@@ -40,6 +40,13 @@ public class URITemplateTest extends Ass
     }
 
     @Test
+    public void testPathCharacters() {
+        String pathChars = ":@!$&'*+,;=-._~()";
+        assertTrue(new URITemplate(pathChars).match(pathChars, 
+                                                    new MetadataMap<String, String>()));
+    }
+    
+    @Test
     public void testMatchBasic() throws Exception {
         URITemplate uriTemplate = new URITemplate("/customers/{id}");
         MultivaluedMap<String, String> values = new MetadataMap<String, String>();

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java?rev=1235544&r1=1235543&r2=1235544&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Tue Jan 24 23:15:27 2012
@@ -59,8 +59,24 @@ public class HttpUtilsTest extends Asser
         assertEquals("%2B+", HttpUtils.urlEncode("+ "));
     }
      
+    
     @Test
     public void testPathEncode() {
+        // rfc3986.txt 3.3
+        //segment-nz    = 1*pchar
+        //pchar         = unreserved / pct-encoded / sub-delims / ":" / "@"
+        // sub-delims  = "!" / "$" / "&" / "'" / "(" / ")" / "*" / "+" / "," / ";" /
"="
+        // unreserved  = ALPHA / DIGIT / "-" / "." / "_" / "~"
+        
+        // '&' has to be represented as &amp; in WADL
+        
+        String pathChars = ":@!$&'()*+,;=-._~";
+        String str = HttpUtils.pathEncode(pathChars);
+        assertEquals(str, pathChars);
+    }
+    
+    @Test
+    public void testPathEncodeWithPlusAndSpace() {
         assertEquals("+%20", HttpUtils.pathEncode("+ "));
     }
     

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1235544&r1=1235543&r2=1235544&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue
Jan 24 23:15:27 2012
@@ -117,6 +117,12 @@ public class BookStore {
     public void preDestroy() {
         //System.out.println("PreDestroy called");
     }
+
+    @GET
+    @Path("allCharsButA-B/:@!$&'()*+,;=-._~")
+    public Book getWithComplexPath() {
+        return new Book("Encoded Path", 125L);
+    }
     
     @GET
     @Path("/default")

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1235544&r1=1235543&r2=1235544&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Tue Jan 24 23:15:27 2012
@@ -80,6 +80,15 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testWithComplexPath() {
+        WebClient wc = 
+            WebClient.create("http://localhost:" + PORT + "/bookstore/allCharsButA-B/:@!$&'()*+,;=-._~");
+        wc.accept("application/xml");
+        Book book = wc.get(Book.class);
+        assertEquals("Encoded Path", book.getName());
+    }
+    
+    @Test
     public void testMalformedAcceptType() {
         WebClient wc = 
             WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");



Mime
View raw message