cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r780741 - in /cxf/trunk/rt/frontend/jaxrs/src: main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java test/java/org/apache/cxf/jaxrs/provider/FormEncodingProviderTest.java
Date Mon, 01 Jun 2009 17:34:25 GMT
Author: sergeyb
Date: Mon Jun  1 17:34:25 2009
New Revision: 780741

URL: http://svn.apache.org/viewvc?rev=780741&view=rev
Log:
CXF-2242 : applying a fix proposed by Nacho G. Mac Dowell

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingProviderTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java?rev=780741&r1=780740&r2=780741&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/FormEncodingProvider.java
Mon Jun  1 17:34:25 2009
@@ -147,15 +147,17 @@
         boolean encoded = AnnotationUtils.getAnnotation(anns, Encoded.class) != null;
         for (Iterator<Map.Entry<String, List<String>>> it = map.entrySet().iterator();
it.hasNext();) {
             Map.Entry<String, List<String>> entry = it.next();
-            for (String value : entry.getValue()) {
+            for (Iterator<String> entryIterator = entry.getValue().iterator(); entryIterator.hasNext();)
{
+                String value = entryIterator.next();
                 os.write(entry.getKey().getBytes("UTF-8"));
                 os.write('=');
-                String data = encoded ? value : HttpUtils.urlEncode(value); 
+                String data = encoded ? value : HttpUtils.urlEncode(value);
                 os.write(data.getBytes("UTF-8"));
-                if (it.hasNext()) {
+                if (entryIterator.hasNext() || it.hasNext()) {
                     os.write('&');
                 }
             }
+
         }
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingProviderTest.java?rev=780741&r1=780740&r2=780741&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/FormEncodingProviderTest.java
Mon Jun  1 17:34:25 2009
@@ -20,6 +20,7 @@
 package org.apache.cxf.jaxrs.provider;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.util.List;
@@ -126,6 +127,48 @@
 
     }
     
+    @Test
+    public void testWriteMultipleValues() throws Exception {
+        MultivaluedMap<String, String> mvMap = new MetadataMap<String, String>();
+        mvMap.add("a", "a1");
+        mvMap.add("a", "a2");
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, 
+                     new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, 
+                     new MetadataMap<String, Object>(), bos);
+        String result = bos.toString();
+        assertEquals("Wrong value", "a=a1&a=a2", result);  
+    }
+    
+    @Test
+    public void testWriteMultipleValues2() throws Exception {
+        MultivaluedMap<String, String> mvMap = new MetadataMap<String, String>();
+        mvMap.add("a", "a1");
+        mvMap.add("a", "a2");
+        mvMap.add("b", "b1");
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, 
+                     new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, 
+                     new MetadataMap<String, Object>(), bos);
+        String result = bos.toString();
+        assertEquals("Wrong value", "a=a1&a=a2&b=b1", result);  
+    }
+    
+    @Test
+    public void testWrite() throws Exception {
+        MultivaluedMap<String, String> mvMap = new MetadataMap<String, String>();
+        mvMap.add("a", "a1");
+        mvMap.add("b", "b1");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, 
+                     new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, 
+                     new MetadataMap<String, Object>(), bos);
+        String result = bos.toString();
+        assertEquals("Wrong value", "a=a1&b=b1", result);  
+    }
+    
     @SuppressWarnings("unchecked")
     @Test
     public void testValidation() throws Exception {



Mime
View raw message