cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-5749] Avoiding NPE if client proxy is given null body parameter
Date Tue, 20 May 2014 15:12:45 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 0cab9af90 -> 503663709


[CXF-5749] Avoiding NPE if client proxy is given null body parameter


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/50366370
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/50366370
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/50366370

Branch: refs/heads/master
Commit: 503663709c991b26d28d41a3689f5ed56cdda1d6
Parents: 0cab9af
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Tue May 20 16:12:16 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Tue May 20 16:12:16 2014 +0100

----------------------------------------------------------------------
 .../org/apache/cxf/jaxrs/client/ClientProxyImpl.java     | 10 +++++++---
 .../java/org/apache/cxf/systest/jaxrs/BookStore.java     |  6 ++++--
 .../cxf/systest/jaxrs/JAXRSClientServerBookTest.java     | 11 +++++++++++
 3 files changed, 22 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/50366370/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
index 4cea12a..d728548 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
@@ -166,7 +166,7 @@ public class ClientProxyImpl extends AbstractClient implements
         
         List<Object> pathParams = getPathParamValues(m, params, types, beanParamsList,
ori);
         
-        int bodyIndex = getBodyIndex(types, ori);
+        int bodyIndex = getBodyIndex(types, ori, params);
         
         UriBuilder builder = getCurrentBuilder().clone(); 
         if (isRoot) {
@@ -205,13 +205,16 @@ public class ClientProxyImpl extends AbstractClient implements
         
         headers.putAll(paramHeaders);
         setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), 
-            bodyIndex == -1 ? null : params[bodyIndex].getClass(), m.getReturnType());
+            bodyIndex == -1 || params[bodyIndex] == null ? null : params[bodyIndex].getClass(),
m.getReturnType());
         
         getState().setTemplates(getTemplateParametersMap(ori.getURITemplate(), pathParams));
         
         Object body = null;
         if (bodyIndex != -1) {
             body = params[bodyIndex];
+            if (body == null) {
+                bodyIndex = -1;
+            }
         } else if (types.containsKey(ParameterType.FORM))  {
             body = handleForm(m, params, types, beanParamsList);
         } else if (types.containsKey(ParameterType.REQUEST_BODY))  {
@@ -275,7 +278,8 @@ public class ClientProxyImpl extends AbstractClient implements
     }
     
     private static int getBodyIndex(MultivaluedMap<ParameterType, Parameter> map, 
-                                    OperationResourceInfo ori) {
+                                    OperationResourceInfo ori,
+                                    Object[] params) {
         List<Parameter> list = map.get(ParameterType.REQUEST_BODY);
         int index = list == null || list.size() > 1 ? -1 : list.get(0).getIndex();
         if (ori.isSubResourceLocator() && index != -1) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/50366370/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
index 34e36fb..af4bdc6 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
@@ -562,9 +562,11 @@ public class BookStore {
     @Path("/collectionBook")
     @Produces({"application/xml", "application/json" })
     @Consumes({"application/xml", "application/json" })
-    public List<Book> postBookGetCollection(Book book) throws Exception {
+    public List<Book> postBookGetCollection(@Nullable Book book) throws Exception {
         List<Book> list = new ArrayList<Book>();
-        list.add(book);
+        if (book != null) {
+            list.add(book);
+        }
         return list;
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/50366370/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 0a0048e..c2f355c 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -620,6 +620,17 @@ public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase
{
     }
     
     @Test
+    public void testPostNullGetEmptyCollectionProxy() throws Exception {
+        
+        String endpointAddress = "http://localhost:" + PORT; 
+        BookStore bs = JAXRSClientFactory.create(endpointAddress, BookStore.class);
+        List<Book> books = bs.postBookGetCollection(null);
+        assertNotNull(books);
+        assertEquals(0, books.size());
+        
+    }
+    
+    @Test
     public void testPostObjectGetCollection() throws Exception {
         
         String endpointAddress =


Mime
View raw message