You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by sc...@apache.org on 2010/08/14 14:33:18 UTC

svn commit: r985478 - in /axis/axis2/java/core/trunk/modules: jaxws-integration/test/org/apache/axis2/jaxws/sample/ jaxws-integration/test/org/apache/axis2/jaxws/sample/dlwminArrays/ jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/ jaxws/src/org/a...

Author: scheu
Date: Sat Aug 14 12:33:18 2010
New Revision: 985478

URL: http://svn.apache.org/viewvc?rev=985478&view=rev
Log:
AXIS2-4796
Contributor:Rich Scheuerle
Summary:
Allows null arguments to web methods that have java.util.List parameters/returns 
Added a verification test.

Modified:
    axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/DLWMinArrayTests.java
    axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/dlwminArrays/GenericService.java
    axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMinimalMethodMarshaller.java
    axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/OccurrenceArray.java

Modified: axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/DLWMinArrayTests.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/DLWMinArrayTests.java?rev=985478&r1=985477&r2=985478&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/DLWMinArrayTests.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/DLWMinArrayTests.java Sat Aug 14 12:33:18 2010
@@ -251,6 +251,45 @@ public class DLWMinArrayTests extends Ab
     
     /**
      * Test method that echos a List of beans (List<WSUser>)
+     * The list contains no items.
+     */
+    public void testEchoComplexListNull() throws Exception {
+        
+        IGenericService proxy = getProxy("echoComplexList");
+        
+        // There really is no discernible difference between
+        // an empty array and null over the wire.  Sometimes users
+        // will pass in a null on the client or server.
+        
+        List<WSUser> response = proxy.echoComplexList(null);
+        assertTrue(response != null);
+        assertTrue(response.size() == 0);
+        
+        // Try the call again
+        response = proxy.echoComplexList(null);
+        assertTrue(response != null);
+        assertTrue(response.size() == 0);
+        
+        // Now try force the server to return a null argument
+        List<WSUser> in = new ArrayList<WSUser>();
+        WSUser wsUser = new WSUser();
+        wsUser.setUserID("FORCENULL");
+        in.add(wsUser);
+        
+        response = proxy.echoComplexList(in);
+        assertTrue(response != null);
+        assertTrue(response.size() == 0);
+        
+        // Try the call again
+        response = proxy.echoComplexList(in);
+        assertTrue(response != null);
+        assertTrue(response.size() == 0);
+        
+        
+    }
+    
+    /**
+     * Test method that echos a List of beans (List<WSUser>)
      * and echos a List<String> as an inout parameter.
      * 2 WSUsers are echo'd
      * 2 Strings are echo'd

Modified: axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/dlwminArrays/GenericService.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/dlwminArrays/GenericService.java?rev=985478&r1=985477&r2=985478&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/dlwminArrays/GenericService.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/dlwminArrays/GenericService.java Sat Aug 14 12:33:18 2010
@@ -64,6 +64,9 @@ public class GenericService implements I
     }
     
     public List<WSUser> echoComplexList(List<WSUser> in ) {
+        if (in.size() > 0 && in.get(0).getUserID().equals("FORCENULL")) {
+            return null;
+        }
         return in;
     }
 

Modified: axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMinimalMethodMarshaller.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMinimalMethodMarshaller.java?rev=985478&r1=985477&r2=985478&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMinimalMethodMarshaller.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/DocLitWrappedMinimalMethodMarshaller.java Sat Aug 14 12:33:18 2010
@@ -342,7 +342,7 @@ public class DocLitWrappedMinimalMethodM
             if (returnType != void.class) {
                 Element returnElement = null;
                 QName returnQName = new QName(returnNS, returnLocalPart);
-                if (representAsOccurrence(returnObject)) {
+                if (representAsOccurrence(returnObject, returnType)) {
                     if (log.isDebugEnabled()) {
                         log.debug("Return element isListOrArray");
                     }
@@ -428,7 +428,7 @@ public class DocLitWrappedMinimalMethodM
             if (elementValue instanceof JAXBElement) {
                 JAXBElement jaxb = (JAXBElement) elementValue;
                 Object value = jaxb.getValue();
-                if (representAsOccurrence(value)) {
+                if (representAsOccurrence(value, jaxb.getDeclaredType())) {
                     if (log.isDebugEnabled()) {
                         log.debug("Build OccurrentArray");
                     }
@@ -450,23 +450,25 @@ public class DocLitWrappedMinimalMethodM
      * @return true if this value should be represented as a series of occurrence
      * elements
      */
-    private static boolean representAsOccurrence(Object value) {
+    private static boolean representAsOccurrence(Object value, Class inClass) {
         // Represent as a series of occurrence elements if not List/Array
         // but not a byte[].  A byte[] has its own encoding.
         
         boolean rc = false;
-        
-        if (value == null) {
-            rc = false;
-        } else if (value instanceof List) {
+        Class cls = (value == null) ? inClass : value.getClass();
+  
+        if (cls == null) {
+            return true;
+        }else if (List.class.isAssignableFrom(cls)) {
             rc = true;
-        } else if (value.getClass().equals(byte[].class)) {
+        } else if (cls.equals(byte[].class)) {
             rc = false;  // assume base64binary
-        } else if (value.getClass().isArray()) {
+        } else if (cls.isArray()) {
             rc = true;
         }
         if (log.isDebugEnabled()) {
-            log.debug("representAsOccurrence for " + JavaUtils.getObjectIdentity(value) + " " + rc);
+            log.debug("representAsOccurrence for " + JavaUtils.getObjectIdentity(value) + 
+                        " of class: " + inClass + rc);
         }
         return rc;
     }

Modified: axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/OccurrenceArray.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/OccurrenceArray.java?rev=985478&r1=985477&r2=985478&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/OccurrenceArray.java (original)
+++ axis/axis2/java/core/trunk/modules/jaxws/src/org/apache/axis2/jaxws/message/OccurrenceArray.java Sat Aug 14 12:33:18 2010
@@ -57,14 +57,15 @@ public class OccurrenceArray {
      */
     public Object[] getAsArray() {
         Object[] objects = null;
-        if (value instanceof List) {
+        if (value == null) {
+            return new Object[0];
+        } else if (value instanceof List) {
             List l = (List) value;
             objects = new Object[l.size()];
             for (int i=0; i<l.size(); i++) {
                 objects[i] = l.get(i);
             }
         } else {
-            
             objects = new Object[Array.getLength(value)];
             for (int i=0; i<objects.length; i++) {
                 objects[i] = Array.get(value, i);