使用smooks交换edifact消息 - 响应期间出错

时间:2014-09-24 08:21:39

标签: apache-camel apache-servicemix smooks edifact

我需要将osgi包写入简单的unmarshal edifact消息(发票),并在数据库中保留发票。我在回复期间收到例外

我的环境: - ServiceMix 5.0.0

我有跟随骆驼路线

    <route>
        <from uri="mina2:tcp://localhost:9999?textline=true&amp;encoding=utf-8" />
        <to uri="smooks://smooks-config.xml" />
    </route>

    <route>
        <from uri="direct:invoice" />
        <process ref="invoiceProcessor" />
    </route> 

其中smooks-config.xml是:

<?xml version="1.0"?>
<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" 
    xmlns:edi="http://www.milyn.org/xsd/smooks/edi-1.2.xsd"
    xmlns:unedifact="http://www.milyn.org/xsd/smooks/unedifact-1.4.xsd"
    xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd"
    xmlns:camel="http://www.milyn.org/xsd/smooks/camel-1.4.xsd"
    >

    <unedifact:reader mappingModel="urn:org.milyn.edi.unedifact:d96a-mapping:1.4" ignoreNewLines="true" />

    <import file="/org/milyn/edi/unedifact/d96a/message-bindingconfig.xml" />

    <camel:route beanId="INVOIC">
        <camel:to endpoint="direct:invoice"/>
    </camel:route>

    <core:exports>
        <core:result type="org.milyn.payload.StringResult"/>
    </core:exports>

</smooks-resource-list>

如您所见,我正在使用标准的d96a绑定和映射。

当我调用netcat发送样本edifact消息时,除响应外,所有处理都没有问题。在回复期间,我收到:

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
org.milyn.SmooksException: Failed to filter source.
        at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:97)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:64)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.Smooks._filter(Smooks.java:526)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.Smooks.filterSource(Smooks.java:477)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.smooks.camel.processor.SmooksProcessor.process(SmooksProcessor.java:107)[221:org.milyn.smooks.osgi:1.5.2]
        at org.apache.camel.impl.ProcessorEndpoint.onExchange(ProcessorEndpoint.java:103)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.impl.ProcessorEndpoint$1.process(ProcessorEndpoint.java:71)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87)[98:org.apache.camel.camel-core:2.12.3]
        at org.apache.camel.component.mina2.Mina2Consumer$ReceiveHandler.messageReceived(Mina2Consumer.java:339)[186:org.apache.camel.camel-mina2:2.12.3]
        at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)[26:org.apache.mina.core:2.0.7]
        at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)[26:org.apache.mina.core:2.0.7]
        at java.lang.Thread.run(Thread.java:744)[:1.7.0_51]
Caused by: java.util.EmptyStackException
        at java.util.Stack.peek(Stack.java:102)[:1.7.0_51]
        at java.util.Stack.pop(Stack.java:84)[:1.7.0_51]
        at org.milyn.namespace.NamespaceDeclarationStack.popNamespaces(NamespaceDeclarationStack.java:132)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.edisax.unedifact.UNEdifactInterchangeParser.parse(UNEdifactInterchangeParser.java:125)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.smooks.edi.unedifact.UNEdifactReader.parse(UNEdifactReader.java:75)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.delivery.sax.SAXParser.parse(SAXParser.java:76)[221:org.milyn.smooks.osgi:1.5.2]
        at org.milyn.delivery.sax.SmooksSAXFilter.doFilter(SmooksSAXFilter.java:86)[221:org.milyn.smooks.osgi:1.5.2]
        ... 27 more

1 个答案:

答案 0 :(得分:0)

我是smooks的新人,我不知道问题的根源,但你可以改变你的骆驼路线:

<route>
    <from uri="mina2:tcp://localhost:9999?textline=true&amp;encoding=utf-8" />
    <to uri="smooks://smooks-config.xml" />
    <to uri="direct:invoice" />
</route>

<route>
    <from uri="direct:invoice" />
    <process ref="invoiceProcessor" />
</route> 

然后更改你的smooks-config.xml

<?xml version="1.0"?>
<smooks-resource-list 
xmlns="http://www.milyn.org/xsd/smooks-1.1.xsd"
xmlns:unedifact="http://www.milyn.org/xsd/smooks/unedifact-1.4.xsd"
xmlns:core="http://www.milyn.org/xsd/smooks/smooks-core-1.4.xsd"
>

<unedifact:reader mappingModel="urn:org.milyn.edi.unedifact:d96a-mapping:1.4" ignoreNewLines="true" />

<core:exports>
    <core:result type="org.milyn.payload.StringResult"/>
</core:exports>

</smooks-resource-list>

这与他们的示例相同:https://github.com/smooks/smooks/tree/67b38b41a17510758ea9f00b7d6fad189916b2ed/smooks-examples/camel/camel-unedifact-to-xml