try {
XMLStreamWriter writer = getWriter(message);
Fault fault = getFault(message);
JBIFault jbiFault = JBIFault.createFault(fault);
nsStack.add(JBIConstants.NS_JBI_BINDING);
String prefix = nsStack.getPrefix(JBIConstants.NS_JBI_BINDING);
StaxUtils.writeStartElement(writer, prefix, JBIFault.JBI_FAULT_ROOT,
JBIConstants.NS_JBI_BINDING);
if (!jbiFault.hasDetails()) {
Element faultString = DOMUtils.createDocument().createElement("fault");
faultString.setTextContent(jbiFault.getCause().getMessage());
StaxUtils.writeNode(faultString, writer, true);
} else {
Element detail = jbiFault.getDetail();
Element elem = DOMUtils.getFirstElement(detail);
if (elem != null) {
StaxUtils.writeNode(elem, writer, true);
}
}