0

I am using a custom transformer in mule and for that I am writing custom java code which extends AbstractMessageTransformer.

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.

Is there any way I can handle FileNotFoundException in custom java class that extends AbstractMessageTransformer ??

Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81

2 Answers2

1

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

Your method will look like this

    try{
        //Your custom transformation
    } catch(FileNotFoundException e){
        Message msg = CoreMessages.transformFailedBeforeFilter();
        throw new TransformerException(msg,this, e);
    }
genjosanzo
  • 3,264
  • 2
  • 16
  • 21
  • Could you Please Explain the way to wrap that exception into a TransformerException – Anirban Sen Chowdhary Sep 21 '13 at 22:32
  • Thanks ... I tried with **doTransform** and FileNotFoundException but didn't end up well – Anirban Sen Chowdhary Sep 22 '13 at 16:27
  • 1
    What problem are you experiencing with this approach? – genjosanzo Sep 22 '13 at 16:28
  • public class MessageAttachmentTransformer extends AbstractMessageTransformer { private List 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; } } } – Anirban Sen Chowdhary Sep 22 '13 at 16:37
  • You should first check if the filename is null, otherwise filename.isEmpty() will most probably cause a NPE – genjosanzo Sep 23 '13 at 01:00
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;
        } 
    }
}
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
Anirban Sen Chowdhary
  • 8,233
  • 6
  • 39
  • 81