Quantcast
Channel: SCN : Document List - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 571

To check file existence before picking using Java

$
0
0

Hi All,

 

Recently, we have received one requirement where we were picking files from three different systems using FTP server and then merge them. The requirement become complex when we had to check the existence of all files at their source directory and stop if any one of the file is absent.

 

To achieve this requirement, we have made one scenario where we will create one sender channel which will be in test mode. That channel will always pick test file and consequently our mapping will execute. In message mapping, we have written three single values udf which will check for the files on ftp server and and pick all three files. If any one of the file is absent,it will throw runtime exception and mapping execution will stop there itself.

 

For better understanding you can follow below map.

diagram.PNG

 

 

For working on FTP server from PI, we have used Apache FTP executable libraries which you can find on apache.org

 

Step1: To import Jar file on apache libraries in imported archive

 

archive.PNG

 

 

Step 2: Accessing FTP Server using FTPClient class

 

init.PNG

 

We can connect using connect and login method FTPClient and get all files list in the directory and then check for our file if it exists there.

def1.PNG

 

At last we will read all data of file and store it in global variable "file1data" which can be appended with other files data.

def2.PNG

 

If any one of the file is not present in directory it will be return empty. On which runtime exception will be thrown.

 

exception.PNG

 

 

Mapping for this is given below, in which three function modules are created for each system.

 

mapping.PNG

 

All three function modules will return blank string if any of the file is not found. And on receiving blank exception_check udf will throw exception.

 

 

You post your reviews in comment section if you face any issue while implementing this requirement

 

 

Regards,

Shankul


Viewing all articles
Browse latest Browse all 571

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>