我创建了一个代理服务,我正在使用 VFS 来执行文件处理。为此启用 vfs。
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CSVtoXMLSmooks" startOnLoad="true" statistics="disable" trace="disable" transports="vfs,http,https">
<target>
<inSequence>
<smooks config-key="CsvtoXml_Smooks">
<input type="text"/>
<output type="xml"/>
</smooks>
<property expression="$body/*" name="payload" scope="default" type="STRING"/>
<log level="custom">
<property expression="get-property('payload')" name="Response payload==="/>
</log>
</inSequence>
</target>
<parameter name="transport.PollInterval">1</parameter>
<parameter name="transport.vfs.FileURI">file:///Home/smooks/In</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///Home/smooks/Out</parameter>
<description/>
</proxy>
在代理服务内部。调用 smooks 中介。
<smooks config-key="CsvtoXml_Smooks">
<input type="text"/>
<output type="xml"/>
</smooks>
创建一个本地条目来定义smooks mediator的映射和过程。
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.2.xsd">
<resource-config selector="org.xml.sax.driver">
<resource>org.milyn.csv.CSVReader</resource>
<param name="fields">CustID,CustName,CustAddress</param>
<param name="rootElementName">data</param>
<param name="recordElementName">csvRecord</param>
</resource-config>
样本输入:
1,chris,india
2,sam,South india
输出将是这样的:
<data><csvRecord number="1"><CustID>1</CustID><CustName>chris</CustName><CustAddress>india</CustAddress></csvRecord><csvRecord number="2"><CustID>2</CustID><CustName>sam</CustName><CustAddress>South india</CustAddress></csvRecord></data>
试试这个。谢谢。