Friday 29 August 2014

SOA-->FILE Adapter


In today's post Ill show you  how to use the Oracle File Adapter, which work with Oracle BPEL Process Manager and Oracle Mediator.File adapter is basically used to read,write files locally on your server.
There are mainly 4 operations in FILE adpater namely:
  • READ: its an inboun operation that reads a file from given dir path
  • WRITE: outbound operation to write files to a location specified under directory path
  • SYNCHRONUS READ: outbound operation used to read a file in middle of the process
  • LIST FILE: outbound operation to list all the files in a given directory

In our usecase,we will be using read and write operations. We will create BPEL process that will poll for new files and after reading the files it will write them to differnet location. 2 file adpaters one inbound and one outbound and 1 BPEL process will be used for implementing this scenario.

STEPS to follow:

1. Create a new SOA project.Click new SOA project.I will be using same application for this usecase "SOALabs" as used in other tutorials.
 2. Give the project name as "FileAdapterLab" and click next.
3. Choose "Empty Composite" template and finish.
4.Drag and drop file adpater from component pallette to exposed services lane.
 5. File adapter configuration window will pop up.Click next.
6. Give the service name as "pollFile" and click next.
7. We will not be doing any transformation neither we our file that we read conforms to any schema, so leave adapter interface default and move next.
8. Since we are reading for new records in a file.Choose operation type as "Read" and click next.Other setting leave as it is.Their significance will be explained in coming posts.
9. Enter directory path from where file adapter will poll for new files.If you want to delete files after successful read, check "Deletd files after successful retreival".Also, provide the location for archiving the file as well and move next.
10. Now in this part we will provide the name of the files that we want to read. I have given as "test*.*" which means it will read all the files starting with test.Leave other settings default and click next.
11. In this window we define polling frequency which means after how many seconds or minutes our file adapter will poll for new files.Also, if you want your file adapter not to read all the files as they are written on the server, use the minimum file age option.Click next.
 12. We will be writing the file as it is read, so choose opaque schema option.
13.Click next and finish.
14. In the similar manner,drag and drop another file adapter this time to external references lane for writing file purposes.File configuration wizard will open up.
15. Give service name as "WriteFile" and click next.
16. Click next again and choose operation name as "Write File" and click next.
17. Specify the directory path where you want your files to be written and file naming convention to be used for files written.If you want that each record is being written to existing file only use "Append to existing File" option. Otherwise leave it default and click next.
18. Again opaque schema will be used and click finish.

19. Now drag and drop a BPEL process onto the components lane.
20. Choose BPEL process as define interface later and give "FileBPELProcess" name to your BPEL process.
21. Wire both the file adapters to the BPEL process created and save all.
22. Double click the BPEL process and open up BPEL designer.In the BPEL designer drag and drop one Receive activity and wire it to the "readFile" partner link.
23. Window will pop up for configuring receive activity.As done in JMS adpater tutorial check mark "Create Instance" and create input variable by clicking on "+" icon.
24. Leave the name for variable as default and click OK.
25. Recieve activty will look like this.Click finish.
26. Drag and drop invoke activity below receuive activity and wire it to the "WriteFile" partner link.
27. Invoke window will pop up.In the same manner like we did for receive activity create input variable for invoke activity.
28. Invoke activity will look like this click OK.
29. As of now BPEL process will look like this.
30. Drag and drop the assing activity between recieve and invoke activity.
31. Double click the assing activity and map receive activity input variable to invoke activity input variable means same contents are being copied to output.
32. SAVE ALL.Compile and deploy the SOA Composite. If you don't know how to deploy clickHERE:
33.Now to test create one file at input dir that you gave while configuring "readFile" FILE adpater with name as test.
34.Open up your EM and drill down to your deployed composite.Keep refreshing and after sometime you will see one instance get created.

35. Click open the instance to see the flow trace of the invoked SOA composite.

36. Verify file is dleted from its source path and it is archived to the archive location.Also verify that a file is written at a path given while configuring "WriteFile" adaper with name as "test_file.txt"
Thats it guys.Today we learned how to configure and work with file adapters using read and write operation.stay tuned in for more tutorials.Till then take care

No comments:

Post a Comment