String node = null;
Element detail = null;
Map<String, String> ns = new HashMap<String, String>();
ns.put("s", Soap12.SOAP_NAMESPACE);
XPathUtils xu = new XPathUtils(ns);
try {
Node mainNode = message.getContent(Node.class);
Node fault = null;
if (reader instanceof W3CDOMStreamReader) {
W3CDOMStreamReader dr = (W3CDOMStreamReader)reader;
fault = dr.getCurrentElement();
dr.consumeFrame();
} else if (mainNode != null) {
Node bodyNode = (Node) xu.getValue("//s:Body",
mainNode,
XPathConstants.NODE);
StaxUtils.readDocElements(bodyNode.getOwnerDocument(),
bodyNode,
new FragmentStreamReader(reader),
false, false);
fault = (Element)xu.getValue("//s:Fault", bodyNode, XPathConstants.NODE);
} else {
fault = StaxUtils.read(new FragmentStreamReader(reader));
}
Element el = (Element)xu.getValue("//s:Fault/s:Code/s:Value",
fault,
XPathConstants.NODE);
if (el != null) {
faultCode = XMLUtils.getQName(el.getTextContent(), el);
}
el = (Element)xu.getValue("//s:Fault/s:Code/s:Subcode",
fault,
XPathConstants.NODE);
if (el != null) {
subCodes = new LinkedList<QName>();
NodeList vlist = el.getElementsByTagNameNS(Soap12.SOAP_NAMESPACE, "Value");
for (int i = 0; i < vlist.getLength(); i++) {
Node v = vlist.item(i);
subCodes.add(XMLUtils.getQName(v.getTextContent(), v));
}
}
exMessage = (String) xu.getValue("//s:Fault/s:Reason/s:Text/text()",
fault,
XPathConstants.STRING);
Node detailNode = (Node) xu.getValue("//s:Fault/s:Detail",
fault,
XPathConstants.NODE);
if (detailNode != null) {
detail = (Element) detailNode;
}
role = (String) xu.getValue("//s:Fault/s:Role/text()",
fault,
XPathConstants.STRING);
node = (String) xu.getValue("//s:Fault/s:Node/text()",
fault,
XPathConstants.STRING);
} catch (XMLStreamException e) {
throw new SoapFault("Could not parse message.",
e,