Tuesday, April 16, 2013

Working With FILE Adapter

Hi Everyone,

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 click HERE:
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

Happy Learning,
cheers !!!

13 comments:

  1. Hi Karan,

    Thanks a lot for such a nice detailed level doc.I have one question, unlike the synchronous hello world scenario, where user input is triggering the process, in this case merely creating the file the desired location will trigger process?

    ReplyDelete
  2. Hi piks,

    Yes you are right, placing the file in input directory will initiate the process.BPEL process will poll for new files after regular intervals configured in JCA adapter. If you want your files not to be read immediately , you can use "MinimumFileAge" option.

    Hope this helps.

    Regards,
    Karan

    ReplyDelete
  3. Thanks but after deploying in EM no instance is created.I have refreshed it many times.

    ReplyDelete
    Replies
    1. Make sure you are placing the file in correct directory....also verify the file name both in JCA file and input directory you are using, both should be same.

      Delete
  4. Hi Mousumi,

    Can you please check the source/target file location has read and write access by process and also the file with correct file name is placed in the location. You can check the logs and get pointers from there.

    please let us know if it works.

    Pallab

    ReplyDelete
    Replies
    1. Hi Pallab,

      You are right. The problem is that such OS level issues for File Adapter and DB level issues at DB Adapter level will not be caught in SOA. Hence, better to check such things.

      Thanks,

      Delete
  5. Nice tutorial but I'm recommend to not use (if possible) in cluster environment because it might be take some duplicate data when disaster recovering
    http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/life_cycle.htm#autoId66

    ReplyDelete
    Replies
    1. Ok.

      don't use it then :P

      Delete
  6. Hello,
    Interesting post.
    I'd prefer using only OSB in 11.1.1.*, is there any way to use the jca file adapter and get it to write an opaque message to a JMS queue?

    Regards Krister

    ReplyDelete
  7. Hi,
    difence service later,synchronous and asynchronous in bpel template, which scenario we can use in real time .please suggest me anyone?

    Regards,
    Nag

    ReplyDelete
  8. Hi Karan,

    Nice write-up. I want to add a empty line after every message written using file adapter. I could not find any configuration which lets me do this. I am using append to existing file.

    Thanks,
    Sai

    ReplyDelete