Using spring ws to get the StreamResult as below
StreamSource source = new StreamSource(new StringReader(MESSAGE)); StreamResult result = new StreamResult(System.out); webServiceTemplate.sendSourceAndReceiveToResult("http://someUri", source, new SoapActionCallback("someCallBack"), result); return result;
I get the result, But I want to extract it to some sort of xml or even as a string (Just want to see the contents in order to generate the response).
How can I do this?
StreamSource source = new StreamSource(new StringReader(MESSAGE)); StreamResult result = new StreamResult(System. out); webServiceTemplate.
public class StreamResult extends Object implements Result. Acts as an holder for a transformation result, which may be XML, plain Text, HTML, or some other form of markup.
public class DOMSource extends Object implements Source. Acts as a holder for a transformation Source tree in the form of a Document Object Model (DOM) tree. Note that XSLT requires namespace support. Attempting to transform a DOM that was not contructed with a namespace-aware parser may result in errors.
Try this one:
try { StreamSource source = new StreamSource(new StringReader("<xml>blabla</xml>")); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(); transformer.transform(source,result); String strResult = writer.toString(); } catch (Exception e) { e.printStackTrace(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With