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