我在mule中使用自定义变换器,为此我正在编写自定义java代码,它扩展了AbstractMessageTransformer。
我在自定义java类中面临一个问题,因为我需要处理FileNotFoundException 它说FileNotFoundException与AbstractMessageTransformer不兼容。
有没有办法在扩展AbstractMessageTransformer的自定义java类中处理FileNotFoundException?
答案 0 :(得分:1)
如果要在扩展 AbstractMessageTransformer 的类中重新抛出 FileNotFoundException ,那么您应该将该异常包装成 TransformerException , doTransform 方法抛出的那个
您的方法将如下所示
try{
//Your custom transformation
} catch(FileNotFoundException e){
Message msg = CoreMessages.transformFailedBeforeFilter();
throw new TransformerException(msg,this, e);
}
答案 1 :(得分:0)
public class MessageAttachmentTransformer extends AbstractMessageTransformer
{private List<String> filename; // file to attach
@SuppressWarnings("deprecation")
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
if (filename.isEmpty() || filename==null || filename.size()==0) **//filename is a list contains list of file path as mule attachment**
{**//If file for attachment is not there**
**//Here I want to place FileNotFoundException**
return message;} else
{ // do other thing} return message;
}
}
}