cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1336660 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/
Date Thu, 10 May 2012 13:07:48 GMT
Author: sergeyb
Date: Thu May 10 13:07:48 2012
New Revision: 1336660

URL: http://svn.apache.org/viewvc?rev=1336660&view=rev
Log:
[CXF-4306] Trying to handle the mix-up of FormParam and Multipart annotaions

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonFiles

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java?rev=1336660&r1=1336659&r2=1336660&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/FormUtils.java Thu
May 10 13:07:48 2012
@@ -50,7 +50,7 @@ public final class FormUtils {
     private static final Logger LOG = LogUtils.getL7dLogger(FormUtils.class);
     private static final String MULTIPART_FORM_DATA_TYPE = "form-data";  
     private static final String MAX_FORM_PARAM_COUNT = "maxFormParameterCount";  
-        
+    private static final String CONTENT_DISPOSITION_FILES_PARAM = "files";    
     private FormUtils() {
         
     }
@@ -165,10 +165,18 @@ public final class FormUtils {
             if (StringUtils.isEmpty(name)) { 
                 throw new WebApplicationException(400);
             }
+            if (CONTENT_DISPOSITION_FILES_PARAM.equals(name)) {
+                // this is a reserved name in Content-Disposition for parts containing files
+                continue;
+            }
             try {
                 String value = IOUtils.toString(a.getDataHandler().getInputStream());
                 params.add(HttpUtils.urlDecode(name),
                            decode ? HttpUtils.urlDecode(value) : value);
+            } catch (IllegalArgumentException ex) {
+                LOG.warning("Illegal URL-encoded characters, make sure that no "
+                    + "@FormParam and @Multipart annotations are mixed up");
+                throw new WebApplicationException(415);
             } catch (IOException ex) {
                 throw new WebApplicationException(415);
             }

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1336660&r1=1336659&r2=1336660&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
Thu May 10 13:07:48 2012
@@ -135,6 +135,12 @@ public class JAXRSMultipartTest extends 
     }
     
     @Test
+    public void testBookJSONFormTwoFilesMixUp() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/filesform/mixup";
+        doAddFormBook(address, "attachmentFormJsonFiles", 200);               
+    }
+    
+    @Test
     public void testBookJSONFormOneFile() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/books/fileform";
         doAddFormBook(address, "attachmentFormJsonFile", 200);               

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1336660&r1=1336659&r2=1336660&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
Thu May 10 13:07:48 2012
@@ -412,7 +412,7 @@ public class MultipartStore {
         Book b1 = books.get(0);
         Book b2 = books.get(1);
         if (!"CXF in Action - 1".equals(b1.getName())
-            || !"CXF in Action - 2".equals(b2.getName())
+            || !"CXF in Action - 2%".equals(b2.getName())
             || !"Larry".equals(name)) {
             throw new WebApplicationException();
         }
@@ -422,6 +422,16 @@ public class MultipartStore {
     }
     
     @POST
+    @Path("/books/filesform/mixup")
+    @Produces("text/xml")
+    @Consumes("multipart/form-data")
+    public Response addBookFilesFormMixUp(@FormParam("owner") String name, 
+                                          @Multipart("files") List<Book> books)
+        throws Exception {
+        return addBookFilesForm(name, books);
+    }
+    
+    @POST
     @Path("/books/fileform")
     @Produces("text/xml")
     @Consumes("multipart/form-data")

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonFiles
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonFiles?rev=1336660&r1=1336659&r2=1336660&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonFiles
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/attachmentFormJsonFiles
Thu May 10 13:07:48 2012
@@ -19,6 +19,6 @@ Content-Disposition: form-data; name="bo
 Content-Type: application/json; charset=US-ASCII
 Content-Transfer-Encoding: 8bit
 
-{"Book":{"name":"CXF in Action - 2","id":124}}
+{"Book":{"name":"CXF in Action - 2%","id":124}}
 --_Part_4_701508.1145579811786--
 --bqJky99mlBWa-ZuqjC53mG6EzbmlxB--
\ No newline at end of file



Mime
View raw message