QName faultCode = ((NameImpl)soapFault.getFaultCodeAsName()).toQName();
String faultString = soapFault.getFaultString();
String faultActor = soapFault.getFaultActor();
Detail detail = soapFault.getDetail();
SOAPFaultException faultEx = new SOAPFaultException(faultCode, faultString, faultActor, detail);
CommonMessageContext msgContext = MessageContextAssociation.peekMessageContext();
if (detail != null && msgContext != null)
{
SerializationContext serContext = msgContext.getSerializationContext();
TypeMapping typeMapping = serContext.getTypeMapping();
Iterator it = detail.getDetailEntries();
while (it.hasNext())
{
DetailEntry deElement = (DetailEntry)it.next();
Name deName = deElement.getElementName();
QName xmlName = new QName(deName.getURI(), deName.getLocalName());
OperationMetaData opMetaData = msgContext.getOperationMetaData();
FaultMetaData faultMetaData = opMetaData.getFault(xmlName);
if (faultMetaData != null)
{
if (log.isDebugEnabled())
log.debug("Deserialize fault: " + faultMetaData);
QName xmlType = faultMetaData.getXmlType();
Class javaType = faultMetaData.getJavaType();
// Get the deserializer from the type mapping
AbstractDeserializerFactory desFactory = (AbstractDeserializerFactory)typeMapping.getDeserializer(javaType, xmlType);
if (desFactory == null)
throw new JAXRPCException("Cannot obtain deserializer factory for: " + xmlType);
// Try jaxb deserialization
try
{
// http://jira.jboss.org/jira/browse/JBWS-955
// Cannot deserialize fault detail
String prefix = deName.getPrefix();
if (prefix.length() > 0)
{
String nsURI = deName.getURI();
String attrValue = deElement.getAttribute("xmlns:" + prefix);
if (nsURI.length() > 0 && attrValue.length() == 0)
deElement.addNamespaceDeclaration(prefix, nsURI);
}
Source xmlFragment = new DOMSource(deElement);
DeserializerSupport des = (DeserializerSupport)desFactory.getDeserializer();
Object userEx = des.deserialize(xmlName, xmlType, xmlFragment, serContext);
if (userEx == null || (userEx instanceof Exception) == false)
throw new WSException("Invalid deserialization result: " + userEx);
faultEx.initCause((Exception)userEx);
}
catch (RuntimeException rte)
{
throw rte;
}