How to Read and Write a File Using Oracle BPEL File Adapter in SOA 12C - Oracle Integration Cloud Service

How to Read and Write a File Using Oracle BPEL File Adapter in SOA 12C - Oracle Integration Cloud Service

The file adapter enables a BPEL process or an Oracle Mediator to exchange (read and write) files on local file systems. The file contents can be in both XML and non-XML data formats.The SOA File Adapter helps us to read or write a file in a directory

In this tutorial we will use File Adapter to create a Service which will pool source location every 60 seconds and read the *.txt files present and write the content back to a CSV File in another location. Once the file is read successfully we will move the file to Archive location in a different place.

 Lets get Started......

Step 1:- Create a New SOA Application from Gallery

create a SOA Application , Provide Application Name and create a empty Composite as shown below.





Step 2 :- Create  a File Adapter in the Exposed Services

Right click on the Expose Service Layer and Insert a File Adapter over there.Which will open File Adapter Service Wizard.

Since the Expose Service is Read Service which will read all TXT files in a location for every 60 seconds.Select the Operation Type as "Read File"

How to Read and Write a File Using Oracle BPEL File Adapter in SOA 12C







Note :Sometime there might a requirement to check if file exists and perform some operations in that context enable "Do not read File Content" check box.


Select Incoming directory where the file will come. Even  we can provide a Logical Name also.Here is the place where we will specify Archive Process. Provide the physical path where you want to archive file once read.

Even we can specify if want to Delete and clear the Incoming folder once read check the check box - "Delete files after successful retrieval".



Provide the File pattern what type of incoming files need to read by the Service. 

For Example if we use a shared directory where files related to PO, Invoices and Payments will come to same location we can specify here a file pattern what kind of files need to be read. 



This is a place where we can specify polling frequency.On our case every 60 seconds it has to pool source folder.



Now we need to define schema for the source file data.For this Oracle has provided a tool called Native Format Builder. Just click on the gear button beside the URL Search light button that will open builder as shown below.


Using this builder . We can use the source file and generate the schema definition.In our case we are reading employees related information in  a Text file .Each Column in the employee record is separated by "," . The same we will selected using the below wizard .At the end it will create a schema which we will use for the read Service Adapter.












Step 3 :- Create  a File Adapter in the External References

Perform the similar steps did in the step 2 but the main major difference is we will select operation as "Write File " in the File adapter. Wizard will ask us the physical location in the server where we want to write the file with file naming patterns.











Step 4 :- Create  a BPEL Empty Service 





Map  Expose Services Read Service to BPEL Component created and hook up the component to Exposed Services Write Operation.


Double click the empty Service call and add a Receive component from the component pallet


Keep all the default values and create a variable for the Transformation.


Similarly create a Invoke Action from the component palette and create a Global Variable for the same as shown below.



Drag and drop Assign Activity between Receive Service and Invoke Action call and map the Receive Service Input variable to Invoke Write Service Variable created above.




Step 5 :- Save all your changes and deploy it to Managed Server to test file Adapter.








Step 6 :- Navigate to SOA 12c EM and go to SOA_INFRA Default folder where the composite is deployed. you should see your composite under default folder.


Step 7 :- Now test the service by placing a txt file in the Incoming folder .You will observe after 60 seconds the file will read by Service and move it to Archive folder.




Step 8: Validate Destination folder where the file is created successfully or not





Done. we have successfully created a File adapter service which will read a file and write it to other file in different location.

No comments