BPEL File Adapter Tutorial


Overview: In this tutorial I will explain how to read a CSV file using ReadFileAdapter and then to write a CSV file using WriteFileAdapter. We don’t have two separate FileAdapters but based on the read and write operation we mention them as ReadFileAdapter or WriteFileAdapter.

ReadFileAdapter will Receive the input data from file and translate the data based on the translation logic defined and post the XML messages.

WriteFileAdapter will receive the XML messages and translate it into actual data and write to a file.

FileAdapter supports the following file formats.

1.XML

2.Delimited (Delimiter can be anything)

3.Fixed position

4.Binary Data

You don’t need to use both ReadFileAdapter and WriteFileAdapter in a single process, for example you can read the data from file using ReadFileAdapter and write data to a database using DBAdapter. In other way you can get the data from a database and write it to a file using WriteFileAdapter. This is purely based on the business requirement and up to us how we are going to use them.

 

System Requirements:

1. jDeveloper 10.1.3

2.SOA Suite 10.1.3

Connections Required:

1.Start the SOA Suite

2.Create Application Server Connection

3.Create Integration Server Connection

Start the SOA Suite:

If you don’t have SOA Suite already installed on your machine click here to download and install it.

If you have SOA Suite installed on your machine navigate Start >> All Programs >> Oracle – >>Start SOA Suite

Once your Application Server starts successfully you will see the screen below

Create Application Server Connection

Navigate to Connection Navigator by clicking view >> Connections Navigator or by pressing Ctrl + Shift + o

Right click on “Application Server” and click New Application Server Connection

Wizard opens with welcome screen

Click Next

Connection Name: AppServerConnection1 (you can change it to anything)

Connection Type: Oracle Application Server 10g 10.1.3

Click Next

Username: oc4jadmin

Password: welcome1(this is the default password, if you have changed it use your own password)

Click next

Leave everything as it is and click next

And then press Test Connection

If you receive the Status as Success! You are good to proceed. If you get any errors make sure your application server is running and try again.

Click Finish to close the wizard and return to Connection Navigator.

Create Integration Server Connection

Go to Connection Navigator by pressing Ctrl+Shift+o

Right click on “Integration Server”

By Clicking the “New Integration Server Connection” wizard opens up with welcome screen.

Click Next

You can leave the Name as it is or change it if needed

Click Next

Application Server: Select the Application Server you created in first step. If you have only one application server it will be automatically selected.

Hostname: localhost

Port Number: 8888

Click Next

Click ‘Test Connection’

If you receive the following message you connection is successful.

Application Server: OK

BPEL Process Manager Server: OK

ESB Server: OK

Click finish to close the wizard

Create New Application

Open Application Navigator by clicking Ctrl+Shift+A or go to view >> Application Navigator

If you have any Application exists  you can create your BPEL process under that if not creation new application by right clicking the Applications and selecting New

Change the application name as you need and leave all the remaining things as default and click OK

Click Cancel to cancel the project. We will create new project manually by selecting the BPEL Process project in next step.

Create New BPEL Process

Right Click on the Application that we created and click New Project

Wizard opens as shown

Select BPEL Process Project and click OK

Change the Name(optional) and

Template: Empty BPEL Process

Click Finish.

If you expand the BPEL Process you can see the files below which are created by default.

Middle panel of jdeveloper opens BPELProcess.bpel file automatically if not open it by double clicking on the file shown in the above figure.

In the .bpel file you can see 3 regions

1.Services(Left Side)

2.Main Activity Region

3.Services(Right Side)

On the Right Side of your screen you can see the component palette.

From the dropdown select ‘Services’ if it is not selected.

From services select “File Adapter”

Drag it to Services region on left and leave it.

Automatically ‘Adapter Configuration Wizard’ will pop up showing the welcome screen

Click Next

Enter Service Name as ‘ReadFileAdapter’ since we are going to use this adapter for reading the file.

Click Next

Select ‘ReadFile’ and click Next

Select the ‘Physical Path’ option and select the path where you CSV file is placed.

I have placed by .CSV file in the ‘C:readfile’ directory

Deselect the option ‘Delte files after successful retrieval’

Click Next

Enter the patten name in ‘Include Files with Name Pattern’

I have entered erpschools*.txt which means that all the files starting with ‘erpschools’ word prefix will be picked for processing.

Ex:

erpschools.txt will be picked

erpschools1.txt will be picked

erpschools2.txt will be picked

1erpschools.com will not be picked.

Click Next

Leave the default values and

Click Next

Click on ‘Define Schema for Native Format’ button

Navtive Format Builder Wizard will pop up with welcome screen.

Click Next

Select ‘Delimited’ option and

Click Next

Select your delimited file.

My Delimited file looks like this

Click Next

Since our file contains only one record select first option and

Click Next

Namespace: leave default value

Enter a name for element that will represent record: readrecord

Click Next

Click Next

Change the column names and types as needed and

Click Next

.xsd(XML Schema Definition) file will created by default

Click next

Click Finish to go back to Adapter Wizard

Schema Location and Schema Element will be populated with the values that we created just now.

Click next

Click Finish

Create Partner Link window will show up as above

Click OK

Now you should be able to see the ReadFileAdapter in the services region as shown above

Now in the component Palette select ‘Process Activities’

Select ‘Receive’ component and drag it to main region

When you move the component to main region it will change the color to yellow then you can drop it.

Double click on Receive_1 component to edit

Click on ‘Flash light’ right to to the ‘Partner Link Field’

Select ‘ReadFileAdapter’ and click OK

Now Partner Link and operation fields will be populated as shown

Click on ‘Auto Create’ button right to Variable to create new variable. If you don’t understand which icon to click place your cursor on the icons and you can see the hint text

Click OK

Check ‘Create Instance’ box and click apply

Click OK

Now the figure looks like this

There is a link created from ReadFileAdapter to Receive_1 component

Create WriteFileAdapter

Go to component palette and select services from drop down

Select the drag FileAdapter to Services region on the right side

FileAdapter Wizard will open with welcome screen as shown below

Click Next

ServiceName: WriteFileAdapter

Click Next

Select ‘Write File’ option

Click Next

Enter Directory path and file naming convention as shown above.

%SEQ% will increase the numbers from 1 onwards which means if you have 10 files to write then your file names will be erp_1.txt, erp_2.txt, erp_3.txt …..erp_10.txt

Click Next

Click Browse to select the schema file that we already created before

Select readrecord

Click OK

Click Next

Click Finish to close the wizard

Click Apply and OK

WriteFileAdapter will showup in the right Services region as show above

Now go to Component palette and select ‘Process Activites’

Select ‘Invoke’ Component from component palette and drop it below the ‘Receive_1’ component

Double click on ‘Invoke_1’ component to edit it

Click Flash light to select the partner link

Click ok

Click Automatically create input variable icon to create new variable

Click ok

Click Apply and OK

Now drag and drop the ‘Transform’ component below the ‘Receive_1’ component and above ‘Invoke_1’ component

Double click on ‘Transform_1’ component to edit the settings

Select as follows

Source variable: Receive_1_Read_InputVariable

Target variable: Invoke_1_Write_InputVariable

Click Apply and OK

Transformation_1.xsl file will open as show above

select  ‘tns:readrecord’ in source and drag it to ‘tns:readrecord’ on target to map the fields.

Auto Map Preferences will pop up as shown above

Click OK to auto map

All fields will be mapped automatically as shown above

Now select BPELProcess.bpel file on top and click validate icon to validate the process

Once it is validated with out errors we are ready to deploy the process

Deploy BPEL Process

Right click on BPEL Process and select Deploy option as shown below

If you have this process already on server it will pop up with version number if not it will start deploying the process

If your deployment is successful you will see the message

BUILD SUCCESSFUL.

Initiate BPEL Process

Open your browser and type the following URL

http://localhost:8888/BPELConsole
If your hostname is different change it in the URL

Username: oc4jadmin

Password: welcome1(default)

Login

You can see the list of deployed BPEL Process on the left panel as shown below

Click on the process we deployed right now

You will be taken to Initiate screen where you have option to post XML Message

Now your process has initiated

Go to your writefile directory to see your file