0

Hi i am working on wso2 ESB 4.7.0,

I wish to process the any particular file like .txt,.xls,.xml , my client provide the data in above format files in system folder,i need to pick from there and process that file , i wish to store that data into data base. Sample .txt file is

ename intime outtime eid 
-------------------------
john  9.10   6.10    y001
scott 10.00  7.00    yoo2
tiger 9.00   6.00    y003

above data i need to insert in empdetails table. I tried with VFS transport in WSO2 ESB, it is able to write the data into text file but how to read from data into a text file.

Help me to solve this.

Community
  • 1
  • 1
Kanchetianeel
  • 189
  • 2
  • 3
  • 15

1 Answers1

2

I understand that you want to read data from a file

To do that, you just need to declare a VFS proxy :

<proxy xmlns="http://ws.apache.org/ns/synapse" name="IncomingFile" transports="vfs" statistics="disable" trace="disable" startOnLoad="true">
   <target inSequence="YourSequence" />
   <parameter name="transport.PollInterval">15</parameter>
   <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
   <parameter name="transport.vfs.FileURI">file:///Your_directory</parameter>
   <parameter name="transport.vfs.MoveAfterProcess">file:///Your_directory_OK</parameter>
   <parameter name="transport.vfs.MoveAfterFailure">file:///Your_directory_KOKO</parameter>
   <parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
   <parameter name="transport.vfs.ContentType">text/plain; charset=ISO-8859-1</parameter>
   <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</proxy>

Don't forget to enable VFS transport receiver in you repository/conf/axis2/axis2.xml :

<transportReceiver name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportListener"/>

The message builder associated with text/plain in your axis2 conf will be used to build the message (org.apache.axis2.format.PlainTextBuilder by default : text content will be encapsulated into an xml node)

You may want to develop and use your own message builder, in order to transform the particular file format into a specific xml tree in order to use XPath inside your mediation.

An alternative would be to use smooks.

Jean-Michel
  • 5,926
  • 1
  • 13
  • 19
  • HI Jean,as per your code file is moving,but My aim is i have to receive this data into ESB proxy service,How can i receive the data into ESB. Please help me. – Kanchetianeel Nov 29 '13 at 07:07
  • I'm not sure to understand your problem : with my proxy sample, every 15 seconds, the proxy scan "Your_directory" searching for "*.txt" and if such a file exists, it's content is loaded and transformed into a soap message that arrive in the IN sequence "YourSequence" : you can mediate it as you need : so, data from the file are received in the ESB as if a HTTP Proxy was receiving a request. – Jean-Michel Nov 29 '13 at 08:10
  • HI Jean Thank you, i am receiving the data, but how can i store this data in particular table into DataBase. – Kanchetianeel Nov 29 '13 at 09:23
  • HI Jean, i am getting this data ** ename intime outtime eid john 9.10 6.10 y001 scott 10.00 7.00 yoo2 tiger 9.00 6.00 y003 **, but how can i store this data row by row in particular table into DataBase – Kanchetianeel Nov 29 '13 at 10:25
  • You can use 'dbreport' mediator : define a data-source and your SQL statement (your insert statement) with needed parameters. Don't forget to copy the jdbc driver jars into repository/components/libs. You can define the data-source in ESB console : Configure -> Data sources -> Add data source – Jean-Michel Dec 02 '13 at 07:41
  • but how can i get these specific columns into DB report mediator.i am using the functions like **get-property('eno')&//eno/text()**,please guide me. – Kanchetianeel Dec 03 '13 at 08:32