diff --git a/core/src/main/java/org/springframework/ws/WebServiceMessage.java b/core/src/main/java/org/springframework/ws/WebServiceMessage.java index b6bbfe63..150709e2 100644 --- a/core/src/main/java/org/springframework/ws/WebServiceMessage.java +++ b/core/src/main/java/org/springframework/ws/WebServiceMessage.java @@ -42,8 +42,11 @@ public interface WebServiceMessage { Source getPayloadSource(); /** - * Returns the contents of the message as a {@link Result}.
Implementations that are read-only will throw an - * {@link UnsupportedOperationException}. + * Returns the contents of the message as a {@link Result}. + *
+ * Calling this method removes the current payload. + * + * Implementations that are read-only will throw an {@link UnsupportedOperationException}. * * @return the message contents * @throws UnsupportedOperationException if the message is read-only diff --git a/core/src/main/java/org/springframework/ws/soap/SoapBody.java b/core/src/main/java/org/springframework/ws/soap/SoapBody.java index c625977a..221a5f00 100644 --- a/core/src/main/java/org/springframework/ws/soap/SoapBody.java +++ b/core/src/main/java/org/springframework/ws/soap/SoapBody.java @@ -20,6 +20,8 @@ import java.util.Locale; import javax.xml.transform.Result; import javax.xml.transform.Source; +import org.springframework.ws.WebServiceMessage; + /** * Represents theBody element in a SOAP message. A SOAP body contains the payload of the
* message. This payload can be custom XML, or a SoapFault (but not both).
@@ -40,13 +42,17 @@ public interface SoapBody extends SoapElement {
* Returns a Source that represents the contents of the body.
*
* @return the message contents
+ * @see WebServiceMessage#getPayloadSource()
*/
Source getPayloadSource();
/**
* Returns a Result that represents the contents of the body.
+ *
+ * Calling this method removes the current content of the body.
*
* @return the message contents
+ * @see WebServiceMessage#getPayloadResult()
*/
Result getPayloadResult();
diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapBody.java b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapBody.java
index 11564c58..6c013e6b 100644
--- a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapBody.java
+++ b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapBody.java
@@ -30,6 +30,7 @@ import org.apache.axiom.soap.SOAPFault;
import org.springframework.ws.soap.SoapBody;
import org.springframework.ws.soap.SoapFault;
+import org.springframework.ws.soap.axiom.support.AxiomUtils;
import org.springframework.xml.transform.StaxSource;
/**
@@ -68,6 +69,7 @@ abstract class AxiomSoapBody extends AxiomSoapElement implements SoapBody {
}
public Result getPayloadResult() {
+ AxiomUtils.removeContents(getAxiomBody());
return new SAXResult(new AxiomContentHandler(getAxiomBody(), getAxiomFactory()));
}
diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java b/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java
index 13512c5e..514af22d 100644
--- a/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java
+++ b/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java
@@ -16,12 +16,16 @@
package org.springframework.ws.soap.axiom.support;
+import java.util.Iterator;
import java.util.Locale;
import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMContainer;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMException;
import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
+
import org.springframework.util.StringUtils;
import org.springframework.xml.namespace.QNameUtils;
@@ -81,5 +85,13 @@ public abstract class AxiomUtils {
return StringUtils.parseLocaleString(language);
}
+ /** Removes the contents (i.e. children) of the container. */
+ public static void removeContents(OMContainer container) {
+ for (Iterator iterator = container.getChildren(); iterator.hasNext();) {
+ OMNode child = (OMNode) iterator.next();
+ child.detach();
+ }
+ }
+
}
diff --git a/core/src/test/java/org/springframework/ws/soap/AbstractSoapBodyTestCase.java b/core/src/test/java/org/springframework/ws/soap/AbstractSoapBodyTestCase.java
index 461841d0..32a2cede 100644
--- a/core/src/test/java/org/springframework/ws/soap/AbstractSoapBodyTestCase.java
+++ b/core/src/test/java/org/springframework/ws/soap/AbstractSoapBodyTestCase.java
@@ -17,6 +17,11 @@
package org.springframework.ws.soap;
import java.util.Locale;
+import javax.xml.transform.dom.DOMResult;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
import org.springframework.xml.transform.StringResult;
import org.springframework.xml.transform.StringSource;
@@ -34,11 +39,21 @@ public abstract class AbstractSoapBodyTestCase extends AbstractSoapElementTestCa
public void testPayload() throws Exception {
String payload = "