* @see org.apache.tuscany.spi.wire.Interceptor#invoke(org.apache.tuscany.spi.wire.Message)
*/
public Message invoke(Message msg) {
Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType());
msg.setBody(input);
Message resultMsg = next.invoke(msg);
Object result = resultMsg.getBody();
// FIXME: How to deal with faults?
if (resultMsg.isFault()) {
// We need to figure out what fault type it is and then transform it back the source fault type
throw new InvocationRuntimeException((Throwable) result);
} else if (result != null) {
// FIXME: Should we fix the Operation model so that getOutputType returns DataType<DataType<T>>?
DataType<DataType> targetType =
new DataType<DataType>("idl:output", Object.class, targetOperation.getOutputType());
targetType.setMetadata(Operation.class.getName(), targetOperation.getOutputType().getMetadata(
Operation.class.getName()));
DataType<DataType> sourceType =
new DataType<DataType>("idl:output", Object.class, sourceOperation.getOutputType());
sourceType.setMetadata(Operation.class.getName(), sourceOperation.getOutputType().getMetadata(
Operation.class.getName()));
result = transform(result, targetType, sourceType);
resultMsg.setBody(result);
}
return resultMsg;
}