I want to use HTTP Listener in my flows, and import csv files in Anypoint studio as input and convert them into JSON. Please help me.
-
What have you tried? What problems are you having?aled– aled2019-10-11 10:40:51 +00:00Commented Oct 11, 2019 at 10:40
-
When I use the HTTP listener and use the File component it does not fetch the local .csv file, but when I use the File component directly in the source, it can read .csv file from local storage but it does not store it in JSON format.Shreejit Malshikhare– Shreejit Malshikhare2019-10-11 11:47:34 +00:00Commented Oct 11, 2019 at 11:47
2 Answers
you can just use a transform message and convert payload to json.
as you can see i am reading a file called address.csv.

in the transform message you can simple right
and in my logger you can see that contents of file converted to json
note ------------------------------------------------- if you want to pick a file in middle of a flow with a http listener you can always use Message-Requester module
here is how the code will look like
<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" />
<mulerequester:request resource="file://src/main/resources/in/ReadME.txt?connector=file-connector-config" doc:name="Retrieve File" returnClass="java.lang.String" />
<logger message="Payload after file requester #[payload]" level="INFO" doc:name="Logger" />
</flow>
refer link --> https://dzone.com/articles/mule-reading-file-in-the-middle-of-a-flow-using-mu
2 Comments
Maybe I'm misunderstanding the question, but if you'd like the http listener kick off the flow, then to load the file, you'll need a groovy script.
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[return new File("C:\test.csv").getText("UTF-8");]]></scripting:script>
</scripting:component>

