1

我想从我的 esb 主目录中名为 test.xml 的 xml 文件中读取,其内容是:

<a>Helloo
<b>World</b>
   </a>

我编写了一个代理来访问节点b的内容,如下所示:

<proxy xmlns="http://ws.apache.org/ns/synapse" name="ReadFileProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
      <property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM"/>
<log level="custom">
      <property name="test.b" expression="$ctx:test//b"/>
</log>
<header name="To" action="remove"/>
         <property name="RESPONSE" value="true" scope="default" type="STRING"/>
         <property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
         <payloadFactory>
            <format>
               <getCombinedResponse>Succefully read</getCombinedResponse>
            </format>
         </payloadFactory>
         <send/>
      </inSequence>
   </target>
   <description></description>
</proxy>

但这给了我错误:

[2013-06-18 16:29:09,524] ERROR - NativeWorkerPool Uncaught exception
org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog
 at [row,col {unknown-source}]: [1,0]
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.next(StAXOMBuilder.java:296)
        at org.apache.axiom.om.impl.llom.OMDocumentImpl.getOMDocumentElement(OMDocumentImpl.java:109)
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:570)
        at org.apache.axiom.om.impl.builder.StAXOMBuilder.getDocumentElement(StAXOMBuilder.java:566)
        at org.apache.axiom.om.util.AXIOMUtil.stringToOM(AXIOMUtil.java:54)
        at org.apache.axiom.om.util.AXIOMUtil.stringToOM(AXIOMUtil.java:39)
        at org.apache.synapse.config.SynapseConfigUtils.stringToOM(SynapseConfigUtils.java:766)
        at org.apache.synapse.mediators.builtin.PropertyMediator.convertValue(PropertyMediator.java:317)
        at org.apache.synapse.mediators.builtin.PropertyMediator.getResultValue(PropertyMediator.java:299)
        at org.apache.synapse.mediators.builtin.PropertyMediator.mediate(PropertyMediator.java:95)
        at org.apache.synapse.mediators.AbstractListMediator.mediate(AbstractListMediator.java:71)
        at org.apache.synapse.mediators.base.SequenceMediator.mediate(SequenceMediator.java:114)
        at org.apache.synapse.core.axis2.ProxyServiceMessageReceiver.receive(ProxyServiceMessageReceiver.java:154)
        at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
        at org.apache.synapse.transport.passthru.ServerWorker.processEntityEnclosingRequest(ServerWorker.java:434)
        at org.apache.synapse.transport.passthru.ServerWorker.run(ServerWorker.java:219)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:722)

我在这做错了什么。是否有任何其他方法可以从任何文件中读取(仅限 pdf、txt 和 xml)。

4

2 回答 2

2

正如您在配置中指定的

<property name="test" expression="get-property('registry','conf:/test.xml')" scope="default" type="OM"/>

您指的是保存在注册表中的文件。这就是为什么您需要将其保存在注册表中的原因。

于 2013-06-19T04:23:35.657 回答
1

您可以使用 VFS 传输来读取文件。请参考样本 [1]。从这个示例中,您可以了解如何从文件中读取。此示例直接将内容发送到端点。对于您的情况,您可以使用 xpath 表达式来检索元素 b。

<property name="test.b" expression="//a/b"/>

[1] http://docs.wso2.org/wiki/pages/viewpage.action?pageId=16846489

于 2013-06-18T11:15:07.627 回答