File Adapter

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

12 responses

  1. Manohar Sir,

    My Requirement:
    I have two sftp servers name ServerA and ServerB. Need to copy files from ServerA and place it on ServerB and change the file permissions to 777 after placing the files.
    The user i am connecting to ServerB has the access to override file permissions.

    Steps
    1. With help of FTP adapter in OSB I am reading files from ServerA and writing on to ServerB — Completed and is working.
    2. How to override file permissions after placing the file ????? — Yet to implement.

    Please suggest me how can i accomodate 2nd step.

  2. Hello Manohar great blog for learners.! Thank you. 🙂

  3. This blog will very useful to beginners

  4. HI ,

    I followed above steps of file adapter in jdev 12c but its not working.
    file is not reading nor writing can you help me here .

    Thnq in advance.

    1. Vidya, can you share the code on my mail

  5. Excellent post with all the screenshots covered for developing a SOA Application that utilizes File adapter.

  6. TY it helps a lot

  7. Hi manohar,
    Very good post.
    I’ve tried it with BPM instead of BPEL without success, could you help me ?
    I just need to read a file through a BPM web form.

    Thanks in advance!

    1. Hi Yan,
      Are you from wipro. Then it is easy for me to look at your code and guide you. Iam an architect at wipro. Can you share the code where you are facing the issue to my wipro Id or manohar.saddala@gmail.com

  8. Hi Manohar,

    Great post. I would like to however know how to solve the below scenario.

    Using a file adapter I am retrieving a .dat file with comma separated values.Each record in the file is of different type. Therefore using an nxsd the file is transformed to an XML. But how do we chunk the records into logical groups if the file is huge? I understand chunking can be achieved if each line is a record in itself. But in this case, the file contains, say Person personal details as one line, the next line is Person Address which is the child of the previous line and the following line is Person bank details which is the sibling of the previous line and the 2nd child of the first line, so all the 3 lines lines together make one record/object. And this repeats again starting with the Person personal details again.

    1. Have you tried creating the nxsd by choosing the file type as complex type and then designing the schema as per your requirement with parent child relation with parent as repeatable and first, second child as non repeatable. If possible mail me .dat sample file

      1. Hi Manohar,

        I see that I haven’t been clear. I am able to generate the nxsd in the expected format. However, what I would like to achieve is chunking of a big dat file which might be more than 10 MB. And because the dat file is gonna have different records of different types without a fixed length, how to achieve chunking? If it’s a CSV file, I know each line corresponds to a record and it’s easier to chunk. But in the dat file a group of 3-4 lines make a record, so how do I proceed to chunk them so I don’t unnecessarily split a single record and end up chunking badly? I will provide the sample file soon if this info isn’t enough.

Leave a comment