Tuesday, 26 September 2017

File Adapter Demo- SOA

As part of Oracle SOA Suite, oracle provides Adapters which are developed based on JCA architecture which will help us in integrating with the systems which are not exposed as Services.
File Adapter is one of the adapters provide by oracle which will help in interacting with the file system to read and write data to files.
In this post we will implement the following
  1. Read data from the file
  2. Write data to the file
  3. BPEL process polling the data from the file and writing to a file

Implementation:

Create a SOA project with the empty composite

  1. Read data from the file
    Drag and drop the File Adapter on the “Exposed Services”


Immediately after dropping the file adapter on the exposed services, you will be popped with the below window

Click Next

Enter the service name and click next

If the you have wsdl which will meets our requirement, then we can select using “Import an existing wsdl” else we need to select the “Define from operation and schema”
Click Next

Select the Operation Type as “Read File” and click Next

Select “Physical path” and browse the directory from where the file has to be read, click next

Enter the file name pattern and click next

Enter the Polling Frequency and click Next

Know define the message for the read operation by clicking the Wheel button highlighted in the above screen


Click Next

Select the sample data file and click next

Click Next

Click Next

Enter the details based on how the data and records are separated. Then click next

Click Next

Click Next

Click Finish

Click next

Click Finish. Finally your composite looks as below

  1. File adapter to write data to the file
Drag and drop the file adapter on to the External References.

You will be popped with the File Adapter configuration wizard

Click Next

Enter the service name and click next

Select “Define from operation and schema” and click Next

Select Operation Type as “Write File” and click Next

Enter the Directory of file and File name cinvention, click Next

Click Define schema button

Click Next

Click Next

Click Next

Click Next

Enter the Target Namespace, root element name and record element name as shown above and click next

Specify the record delimited and filed delimited, click next

Click Next

Click Next and then Finish

Click Next and Then Finish. Finally your composite will look like below

  1. Implement a bpel process the reads the file using “ReadingFile” file adapter service and write to another using “WriteToFile” file adapter service.
Drag and drop the BPEL Process on to Components line

You will be displayed with “Create BPEL Process” wizard

Enter the Name and select template as “Define Service Later”.
We are selecting this template we are not exposing our process as service and our process will be receive messages from the “ReadingFile” file adapter
Click “OK”

Our composite looks like above screen.
Know connect the adapters with the bpel process.

Open the BPEL process by clicking it

Add the “Receive” Activity to process sequence

Connect “Receive” activity with “ReadingFile” partener link

You will be popped with the “Edit Receive” wizard

Select “Create Instance” checkbox and create a variable by clicking “+” as highlighted above.

Click OK

Click Apply and OK
Add “Invoke” activity to the process sequence and connect the invoke activity to “WriteToFile” partnerlink


You will be pooped with “Edit Invoke” wizard.

Create the Input variable by clicking “+” and click apply button, OK
Add “Assign” activity between “Receive” and “Invoke” activities to assign the data between the receive, invoke activities
I will be reading empno. Empname, city from input file and write only empno, empname to output file.
Based on this my “Assign” activity looks like below

Click “Apply” and OK

Finally your BPEL process looks like above snapshot
  1. Deploy the application
  2. Test the application by placing a txt file with the name specified in “ReadingFile” file adapter

Know both InputMessages and OutputMessages directory are empty. Add a file with name format as “employeedatainput*.txt” in “InputMessages” directory
Know the BPEL file will read the file data and write data to the out file as below

If in case source input text file has more than one record we will get the below error. If you look at the payload for “Receive” Activity


To resolve the above error, we need to replace the “Assign” activity with “Transform” activity. Know the bpel process looks like below

Click on the transform activity or open transformation file