String text = soapFault.getFaultString();
Locale locale = soapFault.getFaultStringLocale();
XMLFaultReason reason = new XMLFaultReason(text, localeToXmlLang(locale));
// Construct the XMLFault from the required information (code, reason, detail blocks)
XMLFault xmlFault = new XMLFault(code, reason, detailBlocks);
boolean isSOAP12 =
soapFault.getNamespaceURI().equals(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE);
// Add the secondary fault information
// Get the SubCodes
if (isSOAP12) {
Iterator it = soapFault.getFaultSubcodes();
List<QName> list = new ArrayList<QName>();
while (it.hasNext()) {
QName qName = (QName)it.next();
list.add(qName);
}
if (list.size() > 0) {
QName[] subCodes = new QName[list.size()];
subCodes = list.toArray(subCodes);
xmlFault.setSubCodes(subCodes);
}
}
// Get the secondary Reasons...the first reason was already saved as the primary reason
if (isSOAP12) {
try {
Iterator it = soapFault.getFaultReasonLocales();
boolean first = true;
List<XMLFaultReason> list = new ArrayList<XMLFaultReason>();
while (it.hasNext()) {
locale = (Locale)it.next();
if (first) {
first = false;
} else {
text = soapFault.getFaultReasonText(locale);
list.add(new XMLFaultReason(text, localeToXmlLang(locale)));
}
}
if (list.size() > 0) {
XMLFaultReason[] secondaryReasons = new XMLFaultReason[list.size()];
secondaryReasons = list.toArray(secondaryReasons);
xmlFault.setSecondaryReasons(secondaryReasons);
}
} catch (SOAPException se) {
throw ExceptionFactory.makeWebServiceException(se);
}
}
// Get the Node
if (isSOAP12) {
String soapNode = soapFault.getFaultNode();
if (soapNode != null) {
xmlFault.setNode(soapNode);
}
}
// Get the Role
String soapRole = soapFault
.getFaultActor(); // getFaultActor works for both SOAP 1.1 and SOAP 1.2 per spec
if (soapRole != null) {
xmlFault.setRole(soapRole);
}
return xmlFault;
}