}
return fault;
}
public void handleMessage(Message message) throws Fault {
Fault f = (Fault)message.getContent(Exception.class);
Throwable cause = f.getCause();
WebFault fault = null;
if (cause != null) {
fault = getWebFaultAnnotation(cause.getClass());
}
if (cause instanceof Exception && fault != null) {
Exception ex = (Exception)cause;
Object faultInfo = null;
try {
Method method = cause.getClass().getMethod("getFaultInfo", new Class[0]);
faultInfo = method.invoke(cause, new Object[0]);
} catch (NoSuchMethodException e) {
faultInfo = createFaultInfoBean(fault, cause);
} catch (InvocationTargetException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("INVOCATION_TARGET_EXC", BUNDLE), e);
} catch (IllegalAccessException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e);
} catch (IllegalArgumentException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("COULD_NOT_INVOKE", BUNDLE), e);
}
Service service = message.getExchange().get(Service.class);
try {
DataWriter<Node> writer = service.getDataBinding().createWriter(Node.class);
OperationInfo op = message.getExchange().get(BindingOperationInfo.class).getOperationInfo();
QName faultName = getFaultName(fault, cause.getClass(), op);
MessagePartInfo part = getFaultMessagePart(faultName, op);
if (f.hasDetails()) {
writer.write(faultInfo, part, f.getDetail());
} else {
writer.write(faultInfo, part, f.getOrCreateDetail());
if (!f.getDetail().hasChildNodes()) {
f.setDetail(null);
}
}
f.setMessage(ex.getMessage());
} catch (Exception nex) {
//if exception occurs while writing a fault, we'll just let things continue
//and let the rest of the chain try handling it as is.
LOG.log(Level.WARNING, "EXCEPTION_WHILE_WRITING_FAULT", nex);
}