Last active
July 27, 2017 05:41
-
-
Save IsurangaPerera/373652c3693e1cca688863d030736dbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public SOAPMessage buildSoapResponse(Source response) throws SOAPException { | |
MessageFactory factory = MessageFactory.newInstance(); | |
SOAPMessage soapMsg = factory.createMessage(); | |
SOAPPart part = soapMsg.getSOAPPart(); | |
SOAPEnvelope envelope = part.getEnvelope(); | |
SOAPBody body = envelope.getBody(); | |
StringWriter writer = new StringWriter(); | |
StreamResult result = new StreamResult(writer); | |
TransformerFactory tf = TransformerFactory.newInstance(); | |
Transformer transformer = null; | |
try { | |
transformer = tf.newTransformer(); | |
transformer.transform(response, result); | |
} catch (TransformerException e) { | |
e.printStackTrace(); | |
} | |
DocumentBuilder db = null; | |
DocumentBuilderFactory dFact = DocumentBuilderFactory.newInstance(); | |
dFact.setNamespaceAware(true); | |
try { | |
db = dFact.newDocumentBuilder(); | |
} catch (ParserConfigurationException e1) { | |
e1.printStackTrace(); | |
} | |
InputSource is = new InputSource(); | |
is.setCharacterStream(new StringReader(writer.toString())); | |
Document doc = null; | |
try { | |
doc = db.parse(is); | |
} catch (SAXException | IOException e) { | |
e.printStackTrace(); | |
} | |
body.addDocument(doc); | |
return soapMsg; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment