|
18 | 18 |
|
19 | 19 | import java.io.ByteArrayInputStream; |
20 | 20 | import java.io.ByteArrayOutputStream; |
21 | | -import java.io.IOException; |
22 | | -import java.io.OutputStream; |
23 | 21 | import java.util.Iterator; |
24 | 22 | import java.util.Locale; |
25 | 23 | import javax.xml.namespace.QName; |
26 | 24 | import javax.xml.parsers.DocumentBuilderFactory; |
27 | | -import javax.xml.stream.XMLInputFactory; |
| 25 | +import javax.xml.transform.dom.DOMSource; |
28 | 26 |
|
29 | 27 | import org.apache.axiom.om.OMContainer; |
30 | 28 | import org.apache.axiom.om.OMElement; |
31 | 29 | import org.apache.axiom.om.OMException; |
32 | 30 | import org.apache.axiom.om.OMNamespace; |
33 | | -import org.apache.axiom.om.util.StAXUtils; |
| 31 | +import org.apache.axiom.om.OMXMLBuilderFactory; |
34 | 32 | import org.apache.axiom.soap.SOAPEnvelope; |
35 | | -import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; |
36 | | -import org.w3c.dom.DOMImplementation; |
37 | 33 | import org.w3c.dom.Document; |
38 | 34 | 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; |
42 | 35 |
|
43 | | -import org.springframework.util.Assert; |
44 | 36 | import org.springframework.util.StringUtils; |
45 | 37 |
|
46 | 38 | /** |
@@ -145,54 +137,7 @@ public static Document toDocument(SOAPEnvelope envelope) { |
145 | 137 | * @throws IllegalArgumentException in case of errors |
146 | 138 | */ |
147 | 139 | 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(); |
196 | 141 | } |
197 | 142 |
|
198 | 143 | } |
0 commit comments