3

I get a file path as an input to mule inside xml. Using XPATH expression, I am able to extract the path. I want to read a particular file from that path. I tried to define file inbound endpoint as below. But it doesn't seem to be working.

    <flow name="flow1">
     ....
     ....
    <set-session-variable variableName="filePath" value="#[xpath://filePath]" />
    <flow-ref name="fileFlow"/>
    </flow>

    <flow name="fileFlow">
    <file:inbound-endpoint path="#[header:SESSION:filePath]" />
    </flow>

My understanding here is that no code can be placed before an inbound-endpoint. Hence I defined it in another flow. Please suggest if there is a way to read the file from a specified path.

tortoise
  • 613
  • 1
  • 7
  • 19

1 Answers1

4

Unfortunately, you cannot programmatically call an inbound-endpoint like that.

However the same functionality can be achieved using the Mule requester module:

Example:

  <flow name="RequestFile" doc:name="RequestFile">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="requestfile" doc:name="HTTP"/>
        <mulerequester:request config-ref="Mule_Requester" resource="file:///s/tmp/demorequester/read/#[message.inboundProperties['filename']]" returnClass="java.lang.String" doc:name="Request a file"/>
    </flow>

Instructions here: https://github.com/mulesoft/mule-module-requester and https://blogs.mulesoft.com/dev/mule-dev/introducing-the-mule-requester-module/

tbriscoe
  • 160
  • 1
  • 13
Ryan Carter
  • 11,441
  • 2
  • 20
  • 27
  • Reading files is quite simple with Groovy as well. If you want to read a text file into a String you just need: new File(message.getSessionProperty('filePath')).text. Or is there some reason to prefer the requester module? – Anton Kupias Feb 07 '14 at 20:10
  • 1
    @AntonKupias The problem with using direct File access instead of going through the Mule File transport is that you skip all the error handling, statistics... that Mule adds. So instead of using raw file, before the addition of the requester module, you would have had to use Groovy to call `muleContext.client.request('file:///the_file', timeout)` to actually use the Mule file transport. – David Dossot Feb 08 '14 at 15:43
  • @Ryan, I don't see any documentation on this component , Is it ok to use this component. Although I know it is community or do we get support for this component if there is a failure ? – Naveen Raj Nov 13 '15 at 06:11
  • Yes it is fine. I'm pretty sure they would as they created it. It's quite simple under the cover, mainly just a wrapper around the MuleClient. – Ryan Carter Nov 13 '15 at 10:30