web stats
Mirth Community - View Single Post - Test for presence of PDF file
View Single Post
  #3  
Old 11-05-2018, 02:19 AM
odo odo is offline
OBX.3 Kenobi
 
Join Date: Feb 2017
Location: Luxembourg
Posts: 137
odo is on a distinguished road
Default

Either wrap your code with try/catch:
Code:
     try{
        globalChannelMap.put('pdf', FileUtil.encode(FileUtil.readBytes('/path/to/pdf')));
    } catch(ex){}
or (better) check first if there is a file:
Code:
     if(new java.io.File("/path/to/pdf").isFile()){
        globalChannelMap.put('pdf', FileUtil.encode(FileUtil.readBytes('/path/to/pdf')));
    }
or (best) do both to ensure that the file is correctly read if present:
Code:
    if(new java.io.File("/path/to/pdf").isFile()){
        try{
            globalChannelMap.put('pdf', FileUtil.encode(FileUtil.readBytes('/path/to/pdf')));
        }catch(exception){
            // treat reading errors here
        }
    }
Later, you can send the mail if the attribute is set:
Code:
    if(globalChannelMap.containsKey("pdf")){
        // send mail
    }
The global channel map attributes are sustained between messages. If a pdf should be loaded for each message, the channelMap container must be used instead.
Reply With Quote