Sunday, 17 November 2013

FILE- ADAPTER to Process Files Using Mediater



      Hi in this post we wil discuss about JCA Adapters for FILES. The Oracle File  enable a BPEL process or a Mediator to exchange (read and write) files on local file systems and remote file systems (through use of the file transfer protocol (FTP)). The file contents can be both XML and non-XML data formats.


The Oracle File are based on JCA 1.5 architecture. JCA provides a standard architecture for integrating heterogeneous enterprise information systems (EIS). The JCA Binding Component of the Oracle File and FTP Adapters expose the underlying JCA interactions as services (WSDL with JCA binding) for Oracle BPEL PM integration. 

Overview: In this tutorial, I will explain how to read a multiple record  txt file using ReadFileAdapter and then to write   to txt file using WriteFileAdapter. We don’t have two separate FileAdapters but based on the read and write operation we mention them as ReadFileAdapter or WriteFileAdapter.
ReadFileAdapter will Receive the input data from file and translate the data based on file configurations  defined and post the XML messages.
WriteFileAdapter will receive the XML messages and translate it into actual data  and write to a file.


We are now going to implement first with Mediater and then with BPEL

 Step 1: Configuring FileAdapter to read Local .txt File


Create a soa  project FilereadWrite, with Empty Composite
Drag drop FileAdapter from Servicecomponets of Componentpallete to Exposedservices




Step 2: Defining FileAdapter to read a test File

ServiceName:Multipleread click next

Interface:Define from operation and schema click next

Select Read from Operation Type as we need to read from a file



Ignore the below options don't read file content ,use file streaming , read file as attachment we will discuss in next blog

click next





Select the ‘Physical Path’ option' Logical Path ' is used when we are deploying our service to remote server
Select the path where you incoming  txt file is expected.
I have placed by .txt file in the @ ‘C:\FILEADAPTER\MultipleRead’ directory
Process files recursively
Archive processed files @ D:\Archive_Files\MultipleArchive
select the option ‘Delte files after successful retrieval’ 

Note: Best Practice to maintain different directory for Incoming and Archive Files 


Click Next





I want to define specific file to be read by My fileAdapter
Select 'File Wildcards' Option
Enter the patten name in ‘Include Files with Name Pattern ' :  test*.txt
Enter the name pattren in 'Exclude files with name pattren' :  exclude*.txt 


Note: Files with Include name pattren will be picked ignoring Files with Exclude File pattren

I have entered test*.txt which means that all the files starting with ‘test’ word prefix will be picked for processing.
Ex:
test.txt will be picked
test23.txt will be picked
test43423test.txt will be picked
testexclude.txt     will be picked

soatest.txt will not be picked
1test.txt     will not be picked
exclude.txt  will not be picked
exclude43.txt will not be picked

click next



  Polling frequncy  defines time interval to read the folder for new incoming files
     Minimum File age defines the restriction on file age to be read

in our case the incoming folder will be read for every 60 seconds for every file aged minimum of 0 seconds  

click next
          

 Now we are going to define Schema for the Incoming messages , click next





Select the option to create a new schema ,Select the file type to be Delimited file with contains data separeted by comma

sample file 

1340,Deepthi,Hr,developer,20.000
1341,lasya,Hr,developer,40.000
1342,Madhavi,Hr,developer,80.000 



 Give the Location of file which has the sample representing the incoming file data
I have created a sample txt file . Expecting 200 Number of rows in incoming file ,should process all the rows
Charecter set  US-ACII

Click Next


 
  Now we can specify the Namespace f the Schema.Enter name for the element to represent the record

click next and Finish
.xsd(XML Schema Definition) file will created by default ,
Change the column names and types as needed ,Name the schema as below


We are done with FILEADAPTER  read operation type


Step 3: Configuring FileAdapter to write the Text file Read in above step


 Drag drop FileAdapter from Servicecomponets of Componentpallete to External references


ServiceName:Multiplewrite click next

Now Select Write from Operation Type as we need to write to  a file.


Click Next


 Define the path to which we are writing the file to ,In my case i am writing to D:\FILEADAPTER\Multiplewrite

FileNaming convention sets the naming pattren to write the files

Multiplewrite_%SEQ%.txt

%SEQ% will increase the numbers from 1 onwards which means if you have 10 files to write then your file names will be Multiplewrite_1.txt, Multiplewrite_2.txt, Multiplewrite_3.txt ….Multiplewrite_10.txt
Click Next    



Select the schema created in step 2 testfile3_2.xsd 'Root-Element'
Click Next and Finish

Step 4: Insert Mediater in component swimlane and connect Mediator to  Read fileadapter and write fileadapter we created in Step 2,Step 3




Our composite looks like below


Edit the Mediater to define Routing Rules


Create a Mapping File that transforms incoming file to Outcoming data



Click Ok and Save

Edit the Mapping File




We are now ready to test our data


Place a sample Delimited txt file named : testfile23 @D:\FILEADAPTER\Multipleread

1381,Deepthi,Hr,developer,20.000
1382,Madhavi,Hr,sr.developer,20.000
1383,Sarada,Hr,jr.developer,60.000
1384,Swathi,Hr,sr.developer,40.000
1385,Saranya,Hr,jr.developer,80.000
1386,ramya,Hr,jr.developer,50.000 



now check @D:\FILEADAPTER\Multiplewrite you will find a file Multiplewrite_1

having the above delimited data



Happy learning



                                                                                                           By DeepthiReddy

No comments:

Post a Comment