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 2013/12/03 18:36:23 UTC

svn commit: r1547493 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/

Author: sergeyb
Date: Tue Dec  3 17:36:23 2013
New Revision: 1547493

URL: http://svn.apache.org/r1547493
Log:
Merged revisions 1547487 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1547487 | sergeyb | 2013-12-03 17:20:54 +0000 (Tue, 03 Dec 2013) | 9 lines
  
  Merged revisions 1547482 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1547482 | sergeyb | 2013-12-03 17:16:09 +0000 (Tue, 03 Dec 2013) | 1 line
    
    [CXF-5433] Fixing the issue with mapping Multipart types to primitive values 
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
    cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Tue Dec  3 17:36:23 2013
@@ -0,0 +1,2 @@
+/cxf/branches/2.7.x-fixes:1547487
+/cxf/trunk:1547482

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1547493&r1=1547492&r2=1547493&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java (original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java Tue Dec  3 17:36:23 2013
@@ -54,6 +54,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.form.Form;
@@ -176,9 +177,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 WebApplicationException(400);

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=1547493&r1=1547492&r2=1547493&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Tue Dec  3 17:36:23 2013
@@ -606,6 +606,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/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1547493&r1=1547492&r2=1547493&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Tue Dec  3 17:36:23 2013
@@ -87,6 +87,14 @@ public class JAXRSClientServerBookTest e
     }
     
     @Test
+    public void testGetBookQueryDefault() throws Exception {
+        String address = "http://localhost:" + PORT + "/bookstore/books/query/default";
+        WebClient wc = WebClient.create(address);
+        Book book = wc.get(Book.class);
+        assertEquals(123L, book.getId());
+    }
+    
+    @Test
     public void testGetChapterFromSelectedBook() {
         String address = "http://localhost:" + PORT + "/bookstore/books/id=le=123/chapter/1";
         doTestGetChapterFromSelectedBook(address);

Modified: cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java?rev=1547493&r1=1547492&r2=1547493&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java (original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSMultipartTest.java Tue Dec  3 17:36:23 2013
@@ -440,6 +440,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/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java?rev=1547493&r1=1547492&r2=1547493&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java (original)
+++ cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/MultipartStore.java Tue Dec  3 17:36:23 2013
@@ -160,6 +160,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")