I want to pass the csv file data present in local drive as a string parameter to the DB query. How do I save the file data from vfs to a parameter property?
Also, this is a polling process and hence want to make use of transport vfs if it is possible. Not file connector.
<proxy name="CSVFileProcessorPostDemo" startOnLoad="true" transports="http https vfs" xmlns="http://ws.apache.org/ns/synapse">
<target>
<inSequence>
<dblookup>
<connection>
<pool>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://**************/**********</url>
<user>*********</user>
<password>*********</password>
</pool>
</connection>
<statement>
<sql><![CDATA[SELECT * FROM ba_ior_integration.fn_transform_ior_msg_to_idoc(?)]]></sql>
<parameter type="VARCHAR" value="{How to read the transport file data?}"/>
<result column="1" name="output_db_idoc"/>
</statement>
</dblookup>
<property expression="get-property('output_db_idoc')" name="dbOutput" scope="default" type="STRING" xmlns:ns="http://org.apache.synapse/xsd" xmlns:ns3="http://org.apache.synapse/xsd"/>
.
.
.
.
<parameter name="transport.PollInterval">5</parameter>
<parameter name="transport.vfs.FileURI">file://D:\ESB\files\input_IOR_files</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file://D:\ESB\files\failure_IOR_files</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
<parameter name="transport.vfs.Append">true</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file://D:\ESB\files\output_IOR_files</parameter>
</proxy>
Have searched and found two ways of handling it.
1) It is simply present under $ctx.body tag.
<property expression="$body//m0:text" name="dbInput" scope="default"
type="STRING" xmlns:m0="http://ws.apache.org/commons/ns/payload"/>
And then in dbLookup:
<sql><![CDATA[SELECT * FROM abcde.fn_transform_xyz_msg_to_idoc(?)]]></sql>
<parameter expression="synapse:get-property('dbInput')" type="VARCHAR"/>
<result column="1" name="output_db_idoc"/>
2) Using Java class mediator. The message string is present in MessageContext object.
context.getMessageString() provides the SoapEnvelope required, using which the required inner text can be extracted.
or
context.getSOAPEnvelop(): This did not work for me, shall look into it.
The takeaway is that the data of the files considered under vfs are all present sequentially under MessageContext.