Toolkit for parsing SOAP message
As part of my project, I need to be able to parse a SOAP response from a remote service end-point, and convert it into a custom XML format. My project should be agnostic of the schema used by the SOAP response. However, my first step involves parsing the SOAP message and extracting the relevant sections - Headers, Body, Attachments, Faults. Currently, to do this I'm using the StaX parser.
I was wondering if there's any toolkit available to perform this task so that I wouldn't have to re-invent the wheel again. Especially more so when it comes to handling complexities related to retrieving binary data attachment开发者_如何学编程s w/ their correct Mime types, etc.
Some pseudo-code examples -
SOAPLib s = new SOAPLib(soapResp);
SOAPHeader h s.getHeader();
h.getHeaders();
String body = s.getBody()
SOAPAttachment sa = s.getAttachment(id);
...
...
The "SOAP with Attachments API for Java (SAAJ)" is built into the jdk in the javax.xml.soap package. A tutorial can be found here.
The Api is based on the DOM, to parse a soap message you can either use the SoapFactory#createElement(Element domElement) method in SOAPFactory
or the MessageFactory#createMessage(MimeHeaders headers, InputStream in) in MessageFactory
.
精彩评论