0

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.

2
  • What have you tried? What problems are you having? Commented 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. Commented Oct 11, 2019 at 11:47

2 Answers 2

2

you can just use a transform message and convert payload to json.

as you can see i am reading a file called address.csv. enter image description here

in the transform message you can simple right

enter image description here

and in my logger you can see that contents of file converted to json

enter image description here

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, @satishchennupati. It is working as expected. I am able to import 2 files using this Mule Requester, but is there any way to filter the content of these two files after reading them, and also displaying the filtered content in final response as JSON? Like filtering the uncommon fields in both the CSV files.
i can try that one out
1

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.