简体   繁体   English

如何在Mule中扩展AbstractMessageTransformer的Java类中处理FileNotFoundException?

[英]How to handle FileNotFoundException in Java class extending AbstractMessageTransformer in Mule?

I am using a custom transformer in mule and for that I am writing custom java code which extends AbstractMessageTransformer. 我在m子中使用自定义转换器,为此,我正在编写扩展AbstractMessageTransformer的自定义Java代码。

I am facing a issue since in the custom java class since I need to handle FileNotFoundException and it says FileNotFoundException is not compatible with AbstractMessageTransformer. 我在自定义Java类中遇到了一个问题,因为我需要处理FileNotFoundException,并且它说FileNotFoundException与AbstractMessageTransformer不兼容。

Is there any way I can handle FileNotFoundException in custom java class that extends AbstractMessageTransformer ?? 有什么方法可以处理扩展AbstractMessageTransformer的自定义Java类中的FileNotFoundException?

If what you want to re-throw the FileNotFoundException within a class extending an AbstractMessageTransformer , then you should probably wrap that exception into a TransformerException , the one thrown by the doTransform method 如果要在扩展AbstractMessageTransformer的类中重新抛出FileNotFoundException ,则可能应该将该异常包装到TransformerException中 ,该异常由doTransform方法抛出

Your method will look like this 您的方法将如下所示

    try{
        //Your custom transformation
    } catch(FileNotFoundException e){
        Message msg = CoreMessages.transformFailedBeforeFilter();
        throw new TransformerException(msg,this, e);
    }
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;
        } 
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM