log.debug(" rootCause =" + t.getClass().getName());
log.debug(" exception=" + t.toString());
log.debug(" stack=" + stackToString(t));
}
XMLFault xmlfault = null;
try {
// There are 5 different categories of exceptions.
// Each category has a little different marshaling code.
// A) Service Exception that matches the JAX-WS
// specification (chapter 2.5 of the spec)
// B) Service Exception that matches the JAX-WS "legacy"
// exception (chapter 3.7 of the spec)
// C) SOAPFaultException
// D) WebServiceException
// E) Other runtime exceptions (i.e. NullPointerException)
// Get the FaultDescriptor matching this Exception.
// If FaultDescriptor is found, this is a JAX-B Service Exception.
// If not found, this is a System Exception
FaultDescription fd =
operationDesc.resolveFaultByExceptionName(t.getClass().getCanonicalName());
if (fd != null) {
if (log.isErrorEnabled()) {
log.debug("Marshal as a Service Exception");
}
// Create the JAXB Context
JAXBBlockContext context = new JAXBBlockContext(marshalDesc.getPackages());
// The exception is a Service Exception.
// It may be (A) JAX-WS compliant exception or
// (B) JAX-WS legacy exception
// The faultBeanObject is a JAXB object that represents the data of the exception.
// It is marshalled in the detail section of the soap fault.
// The faultBeanObject is obtained direction from the exception (A) or via
// the legacy exception rules (B).
Object faultBeanObject = null;
FaultBeanDesc faultBeanDesc = marshalDesc.getFaultBeanDesc(fd);
String faultInfo = fd.getFaultInfo();
if (faultInfo == null || faultInfo.length() == 0) {
// Legacy Exception case
faultBeanObject = LegacyExceptionUtil.createFaultBean(t, fd, marshalDesc);
} else {
// Normal case
// Get the fault bean object.
Method getFaultInfo = t.getClass().getMethod("getFaultInfo", null);
faultBeanObject = getFaultInfo.invoke(t, null);
}
if (log.isErrorEnabled()) {
log.debug("The faultBean type is" + faultBeanObject.getClass().getName());
}
// Use "by java type" marshalling if necessary
if (faultBeanObject == t ||
(context.getConstructionType() != JAXBUtils.CONSTRUCTION_TYPE
.BY_CONTEXT_PATH &&
isNotJAXBRootElement(faultBeanObject.getClass(), marshalDesc))) {
context.setProcessType(faultBeanObject.getClass());
}
QName faultBeanQName = new QName(faultBeanDesc.getFaultBeanNamespace(),
faultBeanDesc.getFaultBeanLocalName());
// Make sure the faultBeanObject can be marshalled as an element
if (!marshalDesc.getAnnotationDesc(faultBeanObject.getClass()).
hasXmlRootElement())
{
faultBeanObject = new JAXBElement(faultBeanQName, faultBeanObject.getClass(),
faultBeanObject);
}
// Create a detailblock representing the faultBeanObject
Block[] detailBlocks = new Block[1];
detailBlocks[0] = factory.createFrom(faultBeanObject, context, faultBeanQName);
if (log.isDebugEnabled()) {
log.debug("Create the xmlFault for the Service Exception");
}
// Get the fault text using algorithm defined in JAX-WS 10.2.2.3
String text = t.getMessage();
if (text == null || text.length() == 0) {
text = t.toString();
}
// Now make a XMLFault containing the detailblock
xmlfault = new XMLFault(null, new XMLFaultReason(text), detailBlocks);
} else {
xmlfault = createXMLFaultFromSystemException(t);
}
} catch (Throwable e) {
// If an exception occurs while demarshalling an exception,