DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How To Build AI-Powered Prompt Templates Using the Salesforce Prompt Builder
  • Automated Bug Fixing: From Templates to AI Agents
  • Dynamic File Upload Component in Salesforce LWC
  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices

Trending

  • Navigating Double and Triple Extortion Tactics
  • Simplifying Multi-LLM Integration With KubeMQ
  • Designing for Sustainability: The Rise of Green Software
  • What Is Plagiarism? How to Avoid It and Cite Sources

Parse Template Transformer in Mule

Learn how and when to use the Parse Template component in Mule and see an example of a request and response in a Mule flow.

By 
Ankit Lawaniya user avatar
Ankit Lawaniya
·
Aug. 12, 17 · Tutorial
Likes (13)
Comment
Save
Tweet
Share
22.3K Views

Join the DZone community and get the full member experience.

Join For Free

The Parse Template component loads a file into the Mule payload. The 'Parse Template' transformer parses a template file that can contain MEL expressions and places the resulting string into the message payload.We can use the payload,flowVars and inboundproperties in the template to create the dynamic content.

  • Use Case 1: When we want to prepare the payload to be used by the Web Service Consumer or for a SOAP request.

  • Use Case 2: When we want to create a template for emailing.

  • Use Case 3: There are other scenarios where it can be useful, such as returning HTML to a client from an HTTP transport. We can load an HTML file into the payload that includes embedded MEL.  

Samples of MEL that we can define in the template:

  • #[message.inboundProperties.'http.query.params'.name]

  • #[flowVars.accountNumber]

  • #[payload[0]['order_no']]

Let’s walk through how to use JSON Schema validator in Mule application. In this example, we are receiving the order through HTTP call from the end user. We are using a parse template to load a file from an external location – a file which, behaving as a template, expects values for "order number," "order description," and "order provisioning date." The parse template extracts info from the Mule message variables to insert as values into the template and set the resulting contents as the message payload.

Mule Flow:Image title

Code:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json="http://www.mulesoft.org/schema/mule/json"
xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:jms="http://www.mulesoft.org/schema/mule/jms"
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" version="EE-3.8.1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.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/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.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:listener-config name="HTTP_Listener_Configuration"
host="localhost" port="8081" basePath="/parse" doc:name="HTTP Listener Configuration" />
<flow name="parseTempate">
<http:listener config-ref="HTTP_Listener_Configuration" path="/parse"/> 
<set-payload mimeType="application/json" value="#[payload]" />
<json:json-to-object-transformer
returnClass="java.lang.Object" doc:name="JSON to Object" />
<parse-template location="responseHtml.template"
doc:name="Parse Template" />
<set-property doc:name="Content Type" propertyName="Content-Type"
value="text/html" />
</flow>
</mule>

responseHtml.template

<html>
        <body>
                <table border=4>
                <tr>
                        <th>Order No</th>
                        <th>Order Description</th>
                         <th>Provisioning Date</th>  
                </tr>
                <tr>
                        <td>#[payload[0]['order_no']]</td>
                        <td>#[payload[0]['order_description']]</td>
                         <td>#[payload[0]['provisioning_date']]</td>
                </tr>
                </table>
        </body>
</html>

To execute this flow, we will have to open the REST client and pass the payload as part of the POST request body. Below are the screenshots of the request and response.

Request:

[
{ 
"order_no" : "199",
"order_description" : "PostpaidOrder",
"provisioning_date" : "28/07/2017"
}
]


Image title

Hope this helps.

Thanks.

Keep learning.

Template

Opinions expressed by DZone contributors are their own.

Related

  • How To Build AI-Powered Prompt Templates Using the Salesforce Prompt Builder
  • Automated Bug Fixing: From Templates to AI Agents
  • Dynamic File Upload Component in Salesforce LWC
  • Safeguarding Web Applications With Cloud Service Providers: Anti-CSRF Tokenization Best Practices

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!