You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2011/03/15 17:29:52 UTC

svn commit: r1081842 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/test/java/org/a...

Author: sergeyb
Date: Tue Mar 15 16:29:51 2011
New Revision: 1081842

URL: http://svn.apache.org/viewvc?rev=1081842&view=rev
Log:
[CXF-3404] Proper handling of encoded semicolons

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/PrimitiveTextProvider.java Tue Mar 15 16:29:51 2011
@@ -50,6 +50,7 @@ public class PrimitiveTextProvider 
         
         return InjectionUtils.handleParameter(
                     IOUtils.readStringFromStream(is), 
+                    false,
                     type,
                     ParameterType.REQUEST_BODY, null);
         

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Tue Mar 15 16:29:51 2011
@@ -269,6 +269,7 @@ public final class InjectionUtils {
     }
     
     public static Object handleParameter(String value, 
+                                         boolean decoded,
                                          Class<?> pClass, 
                                          ParameterType pType,
                                          Message message) {
@@ -278,14 +279,16 @@ public final class InjectionUtils {
         }
         
         if (pType == ParameterType.PATH) {
-            PathSegment ps = new PathSegmentImpl(value, false);    
             if (PathSegment.class.isAssignableFrom(pClass)) {
-                return ps;   
+                return new PathSegmentImpl(value, decoded);   
             } else {
-                value = ps.getPath();                 
+                value = new PathSegmentImpl(value, false).getPath();                 
             }
         }
         
+        value = decodeValue(value, decoded, pType);
+        
+        
         if (pClass.isPrimitive()) {
             try {
                 return PrimitiveUtils.read(value, pClass);
@@ -485,9 +488,9 @@ public final class InjectionUtils {
                             paramValue = InjectionUtils.handleBean(type, processedValues,
                                                             pType, message, decoded);
                         } else {
-                            String value = decodeValue(processedValues.values().iterator().next().get(0),
-                                                       decoded, pType);
-                            paramValue = InjectionUtils.handleParameter(value, type, pType, message);
+                            paramValue = InjectionUtils.handleParameter(
+                                processedValues.values().iterator().next().get(0), 
+                                decoded, type, pType, message);
                         }
 
                         if (paramValue != null) {
@@ -631,8 +634,8 @@ public final class InjectionUtils {
             List<String> valuesList = values.values().iterator().next();
             valuesList = checkPathSegment(valuesList, realType, pathParam);
             for (int ind = 0; ind < valuesList.size(); ind++) {
-                String value = decodeValue(valuesList.get(ind), decoded, pathParam);
-                Object o = InjectionUtils.handleParameter(value, realType, pathParam, message);
+                Object o = InjectionUtils.handleParameter(valuesList.get(ind), decoded, 
+                                                          realType, pathParam, message);
                 addToCollectionValues(theValues, o, ind);
             }
         }
@@ -707,8 +710,7 @@ public final class InjectionUtils {
                                 : paramValues.get(0);
             }
             if (result != null) {
-                result = decodeValue(result, decoded, pathParam);
-                value = InjectionUtils.handleParameter(result, paramType, pathParam, message);
+                value = InjectionUtils.handleParameter(result, decoded, paramType, pathParam, message);
             }
         }
         return value;

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Tue Mar 15 16:29:51 2011
@@ -785,7 +785,7 @@ public final class JAXRSUtils {
             return c;
         }
         
-        return InjectionUtils.handleParameter(c.getValue(), pClass, ParameterType.COOKIE, m);
+        return InjectionUtils.handleParameter(c.getValue(), false, pClass, ParameterType.COOKIE, m);
     }
     
     public static <T> T createContextValue(Message m, Type genericType, Class<T> clazz) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/Customer.java Tue Mar 15 16:29:51 2011
@@ -305,7 +305,8 @@ public class Customer extends AbstractCu
                                 @MatrixParam("p2") String mp2,
                                 @MatrixParam("p3") String mp3,
                                 @MatrixParam("p4") String mp4,
-                                @MatrixParam("p4") List<String> mp4List) {
+                                @MatrixParam("p4") List<String> mp4List,
+                                @MatrixParam("p5") String mp5) {
         // complete
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/JAXRSUtilsTest.java Tue Mar 15 16:29:51 2011
@@ -1003,14 +1003,14 @@ public class JAXRSUtilsTest extends Asse
     @SuppressWarnings("unchecked")
     @Test
     public void testMatrixParameters() throws Exception {
-        Class[] argType = {String.class, String.class, String.class, String.class, List.class};
+        Class[] argType = {String.class, String.class, String.class, String.class, List.class, String.class};
         Method m = Customer.class.getMethod("testMatrixParam", argType);
         MessageImpl messageImpl = new MessageImpl();
         
-        messageImpl.put(Message.REQUEST_URI, "/foo;p4=0;p3=3/bar;p1=1;p2/baz;p4=4;p4=5");
+        messageImpl.put(Message.REQUEST_URI, "/foo;p4=0;p3=3/bar;p1=1;p2/baz;p4=4;p4=5;p5");
         List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, null), 
                                                            null, messageImpl);
-        assertEquals("5 Matrix params should've been identified", 5, params.size());
+        assertEquals("5 Matrix params should've been identified", 6, params.size());
         
         assertEquals("First Matrix Parameter not matched correctly", 
                      "1", params.get(0));
@@ -1025,6 +1025,8 @@ public class JAXRSUtilsTest extends Asse
         assertEquals("0", list.get(0));
         assertEquals("4", list.get(1));
         assertEquals("5", list.get(2));
+        assertEquals("Sixth Matrix Parameter was not matched correctly", 
+                     "", params.get(5));
     }
     
     @Test

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreSpring.java Tue Mar 15 16:29:51 2011
@@ -88,6 +88,21 @@ public class BookStoreSpring {
     }
     
     @GET
+    @Path("/semicolon{id}")
+    @Produces("application/xml")
+    public Book getBookWithSemicoln(@PathParam("id") String name) {
+        return new Book(name, 333L);
+    }
+    
+    @GET
+    @Path("/semicolon2{id}")
+    @Produces("application/xml")
+    public Book getBookWithSemicolnAndMatrixParam(@PathParam("id") String name,
+                                                  @MatrixParam("a") String matrixParam) {
+        return new Book(name + matrixParam, 333L);
+    }
+    
+    @GET
     @Path("/bookinfo")
     public Book getBookByUriInfo() throws Exception {
         MultivaluedMap<String, String> params = ui.getQueryParameters();

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerProxySpringBookTest.java Tue Mar 15 16:29:51 2011
@@ -38,7 +38,7 @@ public class JAXRSClientServerProxySprin
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerProxySpring.class, true));
+                   launchServer(BookServerProxySpring.class));
     }
     
     @Test

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java?rev=1081842&r1=1081841&r2=1081842&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerSpringBookTest.java Tue Mar 15 16:29:51 2011
@@ -55,7 +55,7 @@ public class JAXRSClientServerSpringBook
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly", 
-                   launchServer(BookServerSpring.class, true));
+                   launchServer(BookServerSpring.class));
     }
     
     @Test
@@ -77,6 +77,28 @@ public class JAXRSClientServerSpringBook
     }
     
     @Test
+    public void testGetBookWithEncodedSemicolon() throws Exception {
+        String endpointAddress =
+            "http://localhost:" + PORT + "/the/thebooks/bookstore/semicolon%3B"; 
+        WebClient client = WebClient.create(endpointAddress);
+        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000);
+        Book book = client.get(Book.class);
+        assertEquals(333L, book.getId());
+        assertEquals(";", book.getName());
+    }
+    
+    @Test
+    public void testGetBookWithEncodedSemicolonAndMatrixParam() throws Exception {
+        String endpointAddress =
+            "http://localhost:" + PORT + "/the/thebooks/bookstore/semicolon2%3B;a=b"; 
+        WebClient client = WebClient.create(endpointAddress);
+        WebClient.getConfig(client).getHttpConduit().getClient().setReceiveTimeout(1000000);
+        Book book = client.get(Book.class);
+        assertEquals(333L, book.getId());
+        assertEquals(";b", book.getName());
+    }
+    
+    @Test
     public void testGetBookXSLTHtml() throws Exception {
 
         String endpointAddress =