Skip to content

Commit 8aa15a0

Browse files
committed
Backported SWS-266 to 1.0 branch
1 parent dab62fc commit 8aa15a0

File tree

10 files changed

+47
-53
lines changed

10 files changed

+47
-53
lines changed

core/src/main/java/org/springframework/ws/WebServiceMessage.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,11 @@ public interface WebServiceMessage {
4242
Source getPayloadSource();
4343

4444
/**
45-
* Returns the contents of the message as a {@link Result}. <p>Implementations that are read-only will throw an
46-
* {@link UnsupportedOperationException}.
45+
* Returns the contents of the message as a {@link Result}.
46+
* <p/>
47+
* Calling this method removes the current payload.
48+
* <p/>
49+
* Implementations that are read-only will throw an {@link UnsupportedOperationException}.
4750
*
4851
* @return the message contents
4952
* @throws UnsupportedOperationException if the message is read-only

core/src/main/java/org/springframework/ws/soap/SoapBody.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import javax.xml.transform.Result;
2121
import javax.xml.transform.Source;
2222

23+
import org.springframework.ws.WebServiceMessage;
24+
2325
/**
2426
* Represents the <code>Body</code> element in a SOAP message. A SOAP body contains the <strong>payload</strong> of the
2527
* message. This payload can be custom XML, or a <code>SoapFault</code> (but not both).
@@ -40,13 +42,17 @@ public interface SoapBody extends SoapElement {
4042
* Returns a <code>Source</code> that represents the contents of the body.
4143
*
4244
* @return the message contents
45+
* @see WebServiceMessage#getPayloadSource()
4346
*/
4447
Source getPayloadSource();
4548

4649
/**
4750
* Returns a <code>Result</code> that represents the contents of the body.
51+
* <p/>
52+
* Calling this method removes the current content of the body.
4853
*
4954
* @return the message contents
55+
* @see WebServiceMessage#getPayloadResult()
5056
*/
5157
Result getPayloadResult();
5258

core/src/main/java/org/springframework/ws/soap/axiom/AxiomContentHandler.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapBody.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.axiom.soap.SOAPFault;
2929
import org.springframework.ws.soap.SoapBody;
3030
import org.springframework.ws.soap.SoapFault;
31+
import org.springframework.ws.soap.axiom.support.AxiomUtils;
3132
import org.springframework.xml.transform.StaxSource;
3233

3334
/**
@@ -64,7 +65,8 @@ else if (payloadCaching) {
6465
}
6566

6667
public Result getPayloadResult() {
67-
return new SAXResult(new AxiomContentHandler(getAxiomBody()));
68+
AxiomUtils.removeContents(getAxiomBody());
69+
return new SAXResult(new AxiomHandler(getAxiomBody(), getAxiomFactory()));
6870
}
6971

7072
public boolean hasFault() {

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetail.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Iterator getDetailEntries() {
5656
}
5757

5858
public Result getResult() {
59-
return new SAXResult(new AxiomContentHandler(getAxiomFaultDetail()));
59+
return new SAXResult(new AxiomHandler(getAxiomFaultDetail(), getAxiomFactory()));
6060
}
6161

6262
protected SOAPFaultDetail getAxiomFaultDetail() {

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapFaultDetailElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public AxiomSoapFaultDetailElement(OMElement axiomElement, SOAPFactory soapFacto
3838

3939
public Result getResult() {
4040
try {
41-
return new SAXResult(new AxiomContentHandler(getAxiomElement()));
41+
return new SAXResult(new AxiomHandler(getAxiomElement(), getAxiomFactory()));
4242
}
4343
catch (OMException ex) {
4444
throw new AxiomSoapFaultException(ex);

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ abstract class AxiomSoapHeader extends AxiomSoapElement implements SoapHeader {
4444
}
4545

4646
public Result getResult() {
47-
return new SAXResult(new AxiomContentHandler(getAxiomHeader()));
47+
return new SAXResult(new AxiomHandler(getAxiomHeader(), getAxiomFactory()));
4848
}
4949

5050
public SoapHeaderElement addHeaderElement(QName name) {

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapHeaderElement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void setMustUnderstand(boolean mustUnderstand) {
4949

5050
public Result getResult() {
5151
try {
52-
return new SAXResult(new AxiomContentHandler(getAxiomHeaderBlock()));
52+
return new SAXResult(new AxiomHandler(getAxiomHeaderBlock(), getAxiomFactory()));
5353
}
5454
catch (OMException ex) {
5555
throw new AxiomSoapHeaderException(ex);

core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616

1717
package org.springframework.ws.soap.axiom.support;
1818

19+
import java.util.Iterator;
1920
import java.util.Locale;
2021
import javax.xml.namespace.QName;
2122

23+
import org.apache.axiom.om.OMContainer;
2224
import org.apache.axiom.om.OMElement;
2325
import org.apache.axiom.om.OMException;
2426
import org.apache.axiom.om.OMNamespace;
27+
import org.apache.axiom.om.OMNode;
28+
2529
import org.springframework.util.StringUtils;
2630
import org.springframework.xml.namespace.QNameUtils;
2731

@@ -81,5 +85,13 @@ public static Locale toLocale(String language) {
8185
return StringUtils.parseLocaleString(language);
8286
}
8387

88+
/** Removes the contents (i.e. children) of the container. */
89+
public static void removeContents(OMContainer container) {
90+
for (Iterator iterator = container.getChildren(); iterator.hasNext();) {
91+
OMNode child = (OMNode) iterator.next();
92+
child.detach();
93+
}
94+
}
95+
8496

8597
}

core/src/test/java/org/springframework/ws/soap/AbstractSoapBodyTestCase.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
package org.springframework.ws.soap;
1818

1919
import java.util.Locale;
20+
import javax.xml.transform.dom.DOMResult;
21+
22+
import org.w3c.dom.Document;
23+
import org.w3c.dom.Element;
24+
import org.w3c.dom.NodeList;
2025

2126
import org.springframework.xml.transform.StringResult;
2227
import org.springframework.xml.transform.StringSource;
@@ -34,11 +39,21 @@ protected final SoapElement createSoapElement() throws Exception {
3439

3540
public void testPayload() throws Exception {
3641
String payload = "<payload xmlns='http://www.springframework.org' />";
37-
StringSource contents = new StringSource(payload);
38-
transformer.transform(contents, soapBody.getPayloadResult());
42+
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
3943
assertPayloadEqual(payload);
4044
}
4145

46+
public void testGetPayloadResultTwice() throws Exception {
47+
String payload = "<payload xmlns='http://www.springframework.org' />";
48+
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
49+
transformer.transform(new StringSource(payload), soapBody.getPayloadResult());
50+
DOMResult domResult = new DOMResult();
51+
transformer.transform(soapBody.getSource(), domResult);
52+
Element bodyElement = ((Document) domResult.getNode()).getDocumentElement();
53+
NodeList children = bodyElement.getChildNodes();
54+
assertEquals("Invalid amount of child nodes", 1, children.getLength());
55+
}
56+
4257
public void testNoFault() throws Exception {
4358
assertFalse("body has fault", soapBody.hasFault());
4459
}

0 commit comments

Comments
 (0)