Skip to content

Commit ec3c0e9

Browse files
committed
SWS-302
1 parent 2cb0b52 commit ec3c0e9

17 files changed

+619
-56
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.axiom.soap.SOAPFaultCode;
2929
import org.apache.axiom.soap.SOAPFaultReason;
3030
import org.apache.axiom.soap.SOAPProcessingException;
31+
3132
import org.springframework.util.Assert;
3233
import org.springframework.util.StringUtils;
3334
import org.springframework.ws.soap.SoapFault;
@@ -76,7 +77,7 @@ public Soap11Fault addFault(QName code, String faultString, Locale locale) {
7677
"A fault code with namespace and local part must be specific for a custom fault code");
7778
}
7879
try {
79-
detachAllBodyChildren();
80+
AxiomUtils.removeContents(getAxiomBody());
8081
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
8182
SOAPFaultCode faultCode = getAxiomFactory().createSOAPFaultCode(fault);
8283
setValueText(code, fault, faultCode);
@@ -115,7 +116,7 @@ else if (StringUtils.hasLength(code.getNamespaceURI())) {
115116
private SOAPFault addStandardFault(String localName, String faultString, Locale locale) {
116117
Assert.notNull(faultString, "No faultString given");
117118
try {
118-
detachAllBodyChildren();
119+
AxiomUtils.removeContents(getAxiomBody());
119120
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
120121
SOAPFaultCode faultCode = getAxiomFactory().createSOAPFaultCode(fault);
121122
faultCode.setText(QNameUtils.createQName(fault.getNamespace().getNamespaceURI(), localName,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.axiom.soap.SOAPFaultText;
2929
import org.apache.axiom.soap.SOAPFaultValue;
3030
import org.apache.axiom.soap.SOAPProcessingException;
31+
3132
import org.springframework.util.Assert;
3233
import org.springframework.ws.soap.SoapFault;
3334
import org.springframework.ws.soap.axiom.support.AxiomUtils;
@@ -79,7 +80,7 @@ public Soap12Fault addDataEncodingUnknownFault(QName[] subcodes, String reason,
7980
private SOAPFault addStandardFault(String localName, String faultStringOrReason, Locale locale) {
8081
Assert.notNull(faultStringOrReason, "No faultStringOrReason given");
8182
try {
82-
detachAllBodyChildren();
83+
AxiomUtils.removeContents(getAxiomBody());
8384
SOAPFault fault = getAxiomFactory().createSOAPFault(getAxiomBody());
8485
SOAPFaultCode code = getAxiomFactory().createSOAPFaultCode(fault);
8586
SOAPFaultValue value = getAxiomFactory().createSOAPFaultValue(code);

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

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,15 @@
1616

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

19-
import java.util.Iterator;
20-
import javax.xml.stream.XMLStreamReader;
2119
import javax.xml.transform.Result;
2220
import javax.xml.transform.Source;
2321

24-
import org.apache.axiom.om.OMElement;
25-
import org.apache.axiom.om.OMException;
2622
import org.apache.axiom.soap.SOAPBody;
2723
import org.apache.axiom.soap.SOAPFactory;
2824
import org.apache.axiom.soap.SOAPFault;
2925

3026
import org.springframework.ws.soap.SoapBody;
3127
import org.springframework.ws.soap.SoapFault;
32-
import org.springframework.ws.soap.axiom.support.AxiomUtils;
33-
import org.springframework.xml.transform.StaxSource;
3428

3529
/**
3630
* Axiom-specific version of <code>org.springframework.ws.soap.Soap11Body</code>.
@@ -40,36 +34,24 @@
4034
*/
4135
abstract class AxiomSoapBody extends AxiomSoapElement implements SoapBody {
4236

43-
private boolean payloadCaching;
37+
private final Payload payload;
4438

4539
protected AxiomSoapBody(SOAPBody axiomBody, SOAPFactory axiomFactory, boolean payloadCaching) {
4640
super(axiomBody, axiomFactory);
47-
this.payloadCaching = payloadCaching;
41+
if (payloadCaching) {
42+
payload = new CachingPayload(axiomBody, axiomFactory);
43+
}
44+
else {
45+
payload = new NonCachingPayload(axiomBody, axiomFactory);
46+
}
4847
}
4948

5049
public Source getPayloadSource() {
51-
try {
52-
OMElement payloadElement = getPayloadElement();
53-
XMLStreamReader streamReader;
54-
if (payloadElement == null) {
55-
return null;
56-
}
57-
else if (payloadCaching) {
58-
streamReader = payloadElement.getXMLStreamReader();
59-
}
60-
else {
61-
streamReader = payloadElement.getXMLStreamReaderWithoutCaching();
62-
}
63-
return new StaxSource(streamReader);
64-
}
65-
catch (OMException ex) {
66-
throw new AxiomSoapBodyException(ex);
67-
}
50+
return payload.getSource();
6851
}
6952

7053
public Result getPayloadResult() {
71-
AxiomUtils.removeContents(getAxiomBody());
72-
return new AxiomResult(getAxiomBody(), getAxiomFactory());
54+
return payload.getResult();
7355
}
7456

7557
public boolean hasFault() {
@@ -81,23 +63,6 @@ public SoapFault getFault() {
8163
return axiomFault != null ? new AxiomSoap11Fault(axiomFault, getAxiomFactory()) : null;
8264
}
8365

84-
private OMElement getPayloadElement() throws OMException {
85-
return getAxiomBody().getFirstElement();
86-
}
87-
88-
protected void detachAllBodyChildren() {
89-
try {
90-
for (Iterator iterator = getAxiomBody().getChildElements(); iterator.hasNext();) {
91-
OMElement child = (OMElement) iterator.next();
92-
child.detach();
93-
}
94-
}
95-
catch (OMException ex) {
96-
throw new AxiomSoapBodyException(ex);
97-
}
98-
99-
}
100-
10166
protected final SOAPBody getAxiomBody() {
10267
return (SOAPBody) getAxiomElement();
10368
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.apache.axiom.soap.SOAPEnvelope;
88
import org.apache.axiom.soap.SOAPFactory;
99
import org.apache.axiom.soap.SOAPHeader;
10+
1011
import org.springframework.ws.soap.SoapBody;
1112
import org.springframework.ws.soap.SoapEnvelope;
1213
import org.springframework.ws.soap.SoapHeader;
@@ -23,7 +24,7 @@ class AxiomSoapEnvelope extends AxiomSoapElement implements SoapEnvelope {
2324

2425
private AxiomSoapBody body;
2526

26-
public AxiomSoapEnvelope(SOAPEnvelope axiomEnvelope, SOAPFactory axiomFactory, boolean payloadCaching) {
27+
AxiomSoapEnvelope(SOAPEnvelope axiomEnvelope, SOAPFactory axiomFactory, boolean payloadCaching) {
2728
super(axiomEnvelope, axiomFactory);
2829
this.payloadCaching = payloadCaching;
2930
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public void writeTo(OutputStream outputStream) throws IOException {
214214
transportOutputStream.addHeader(TransportConstants.HEADER_CONTENT_TYPE, contentType);
215215
transportOutputStream.addHeader(TransportConstants.HEADER_SOAP_ACTION, soapAction);
216216
}
217+
217218
if (payloadCaching) {
218219
axiomMessage.serialize(outputStream, format);
219220
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright 2008 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.ws.soap.axiom;
18+
19+
import javax.xml.stream.XMLStreamReader;
20+
import javax.xml.transform.Result;
21+
22+
import org.apache.axiom.om.OMElement;
23+
import org.apache.axiom.soap.SOAPBody;
24+
import org.apache.axiom.soap.SOAPFactory;
25+
26+
/**
27+
* @author Arjen Poutsma
28+
* @since 1.5.2
29+
*/
30+
class CachingPayload extends Payload {
31+
32+
CachingPayload(SOAPBody axiomBody, SOAPFactory axiomFactory) {
33+
super(axiomBody, axiomFactory);
34+
}
35+
36+
protected XMLStreamReader getStreamReader(OMElement payloadElement) {
37+
return payloadElement.getXMLStreamReader();
38+
}
39+
40+
public Result getResultInternal() {
41+
return new AxiomResult(getAxiomBody(), getAxiomFactory());
42+
}
43+
44+
}

0 commit comments

Comments
 (0)