425 total views, 0 views today

How to write File using Oracle BPEL File Adapter Example

 

The SOA File Adapter helps us to read or write a file in a directory. The visual composite window in JDeveloper allows integrating the File Adapter with simple multiple mouse clicks.  In this post, The BPEL process read a record from a DB table and writes the table record in a Text file using Oracle BPEL File Adapter. It follows the below two steps

 

1. Read a record from a Table, Store the column in a String variable.

 

2. Write the String value in a Text file

 

You can download the project at the end of this post. The BPEL reads HR schema Employee table record and writes into a text file. The HR schema is a built-in schema in Oracle database. The BPEL uses DB Polling adapter to read a record from the table and deletes it once process ends. 

 

Write File using Oracle BPEL File Adapter

 

Explaining each step of the project is document expensive so I place only the needed steps in this post. I covered only the following two steps

 

1. How to include a File Adapter in the BPEL Composite

 

2. We cannot write a string directly into a FileAdapter payload. The File adapter in Oracle BPEL accepts only Opaque element which is a base64binary datatype. So, we are converting the string into base64binary then send it to File adapter which will write a file in the file system.

 

I have already created a BPEL project. To write a file in BPEL, we must include a File adapter in the SOA Composite so that we can invoke it in the Oracle BPEL process. Follow the steps to include a File adapter in the Composite:

 

Include the File Adapter in the Oracle SOA Composite

 

1. Open the SOA Composite >> Right click on the External References >> Insert >>Select File as shown below

 

 

121017_2058_Howtowritea1 How to write a File using Oracle BPEL File Adapter Example

 

 

2. The File Adapter wizard appears, input a name and click Next

 

 

121017_2058_Howtowritea2 How to write a File using Oracle BPEL File Adapter Example

 

3. Select as shown below and click Next

 

121017_2058_Howtowritea3 How to write a File using Oracle BPEL File Adapter Example

 

4. Input as it is and click Next

 

121017_2058_Howtowritea4 How to write a File using Oracle BPEL File Adapter Example

 

5. Select Write File and click Next

 

121017_2058_Howtowritea5 How to write a File using Oracle BPEL File Adapter Example

 

6. Specify the directory where you want the Oracle BPEL to write files. We can set the directory at runtime as well.

 

121017_2058_Howtowritea6 How to write a File using Oracle BPEL File Adapter Example

 

7. I chose the Native format;  Click Finish. Here we have included the File Adapter in the composite.

 

121017_2058_Howtowritea7 How to write a File using Oracle BPEL File Adapter Example

 

Convert the string into the base64binary in Oracle BPEL process

 

Assume, we have a String variable contains a value (Table record column value); We can’t pass the String value directly into the File adapter. We must convert it into a base64binary data type. Here, I am creating a variable of type base64binary and convert the string value into it.

 

1. Open an Assign activity >> Right click on the Variable and create variable >> Input a name and choose type base64Binary from XML Schema Simple type

 

121017_2058_Howtowritea8 How to write a File using Oracle BPEL File Adapter Example

 

 

2. The following Java embedded code converts the String value into the base64Binary attribute. Here the variable ‘Name’ is a string attribute and ‘base64’ is a base64binary attribute

 

 

 

3. Assign the base64 to the payload of File Adapter which is an opaque type; Also I have created FileName which is a name of the file the Oracle BPEL is going to create; I used string function concat which concatenates EmployeeID+.txt

 

121017_2058_Howtowritea9 How to write a File using Oracle BPEL File Adapter Example

 

 

4. Here I am invoking the File adapter; The operation is Write

 

 

121017_2058_Howtowritea10 How to write a File using Oracle BPEL File Adapter Example

 

2. I pass the FIleName variable to jca.file.FileName; Now BPEL writes the filename as <EMPLOYEE_OD>.txt; Similarly you can pass the directory here by jca.file.Directory

 

121017_2058_Howtowritea11 How to write a File using Oracle BPEL File Adapter Example

 

That’s it; I deployed the BPEL process on my local BPEL server. For each record in the table, there is a file gets created by Oracle BPEL

Below is the Employee table record; Note the Employee_ID

 

121017_2058_Howtowritea12 How to write a File using Oracle BPEL File Adapter Example

 

Below are the files get written; Note the filename and file content

 

121017_2058_Howtowritea13 How to write a File using Oracle BPEL File Adapter Example

 

Download the Oracle BPEL File Adapter Project

Caution : If you going to run this project on your local then export the HR.employee table records into a file because this process reads and deletes all the record.

 

govindan How to write a File using Oracle BPEL File Adapter Example
Connect me

Govind

Thank you for visiting my personal blog. Myself Govindan, Software Developer by profession since 2006 and hence I started this blog early in 2016 and ever since I've been writing about technologies experienced and learnings of everyday life.

The views expressed on this blog are my personal views and do not necessarily reflect the views of my employer.

Please feeling free to reach me on any comments and feedbacks you have. Would be more than glad to listen and reply šŸ™‚
govindan How to write a File using Oracle BPEL File Adapter Example
Connect me
By | 2017-12-10T16:30:10+00:00 December 10th, 2017|Categories: BPEL|Tags: , , , , |Comments Off on How to write a File using Oracle BPEL File Adapter Example
Like us on Facebook.
Connect!