使用smooks解析csv文件会返回错误null或空arg

时间:2016-07-07 13:06:25

标签: java csv wso2esb smooks

我尝试使用最新版本的smooks(1.5.1)和wso2 esb ang get错误解析csv文件: java.lang.IllegalArgumentException:方法调用中为null或空'field'arg。

我的csv文件有多记录字段定义: 输入.csv文件(使用制表符分隔):

T11 T12 T13 T14 T15 T16
T21 T22 T23 T24 T25 T26
T3

代理服务(仅限smooks配置部分:

<smooks config-key="smooks-config">
<input type="text"/>
<output type="xml"/>
</smooks>

Smooks配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<localEntry key="smooks-config" xmlns="http://ws.apache.org/ns/synapse">
  <smooks-resource-list xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd" xmlns:csv="http://www.milyn.org/xsd/smooks/csv-1.5.xsd">
    <csv:reader fields="T11[*] | T22[*] | T3[*]" indent="true"
      recordElementName="message" rootElementName="messages" separator="&#x9;"/>
  </smooks-resource-list>
</localEntry>

结果我得到例外:

TID: [-1234]  [ESB]  [2016-07-07 15:33:16,742] DEBUG -  Start : Smooks mediator {org.wso2.carbon.mediator.transform.SmooksMediator}
TID: [-1234]  [ESB]  [2016-07-07 15:33:16,756] ERROR -  Failed to filter source. {org.wso2.carbon.mediator.transform.SmooksMediator}
org.milyn.SmooksException: Failed to filter source.
    at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:97)
    at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:64)
    at org.milyn.Smooks._filter(Smooks.java:526)
    at org.milyn.Smooks.filterSource(Smooks.java:482)
    at org.wso2.carbon.mediator.transform.SmooksMediator.mediate(SmooksMediator.java:131)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:149)
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:185)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.axis2.transport.base.AbstractTransportListener.handleIncomingMessage(AbstractTransportListener.java:328)
    at org.apache.synapse.transport.vfs.VFSTransportListener.processFile(VFSTransportListener.java:751)
    at org.apache.synapse.transport.vfs.VFSTransportListener.scanFileOrDirectory(VFSTransportListener.java:407)
    at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:177)
    at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:124)
    at org.apache.axis2.transport.base.AbstractPollingTransportListener$1$1.run(AbstractPollingTransportListener.java:67)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: null or empty 'fields' arg in method call.
    at org.milyn.assertion.AssertArgument.isNotNullAndNotEmpty(AssertArgument.java:105)
    at org.milyn.flatfile.Record.<init>(Record.java:43)
    at org.milyn.flatfile.variablefield.VariableFieldRecordParser.nextRecord(VariableFieldRecordParser.java:201)
    at org.milyn.flatfile.FlatFileReader.parse(FlatFileReader.java:176)
    at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:76)
    at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)
    ... 19 more
TID: [-1234]  [ESB]  [2016-07-07 15:33:16,763] ERROR -  Failed to filter source. Caused by Failed to filter source. {org.apache.synapse.mediators.base.SequenceMediator}
org.wso2.carbon.mediator.service.MediatorException: Failed to filter source. Caused by Failed to filter source.
    at org.wso2.carbon.mediator.transform.SmooksMediator.handleException(SmooksMediator.java:252)
    at org.wso2.carbon.mediator.transform.SmooksMediator.mediate(SmooksMediator.java:147)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:81)
    at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:48)
    at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:149)
    at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:185)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
    at org.apache.axis2.transport.base.AbstractTransportListener.handleIncomingMessage(AbstractTransportListener.java:328)
    at org.apache.synapse.transport.vfs.VFSTransportListener.processFile(VFSTransportListener.java:751)
    at org.apache.synapse.transport.vfs.VFSTransportListener.scanFileOrDirectory(VFSTransportListener.java:407)
    at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:177)
    at org.apache.synapse.transport.vfs.VFSTransportListener.poll(VFSTransportListener.java:124)
    at org.apache.axis2.transport.base.AbstractPollingTransportListener$1$1.run(AbstractPollingTransportListener.java:67)
    at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

我认为问题出在“T3”行(如果我从csv中删除这一行 - 文件被解析,但没有额外的“recordElementName”)

先谢谢

1 个答案:

答案 0 :(得分:0)

cvs reader config中的字段定义看起来不正确。

根据Smooks 1.5文档:

  

注意&#39;字段中的sytax&#39;属性。每个记录定义由管道符号&#39; |&#39;分隔。每个记录定义都构造为记录名[field-name,field-name]。 记录名称与传入消息中的第一个字段匹配,因此用于选择用于输出该记录的相应记录定义。另请注意,当您不想为记录字段命名时,如何使用astrix字符(&#39; *&#39;)。在这种情况下(如在记录中存在额外/意外字段时),阅读器将使用生成的元素名称生成输出字段元素,例如, &#34; field_0&#34;,&#34; field_1&#34;等。阅读&#34;杂志&#34;记录在上一个例子中。

请注意,记录名应该与行中的第一个字段匹配。

我的理解是cvs reader config在你的例子中应该是这样的:

<csv:reader fields="T11[*] | T21[*] | T3[*]" indent="true" 
    recordElementName="message" rootElementName="messages" 
    separator="&#x9;"/>

注意&#34; T21 [*]&#34;而不是&#34; T22 [*]&#34;

尝试更正并查看它是否修复了您怀疑是T3问题。