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

  • MuleSoft: Tactical and Strategical Role of an Application Template
  • How To Build AI-Powered Prompt Templates Using the Salesforce Prompt Builder
  • Automated Bug Fixing: From Templates to AI Agents
  • MuleSoft OAuth 2.0 Provider: Password Grant Type

Trending

  • How to Use AWS Aurora Database for a Retail Point of Sale (POS) Transaction System
  • Operational Principles, Architecture, Benefits, and Limitations of Artificial Intelligence Large Language Models
  • Infrastructure as Code (IaC) Beyond the Basics
  • How GitHub Copilot Helps You Write More Secure Code
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. MuleSoft : Dynamic Content (Parser/Velocity Template)

MuleSoft : Dynamic Content (Parser/Velocity Template)

In this post, we will discuss, and provide examples of, how to use MuleSoft's Velocity Template and its Parse Template component.

By 
Amit Ghorpade user avatar
Amit Ghorpade
·
Mar. 08, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
9.1K Views

Join the DZone community and get the full member experience.

Join For Free

While working with some Spring applications, I came across Velocity Template, which is used to dynamically replace pieces of content in emails.

Some common use cases for the Velocity Template are welcome, registration, and password reset emails, where the developer just needs to replace the user’s email id, name, or reset password token. In this post, we will go through how to use Velocity Template and its magical component, Parse Template.

Velocity Template

Velocity Engine reads templates from given a resource, or LoaderPath. Add the below Velocity engine bean dependency to your code:

<beans:beans>
<beans:bean name=”velocityEngine” class=”org.springframework.ui.velocity.VelocityEngineFactoryBean”>
<beans:property name=”resourceLoaderPath” value=”classpath:templates”/>
</beans:bean>
</beans:beans>

This Velocity Engine will read template files from the resource/templates folder in your application.

Now, we will add a custom Java class which will have a bean property like the above Velocity engine, and another class which will create the template file name.

<custom-transformer class=”emailsendproject.VelocityMessageTransformer” doc:name=”Java”>
<spring:property name=”velocityEngine” ref=”velocityEngine” />
<spring:property name=”templateName” value=”WelcomeEmail.vm” />
</custom-transformer>

Email Template:

Welcome ${firstname} 
 This is send email with velocity template example demo.
Regards,
Amit Ghorpade

In this case, ${firstname } will be replaced by the dynamic value in the custom Java class using the Velocity template engine.

MuleSoft's Mule flow will look as shown below. In this flow, we will get input parameters from an HTTP component, then we will call a custom Java class where the Velocity engine will replace static content with input values and return the payload which will be used in the email's body content.

muleflow

Parse Template 

If you don’t know much more about the Velocity template and still want to achieve dynamic content templating, MuleSoft came up with a great component - Parse Template.

Parse Template accepts template file locations which will have content similar to what I've depicted below: 

Hello #[payload.firstname],#[message.inboundProperties.username]
    You have just submitted file: #[payload.fileName].
   Have a great day.
 Regards,
#[flowVars.sender]

Before we call this Parse Template component, set the values in payload, flowVars, andinboundproperties.

I loved this Parse Template feature. You can test both the examples with the code I've provided on my GitHub repo.

I hope this will help you in your project.

Template MuleSoft Velocity (JavaScript library)

Published at DZone with permission of Amit Ghorpade. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • MuleSoft: Tactical and Strategical Role of an Application Template
  • How To Build AI-Powered Prompt Templates Using the Salesforce Prompt Builder
  • Automated Bug Fixing: From Templates to AI Agents
  • MuleSoft OAuth 2.0 Provider: Password Grant Type

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!