cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1547482 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/
Date Tue, 03 Dec 2013 17:16:09 GMT
Author: sergeyb
Date: Tue Dec  3 17:16:09 2013
New Revision: 1547482

URL: http://svn.apache.org/r1547482
Log:
[CXF-5433] Fixing the issue with mapping Multipart types to primitive values 

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.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
    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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1547482&r1=1547481&r2=1547482&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Tue Dec  3 17:16:09 2013
@@ -56,6 +56,7 @@ import org.apache.cxf.attachment.Attachm
 import org.apache.cxf.attachment.ByteDataSource;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.PrimitiveUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
@@ -181,9 +182,13 @@ public class MultipartProvider extends A
         
         if (id != null && !id.required()) {
             /*
-             * If user asked for a null, give them a null. 
+             * Return default value for a missing optional part 
              */
-            return null;
+            Object defaultValue = null;
+            if (c.isPrimitive()) {
+                defaultValue = PrimitiveUtils.read((Class<?>)c == boolean.class ? "false"
: "0", c);
+            }
+            return defaultValue;
         }
         
         throw new BadRequestException();

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=1547482&r1=1547481&r2=1547482&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
Dec  3 17:16:09 2013
@@ -841,6 +841,13 @@ public class BookStore {
         return doGetBook(id);
     }
     
+    @GET
+    @Path("/books/query/default")
+    @Produces("application/xml")
+    public Book getBook(@QueryParam("bookId") long id) throws BookNotFoundFault {
+        return books.get(id + 123);
+    }
+    
     
     
     @GET

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=1547482&r1=1547481&r2=1547482&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 Dec  3 17:16:09 2013
@@ -94,6 +94,15 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookQueryDefault() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/query/default";
+        WebClient wc = WebClient.create(address);
+        Response r = wc.get();
+        Book book = r.readEntity(Book.class);
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
     public void testGetBookSameUriAutoRedirect() throws Exception {
         String address = "http://localhost:" + PORT + "/bookstore/redirect?sameuri=true";
         WebClient wc = WebClient.create(address);

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=1547482&r1=1547481&r2=1547482&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
Tue Dec  3 17:16:09 2013
@@ -465,6 +465,19 @@ public class JAXRSMultipartTest extends 
     }
     
     @Test
+    public void testNullableParamsPrimitive() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/testnullpartprimitive";
+        WebClient client = WebClient.create(address);
+        client.type("multipart/form-data").accept("text/plain");
+        List<Attachment> atts = new LinkedList<Attachment>();
+        atts.add(new Attachment("somepart", "text/plain", "hello there"));
+        Response r = client.postCollection(atts, Attachment.class);
+        assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
+        assertEquals((Integer)0, Integer.valueOf(IOUtils.readStringFromStream((InputStream)r.getEntity())));
+    }
+    
+    
+    @Test
     public void testAddBookJaxbJsonImageWebClientMixed() throws Exception {
         Map<String, String> params = 
             doTestAddBookJaxbJsonImageWebClient("multipart/mixed");

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=1547482&r1=1547481&r2=1547482&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
Tue Dec  3 17:16:09 2013
@@ -188,6 +188,14 @@ public class MultipartStore {
     }
     
     @POST
+    @Path("/books/testnullpartprimitive")
+    @Consumes("multipart/form-data")
+    @Produces("text/plain")
+    public int testNullPart2(@Multipart(value = "someid", required = false) int value) {
+        return value;
+    }
+    
+    @POST
     @Path("/books/testnullpartFormParam")
     @Consumes("multipart/form-data")
     @Produces("text/plain")



Mime
View raw message