0
我有一個簡單的代理服務,它從csv文件讀取並使用smooks介體將其轉換爲XML消息。如果csv文件包含用單引號(')括起來的字段,那麼它效果很好。如何使用WSO2 ESB 4.8.1中的Smooks從csv文件中讀取使用雙引號括起來的字段
FileStructure:
'accountid','accountname','accountlocation'
'121','dummyaccount','finland'
'121','dummyaccount','finland'
'121','dummyaccount','finland'
但不幸的是在我的情況的字段被包圍在「雙引號」和Smooks的不解析文件,它是無法讀取該文件。
FileStructureDoubleQuotes:
"accountid","accountname","accountlocation"
"121","dummyaccount","finland"
"121","dummyaccount","finland"
"121","dummyaccount","finland"
代理服務:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="ConvertcsvfiletoXML"
transports="vfs"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="DISABLE_SMOOKS_RESULT_PAYLOAD" value="true"/>
<smooks config-key="gov:/SmooksTest/smooks-config.xml">
<input type="text"/>
<output type="xml"/>
</smooks>
</inSequence>
</target>
<parameter name="transport.PollInterval">100</parameter>
<parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
<parameter name="transport.vfs.FileURI">file:///home/omerkhalid/Documents/SmooksTest/in</parameter>
<parameter name="transport.vfs.MoveAfterProcess">file:///home/omerkhalid/Documents/SmooksTest/out</parameter>
<parameter name="transport.vfs.MoveAfterFailure">file:///home/omerkhalid/Documents/SmooksTest/failed</parameter>
<parameter name="transport.vfs.FileNamePattern">.*.csv</parameter>
<parameter name="transport.vfs.ContentType">text/plain</parameter>
<parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
</proxy>
的Smooks配置文件:
<smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.1.xsd"
xmlns:jms="http://www.milyn.org/xsd/smooks/jms-routing-1.2.xsd"
xmlns:ftl="http://www.milyn.org/xsd/smooks/freemarker-1.1.xsd">
<params>
<param name="stream.filter.type">SAX</param>
<param name="stream.filter.readerPoolSize">300</param>
</params>
<csv:reader fields="id,name,location" separator="," quote="'" skipLines="1" />
<resource-config selector="csv-record">
<resource>org.milyn.delivery.DomModelCreator</resource>
</resource-config>
<ftl:freemarker applyOnElement="csv-record">
<ftl:template>/repository/resources/smooks/csv_record_as_xml.ftl</ftl:template>
<ftl:use>
<ftl:bindTo id="csv_record_as_xml"/>
</ftl:use>
</ftl:freemarker>
<jms:router routeOnElement="csv-record" beanId="csv_record_as_xml" destination="TestQueue">
<jms:message>
<!-- Need to use special FreeMarker variable ".vars" -->
<jms:correlationIdPattern>${.vars["csv-record"].id}</jms:correlationIdPattern>
</jms:message>
<jms:jndi properties="/repository/resources/smooks/activemq.sr.jndi.properties" />
<jms:highWaterMark mark="10000000"/>
</jms:router>
</smooks-resource-list>
對於下面的配置單引號的工作原理:
<csv:reader fields="id,name,location" separator="," quote="'" skipLines="1" />
但對於下面的配置不起作用雙引號:
<csv:reader fields="id,name,location" separator="," quote=" " " skipLines="1" />
那麼我們應該怎樣做在雙引號的情況下? 注意:將雙引號更改爲另一個特殊符號在我的情況下不是公開的。