Search code examples
mulemule-studiomule-componentmule-elmule-esb

How to read file in middle of the flow


I am trying to read two simultaneously file in middle of the flow and combine them into one payload. To reading the files in middle of the flow I am using mule requester component. While triggering the flow (localhost:8081/requester/requester)I am getting error :

"Exception(s) were found for route(s): 0: The endpoint "src\main\resources\input1\employees.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException). 1: The endpoint "src\main\resources\input2\employees2.xml" is malformed and cannot be parsed. If this is the name of a global endpoint, check the name is correct, that the endpoint exists, and that you are using the correct configuration (eg the "ref" attribute). Note that names on inbound and outbound endpoints cannot be used to send or receive messages; use a named global endpoint instead. (org.mule.api.endpoint.MalformedEndpointException)."

 <?xml version="1.0" encoding="UTF-8"?>
 <mule xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:mulerequester="http://www.mulesoft.org/schema/mule/mulerequester" xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/mulerequester http://www.mulesoft.org/schema/mule/mulerequester/current/mule-mulerequester.xsd  http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
<file:connector name="file-connector-config" autoDelete="false" streaming="true" validateConnections="true" doc:name="File" />
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" basePath="/requester" doc:name="HTTP Listener Configuration" />
<flow name="muleRequester">
    <http:listener config-ref="HTTP_Listener_Configuration" path="/requester" doc:name="HTTP" />
    <logger message="Invoking Mule Requester" level="INFO" doc:name="Logger" />
    <scatter-gather doc:name="Scatter-Gather">
           <mulerequester:request resource="src\main\resources\input1\employees.xml" returnClass="java.lang.String" doc:name="Retrieve File1"/>

           <mulerequester:request resource="src\main\resources\input2\employees2.xml" returnClass="java.lang.String" doc:name="Retrieve File2"/>
      </scatter-gather><dw:transform-message doc:name="Transform Message"> 
        <dw:set-payload>< [CDATA[%dw 1.0 %output application/json
   ---
    {
payload1: payload[0],
payload2: payload[1]
    }]]></dw:set-payload>
    </dw:transform-message>
    <file:outbound-endpoint path="src/main/resources/output" responseTimeout="10000" doc:name="File"/>
    <logger message="Payload after file requester #[payload]" level="INFO" doc:name="Logger" />
</flow>

I am not using maven. Do I need to download any other jar or where I can do the correction?


Solution

  • resource needs to be an Mule endpoint url. Mule requester module can work with many transports such as jms, file, ftp. So the path to the file is not enough. Here is an example of an endpoint url for reading a file:

    <mulerequester:request resource="file://src/main/resources/in/ReadME.txt?connector=file-connector-config" doc:name="Retrieve File" returnClass="java.lang.String" />
    

    You can also point to a global endpoint like you have defined like so:

    <mulerequester:request config-ref="muleRequesterConfig" resource="myFileEndpoint" doc:name="Mule Requester" />