Question

I want to read from an xml file in my esb home directory called test.xml whose content is:

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

I have written a proxy to access content of node b as:

<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>

But it is giving me error as:

[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)

What am i doing wrong in this. Is there any other method to read from any file(pdf,txt and xml only).

Was it helpful?

Solution

As you have specified in the configuration

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

you are referring a file which is saved in the registry. This is why you need to save that in the registry.

OTHER TIPS

You can use VFS transport to read from a file. Please reffer the sample [1]. From this sample you can get to know how to read from a file. This sample directly sends the content to an endpoint. For your case you can use an xpath expression to retrieve the element b.

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top