Author: Abhinav Patel
Welcome All to the series of HTML rendering in Mule! With this series, I am introducing you all to a whole new world of services that could be created using MuleSoft tools.
If you have not gone through my previous article, I would recommend you to go through it first to get a basic understanding of HTML rendering and its requirements. In this article, we will try to understand the working of Parse Template for multiple records, where we will try to send the bulk of the record in a single response. We are just going to extend the scenario that is explained in the previous blog. Let us assume that the admin department wants the details of all the employees at any given time. How will we cater to this request?
Keeping the rest of the configurations same as previous, we will just change the configuration for Parse Template and add a new Transform message component. Send Email and Read File operation inherit their configuration properties from the previous blog.
All the new configurations are done so as to achieve this as shown below (the rest of the values are set to default or as done previously):
- Transform Message:
- Parse Template:
Also, since this functionality will be used by the Admin team occasionally, hence I have planned to replace the scheduler with HTTP Listener listening to “test” endpoint.
Once the application is ready to be deployed, let’s run the application and test it.
- While making a call to http://localhost:8081/test using a browser, the response received will be “Mail sent successfully” due to set Payload.
- If you check the mail, you will be able to see the employee details as shown below:
Now, you have a basic understanding of sending a well-formatted HTML response using dataweave. We can even extend the same to other data sources like a Relational Database or NoSQL with some slight configuration changes.
Now let us think how we can extract the data from HTML responses.
For demonstration purpose, I have taken my first blog published on wordpress as an example. Look into the code mentioned below to get an idea on how to retrieve the details from the HTML response using dataweave (Note: there are other examples to do the same; using java libraries too).
I hope you got to learn something new from this walk-through. Do post your responses in the comment to let me know that your application is running. Till then continue reading the other blogs that I have written and let me know your thoughts on those.