cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1056778 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/ systests/jaxrs/src/test/java/org/a...
Date Sat, 08 Jan 2011 19:47:33 GMT
Author: sergeyb
Date: Sat Jan  8 19:47:33 2011
New Revision: 1056778

URL: http://svn.apache.org/viewvc?rev=1056778&view=rev
Log:
[CXF-3226] Support for explicit spaces in Path expressions

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/utils/HttpUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/URITemplateTest.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=1056778&r1=1056777&r2=1056778&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
Sat Jan  8 19:47:33 2011
@@ -61,7 +61,8 @@ public final class URITemplate {
             UriChunk chunk = UriChunk.createUriChunk(templatePart);
             uriChunks.add(chunk);
             if (chunk instanceof Literal) {
-                String substr = escapeCharacters(chunk.getValue());
+                String encodedValue = HttpUtils.encodePartiallyEncoded(chunk.getValue(),
false);
+                String substr = escapeCharacters(encodedValue);
                 literalChars.append(substr);
                 patternBuilder.append(substr);
             } else if (chunk instanceof Variable) {

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=1056778&r1=1056777&r2=1056778&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 Sat
Jan  8 19:47:33 2011
@@ -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/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1056778&r1=1056777&r2=1056778&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Sat Jan  8 19:47:33 2011
@@ -212,7 +212,7 @@ public final class ResourceUtils {
             Method annotatedMethod = AnnotationUtils.getAnnotatedMethod(m);
             
             String httpMethod = AnnotationUtils.getHttpMethodValue(annotatedMethod);
-            Path path = (Path)AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class);
+            Path path = AnnotationUtils.getMethodAnnotation(annotatedMethod, Path.class);
             
             if (httpMethod != null || path != null) {
                 md.bind(createOperationInfo(m, annotatedMethod, cri, path, httpMethod), m);

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=1056778&r1=1056777&r2=1056778&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
Sat Jan  8 19:47:33 2011
@@ -250,7 +250,26 @@ public class URITemplateTest extends Ass
         assertFalse(uriTemplate.match("/books/acdb", values));
 
     }
+    
+    @Test
+    public void testEscapingWildCard() throws Exception {
+        URITemplate uriTemplate = new URITemplate("/books/a*");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
+
+        assertTrue(uriTemplate.match("/books/a*", values));
+        assertFalse(uriTemplate.match("/books/a", values));
+        assertFalse(uriTemplate.match("/books/ac", values));
+    }
+
+    @Test
+    public void testEncodedSpace() throws Exception {
+        URITemplate uriTemplate = new URITemplate("/1 2/%203");
+        MultivaluedMap<String, String> values = new MetadataMap<String, String>();
 
+        assertTrue(uriTemplate.match("/1%202/%203", values));
+        assertFalse(uriTemplate.match("/1 2/%203", values));
+    }
+    
     @Test
     public void testBasicCustomExpression4() throws Exception {
         URITemplate uriTemplate = new URITemplate("/books/{bookId:...\\.}");
@@ -559,9 +578,10 @@ public class URITemplateTest extends Ass
         assertFalse(tok.hasNext());
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testUnclosedVariable() {
-        new URITemplate("/foo/{var/bar");
+        URITemplate ut = new URITemplate("/foo/{var/bar");
+        assertEquals("/foo/{var/bar", ut.getValue());
     }
 
     @Test

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=1056778&r1=1056777&r2=1056778&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 Sat
Jan  8 19:47:33 2011
@@ -389,6 +389,13 @@ public class BookStore {
     }
     
     @GET
+    @Path("/the books/{bookId}/")
+    @Produces("application/xml")
+    public Book getBookWithSpace(@PathParam("bookId") String id) throws BookNotFoundFault
{
+        return doGetBook(id);
+    }
+    
+    @GET
     @Path("/books/search")
     @Produces("application/xml")
     public Book getBook(@Context SearchContext searchContext) 

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=1056778&r1=1056777&r2=1056778&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
Sat Jan  8 19:47:33 2011
@@ -89,6 +89,20 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testBookWithSpace() throws Exception {
+        WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/").path("the
books/123");
+        Book book = client.get(Book.class);
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
+    public void testBookWithSpaceProxy() throws Exception {
+        BookStore store = JAXRSClientFactory.create("http://localhost:" + PORT, BookStore.class);
+        Book book = store.getBookWithSpace("123");
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
     public void testTempRedirectWebClient() throws Exception {
         WebClient client = WebClient.create("http://localhost:" + PORT + "/bookstore/tempredirect");
         Response r = client.type("*/*").get();



Mime
View raw message