XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
if (hasFault(message, xmlReader)) {
SOAPFault soapFault =
soapMessage.getSOAPPart().getEnvelope().getBody().addFault();
SoapFault fault =
message.getVersion() instanceof Soap11
? Soap11FaultInInterceptor.unmarshalFault(message, xmlReader)
: Soap12FaultInInterceptor.unmarshalFault(message, xmlReader);
if (fault.getFaultCode() != null) {
soapFault.setFaultCode(fault.getFaultCode());
}
if (fault.getMessage() != null) {
soapFault.setFaultString(fault.getMessage());
}
if (fault.getRole() != null) {
soapFault.setFaultActor(fault.getRole());
}
if (fault.getDetail() != null
&& fault.getDetail().getFirstChild() != null) {
Detail detail = null;
Node child = fault.getDetail().getFirstChild();
while (child != null) {
if (Node.ELEMENT_NODE == child.getNodeType()) {
if (detail == null) {
detail = soapFault.addDetail();
}
Node importedChild = soapMessage.getSOAPPart().importNode(child, true);
detail.appendChild(importedChild);
}
child = child.getNextSibling();
}
}
DOMSource bodySource = new DOMSource(soapFault);
xmlReader = StaxUtils.createXMLStreamReader(bodySource);
} else {
StaxUtils.readDocElements(soapMessage.getSOAPBody(), xmlReader, true);
DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
xmlReader = StaxUtils.createXMLStreamReader(bodySource);
xmlReader.nextTag();
xmlReader.nextTag(); // move past body tag
}
message.setContent(XMLStreamReader.class, xmlReader);
} catch (SOAPException soape) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message(
"SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), soape,
message.getVersion().getSender());
} catch (XMLStreamException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message(
"SOAPHANDLERINTERCEPTOR_EXCEPTION", BUNDLE), e, message
.getVersion().getSender());
}
}