super(Phase.UNMARSHAL);
addAfter(ClientFaultConverter.class.getName());
}
public void handleMessage(Message msg) {
CorbaMessage message = (CorbaMessage)msg;
try {
SystemException sysEx = message.getSystemException();
if (sysEx != null) {
// TODO: Do we need anything else to handle system exceptions here...i.e. do
// we want to add a wrapper around this so that we can add some more information?
message.setContent(Exception.class, sysEx);
return;
}
CorbaStreamable exStreamable = message.getStreamableException();
if (exStreamable != null) {
DataReader<XMLStreamReader> reader = getDataReader(message);
BindingOperationInfo bopInfo = message.getExchange().get(BindingOperationInfo.class);
OperationInfo opInfo = bopInfo.getOperationInfo();
ServiceInfo service = message.getExchange().get(ServiceInfo.class);
org.omg.CORBA.ORB orb = (org.omg.CORBA.ORB) message.get(CorbaConstants.ORB);
if (orb == null) {
orb = message.getExchange().get(org.omg.CORBA.ORB.class);
}
QName elName = new QName("", exStreamable.getName());
FaultInfo fault = getFaultInfo(opInfo, elName);
CorbaTypeEventProducer faultEventProducer =
CorbaHandlerUtils.getTypeEventProducer(exStreamable.getObject(),
service,
orb);
CorbaStreamReader streamReader = new CorbaStreamReader(faultEventProducer);
Object e = reader.read(fault.getMessageParts().get(0), streamReader);
if (!(e instanceof Exception)) {
Class<?> exClass = fault.getProperty(Class.class.getName(), Class.class);
if (exClass != null) {
Class<?> beanClass = e.getClass();
Constructor<?> constructor =
exClass.getConstructor(new Class[]{String.class, beanClass});
String repId = (message.getStreamableException()._type().id() != null)
? message.getStreamableException()._type().id()
: "";
e = constructor.newInstance(new Object[]{repId, e});
} else {
// Get the Fault
Fault faultEx = (Fault) message.getContent(Exception.class);
if (e instanceof Document) {
createFaultDetail((Document)e, fault, faultEx);
}
e = faultEx;
}
}
message.setContent(Exception.class, e);
}
} catch (java.lang.Exception ex) {
LOG.log(Level.SEVERE, "CORBA unmarshalFault exception", ex);
throw new CorbaBindingException("CORBA unmarshalFault exception", ex);
}