body.removeContents();
SOAPFault soapFault = body.addFault();
if (exception instanceof SOAPFaultException) {
SOAPFaultException sf = (SOAPFaultException)exception;
soapFault.setFaultString(sf.getFault().getFaultString());
soapFault.setFaultCode(sf.getFault().getFaultCodeAsQName());
soapFault.setFaultActor(sf.getFault().getFaultActor());
if (sf.getFault().hasDetail()) {
Node nd = originalMsg.getSOAPPart().importNode(
sf.getFault().getDetail()
.getFirstChild(), true);
soapFault.addDetail().appendChild(nd);
}
} else if (exception instanceof Fault) {
SoapFault sf = SoapFault.createFault((Fault)exception, ((SoapMessage)message)
.getVersion());
soapFault.setFaultString(sf.getReason());
soapFault.setFaultCode(sf.getFaultCode());
if (sf.hasDetails()) {
soapFault.addDetail();
Node nd = originalMsg.getSOAPPart().importNode(sf.getDetail(), true);
nd = nd.getFirstChild();
while (nd != null) {
soapFault.getDetail().appendChild(nd);
nd = nd.getNextSibling();
}