Monday, May 18, 2015

Cron style file transfer with WSO2 ESB File Connector

Given a requirement where you would need to perform a file transfer as a cron job (ex: transfer files during weekends only) , you will have to use a scheduled task. But the default VFS transport mechanism would not work with a scheduled task. Therefore, you should use file connector to perform the file transfers. [1]

1.First of all you need to download file connector from wso2 store.
2.  Go through [2] and enable the file connector zip, downloaded from step 1.
3.Now that you have enabled File connector, you can have a sample proxy configuration like below. (Note: I have used ESB 4.8.0 )

proxy name="SampleProxy" transports="https http" startOnLoad="true" trace="disable">
<property name="filelocation" expression="json-eval($.filelocation)"/>
<property name="file" expression="json-eval($.file)"/>
<property name="newfilelocation" expression="json-eval($.newfilelocation)"/>
<property name="filebeforeprocess" expression="json-eval($.filebeforeprocess)"/>
<property name="fileafterprocess" expression="json-eval($.fileafterprocess)"/>

4. Next add a schedule task [3], that would perform this proxy according to given cron expression.
    You can give below values for the schedule task properties.

Task Name : SampleInjectToSequenceTask
Task group : synapse.simple.quartz
Task Implementation :org.apache.synapse.startup.tasks.MessageInjector
Trigger Type : Cron
Cron : * * * * 6-0 ? (add your specific cron expression)
By clicking 'Load Task Properties' button(near Task Implementation) you can add below property values.
injectTo : proxy
proxyName : SampleProxy
message (xml): <m0:getQuote xmlns:m0="http://services.samples">

5. Create a sample JSON input file like below. (sampleFileConnector.xml )


6. Use this curl command to test your proxy configuration.
url -v -X POST  -d @Desktop/sampleFileConnector.xml -H "Content-type: application/json" http://localhost:8280/services/SampleProxy

7. You can look into [4] to get more information on different operations/ properties that are available in File Connector.  Also go through [5] to refer more on WSO2 ESB connectors.

[2] h

No comments:

Post a Comment