You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2010/03/13 21:37:18 UTC

svn commit: r922673 - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/test/java/org/apache/axiom/soap/ axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/ axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/

Author: veithen
Date: Sat Mar 13 20:37:18 2010
New Revision: 922673

URL: http://svn.apache.org/viewvc?rev=922673&view=rev
Log:
WSCOMMONS-526: Make sure that SOAPEnvelope#getBody returns null (instead of throwing an exception) if the envelope only contains a header. This is consistent with the existing Javadoc of the method. Also resynchronized the DOOM and LLOM implementations. This in particular implies that DOOM's getBody method will now throw an exception if the envelope contains an unexpected element.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java?rev=922673&r1=922672&r2=922673&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java Sat Mar 13 20:37:18 2010
@@ -75,4 +75,15 @@ public class SOAPEnvelopeTestBase extend
         soapFactory.createSOAPHeader(env);
         assertTrue("Header isn't the first child!", env.getFirstElement() instanceof SOAPHeader);
     }
+    
+    public void testGetBodyOnEmptyEnvelope() {
+        assertNull(soapFactory.createSOAPEnvelope().getBody());
+    }
+    
+    // Regression test for WSCOMMONS-526
+    public void testGetBodyOnEnvelopeWithHeaderOnly() {
+        SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();
+        soapFactory.createSOAPHeader(envelope);
+        assertNull(envelope.getBody());
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java?rev=922673&r1=922672&r2=922673&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java Sat Mar 13 20:37:18 2010
@@ -160,17 +160,15 @@ public class SOAPEnvelopeImpl extends SO
                 while (node != null && node.getType() != OMNode.ELEMENT_NODE) {
                     node = node.getNextOMSibling();
                 }
-                element = (OMElement) node;
-
-                if (node != null
-                        && SOAPConstants.BODY_LOCAL_NAME.equals(element
-                        .getLocalName())) {
-                    return (SOAPBody) element;
+                if (node == null) {
+                    // The envelope only contains a header
+                    return null;
+                } else if (SOAPConstants.BODY_LOCAL_NAME.equals(((OMElement)node).getLocalName())) {
+                    return (SOAPBody)node;
+                } else {
+                    throw new OMException("SOAPEnvelope must contain a body element " +
+                            "which is either first or second child element of the SOAPEnvelope.");
                 }
-                /*  else {
-                        throw new OMException(
-                                "SOAPEnvelope must contain a body element which is either first or second child element of the SOAPEnvelope.");
-                    }*/
             }
         }
         return null;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java?rev=922673&r1=922672&r2=922673&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java Sat Mar 13 20:37:18 2010
@@ -171,11 +171,11 @@ public class SOAPEnvelopeImpl extends SO
                 while (node != null && node.getType() != OMNode.ELEMENT_NODE) {
                     node = node.getNextOMSibling();
                 }
-                element = (OMElement) node;
-
-                if (node != null &&
-                        SOAPConstants.BODY_LOCAL_NAME.equals(element.getLocalName())) {
-                    return (SOAPBody) element;
+                if (node == null) {
+                    // The envelope only contains a header
+                    return null;
+                } else if (SOAPConstants.BODY_LOCAL_NAME.equals(((OMElement)node).getLocalName())) {
+                    return (SOAPBody)node;
                 } else {
                     throw new OMException("SOAPEnvelope must contain a body element " +
                             "which is either first or second child element of the SOAPEnvelope.");