Skip to content

Commit f189e86

Browse files
veithengregturn
authored andcommitted
SWS-986 - Upgrade Axiom and use new API to convert Document to SOAPMessage
Original pull-request: #82
1 parent 35a7265 commit f189e86

File tree

3 files changed

+8
-64
lines changed

3 files changed

+8
-64
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ configure(allprojects) {
1414

1515
ext.springVersion = "4.2.8.RELEASE"
1616
ext.springSecurityVersion = "4.0.4.RELEASE"
17-
ext.axiomVersion = "1.2.16"
17+
ext.axiomVersion = "1.2.20"
1818
ext.smackVersion = "4.1.9"
1919

2020
apply plugin: "java"

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
import java.util.Iterator;
2626
import javax.activation.DataHandler;
2727
import javax.xml.stream.XMLStreamException;
28+
import javax.xml.transform.dom.DOMSource;
2829

2930
import org.apache.axiom.attachments.Attachments;
3031
import org.apache.axiom.om.OMElement;
3132
import org.apache.axiom.om.OMException;
3233
import org.apache.axiom.om.OMOutputFormat;
34+
import org.apache.axiom.om.OMXMLBuilderFactory;
3335
import org.apache.axiom.om.impl.MTOMConstants;
3436
import org.apache.axiom.om.impl.OMMultipartWriter;
3537
import org.apache.axiom.soap.SOAPBody;
@@ -212,12 +214,9 @@ public Document getDocument() {
212214
public void setDocument(Document document) {
213215
// save the Soap Action
214216
String soapAction = getSoapAction();
215-
SOAPEnvelope envelope = AxiomUtils.toEnvelope(document);
216-
SOAPMessage newMessage = axiomFactory.createSOAPMessage();
217-
newMessage.setSOAPEnvelope(envelope);
218-
219217
// replace the Axiom message
220-
setAxiomMessage(newMessage);
218+
setAxiomMessage(OMXMLBuilderFactory.createSOAPModelBuilder(axiomFactory.getMetaFactory(),
219+
new DOMSource(document)).getSOAPMessage());
221220
// restore the Soap Action
222221
setSoapAction(soapAction);
223222
}

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

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,21 @@
1818

1919
import java.io.ByteArrayInputStream;
2020
import java.io.ByteArrayOutputStream;
21-
import java.io.IOException;
22-
import java.io.OutputStream;
2321
import java.util.Iterator;
2422
import java.util.Locale;
2523
import javax.xml.namespace.QName;
2624
import javax.xml.parsers.DocumentBuilderFactory;
27-
import javax.xml.stream.XMLInputFactory;
25+
import javax.xml.transform.dom.DOMSource;
2826

2927
import org.apache.axiom.om.OMContainer;
3028
import org.apache.axiom.om.OMElement;
3129
import org.apache.axiom.om.OMException;
3230
import org.apache.axiom.om.OMNamespace;
33-
import org.apache.axiom.om.util.StAXUtils;
31+
import org.apache.axiom.om.OMXMLBuilderFactory;
3432
import org.apache.axiom.soap.SOAPEnvelope;
35-
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
36-
import org.w3c.dom.DOMImplementation;
3733
import org.w3c.dom.Document;
3834
import org.w3c.dom.Element;
39-
import org.w3c.dom.ls.DOMImplementationLS;
40-
import org.w3c.dom.ls.LSOutput;
41-
import org.w3c.dom.ls.LSSerializer;
4235

43-
import org.springframework.util.Assert;
4436
import org.springframework.util.StringUtils;
4537

4638
/**
@@ -145,54 +137,7 @@ public static Document toDocument(SOAPEnvelope envelope) {
145137
* @throws IllegalArgumentException in case of errors
146138
*/
147139
public static SOAPEnvelope toEnvelope(Document document) {
148-
try {
149-
DOMImplementation implementation = document.getImplementation();
150-
Assert.isInstanceOf(DOMImplementationLS.class, implementation);
151-
152-
DOMImplementationLS loadSaveImplementation = (DOMImplementationLS) implementation;
153-
LSOutput output = loadSaveImplementation.createLSOutput();
154-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
155-
output.setByteStream(bos);
156-
157-
LSSerializer serializer = loadSaveImplementation.createLSSerializer();
158-
serializer.write(document, output);
159-
160-
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
161-
162-
XMLInputFactory inputFactory = StAXUtils.getXMLInputFactory();
163-
164-
@SuppressWarnings("deprecation")
165-
StAXSOAPModelBuilder stAXSOAPModelBuilder =
166-
new StAXSOAPModelBuilder(inputFactory.createXMLStreamReader(bis), null);
167-
SOAPEnvelope envelope = stAXSOAPModelBuilder.getSOAPEnvelope();
168-
169-
// Necessary to build a correct Axiom tree, see SWS-483
170-
envelope.serialize(new NullOutputStream());
171-
172-
return envelope;
173-
}
174-
catch (Exception ex) {
175-
IllegalArgumentException iaex =
176-
new IllegalArgumentException("Error in converting Document to SOAP Envelope");
177-
iaex.initCause(ex);
178-
throw iaex;
179-
}
180-
}
181-
182-
/** OutputStream that does nothing. */
183-
private static class NullOutputStream extends OutputStream {
184-
185-
@Override
186-
public void write(int b) throws IOException {
187-
}
188-
189-
@Override
190-
public void write(byte[] b) throws IOException {
191-
}
192-
193-
@Override
194-
public void write(byte[] b, int off, int len) throws IOException {
195-
}
140+
return OMXMLBuilderFactory.createSOAPModelBuilder(new DOMSource(document)).getSOAPEnvelope();
196141
}
197142

198143
}

0 commit comments

Comments
 (0)