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

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache
  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features

Trending

  • Enhancing Business Decision-Making Through Advanced Data Visualization Techniques
  • Using Python Libraries in Java
  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Can You Run a MariaDB Cluster on a $150 Kubernetes Lab? I Gave It a Shot

How to Generate Property Key at Run-Time

In this article, Abhay Singh explains how to generate a property key at run-time and accessing the corresponding value using DataWeave.

By 
Abhay Singh user avatar
Abhay Singh
·
Dec. 23, 16 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
5.0K Views

Join the DZone community and get the full member experience.

Join For Free

we are very much aware how important of a role property files play in mule esb in making integrations and applications dynamic, and even in making it reusable.

generally, a value in the property file can be accessed by nesting the key within curly brackets, which is preceded by the $ symbol (like this: ${key} .).

with the idea of making integrations and applications as dynamic and fluid as possible, one can generate values from property files at compile-time or run-time.

one way of generating property values at runtime is by using dataweave. dataweave supports accessing property values in property files using property keys.

scenario

in this scenario, we will be creating a file whose properties are in a property file. these properties are the name of the file, the content of the file, and the path where the file will be placed.

to begin with, we have an http listener that accepts interfacenumber as the input parameter. based on the interface number, the application will form property keys in the message properties transformer, which will be assigned to a unique flow variable. this flow variable, when accessed inside dataweave, will return the desired property value specific to that particular interface.

the applications endpoint is a file connector, wherein configurations such as file name/pattern and path are generated dynamically depending on the interface.

mule flow

image title

the configuration xml of the flow is given below:

<http:listener-config name="http_listener_configuration" host="${http.host}" port="${http.port}" doc:name="http listener configuration"/>
<flow name="runtimeproperties_flow">
<http:listener config-ref="http_listener_configuration" path="${http.path}" doc:name="http"/>
        <message-properties-transformer scope="invocation" doc:name="message properties">
            <add-message-property key="filename" value="#['interface.' + message.inboundproperties['http.query.params']['interfacenumber'] + '.filename']"/>
            <add-message-property key="filecontent" value="#['interface.' + message.inboundproperties['http.query.params']['interfacenumber'] + '.filecontent']"/>
            <add-message-property key="filepath" value="#['interface.' + message.inboundproperties['http.query.params']['interfacenumber'] + '.filepath']"/>
        </message-properties-transformer>
        <set-payload doc:name="set payload" value="#[dw('p(flowvars.filecontent)')]"/>
        <file:outbound-endpoint responsetimeout="10000" doc:name="file" outputpattern="#[dw('p(flowvars.filename)')]" path="#[dw('p(flowvars.filepath)')]"/>

</flow>

the structure of the property file is given below:

####################### http properties  #######################
http.host=0.0.0.0
http.port=8081
http.path=/test

################### interface 001 properties ###################
interface.001.filename=interface001.txt
interface.001.filecontent=this is test data for interface 001
interface.001.filepath=c:\users/xyz/desktop/test/interface 001

################### interface 002 properties ###################
interface.002.filename=interface002.txt
interface.002.filecontent=this is test data for interface 002
interface.002.filepath=c:\users/xyz/desktop/test/interface 002

from the configuration xml, one can figure that we are creating a key structure similar to that in the property file and store it in a flow variable.

these flow variables are then accessed using the dataweave function inside any component as per the configuration.

hence, we have managed to dynamically access property values at compile time solely from the input received and successfully generated the desired result.

Property (programming)

Opinions expressed by DZone contributors are their own.

Related

  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache
  • Modify JSON Data in Postgres and Hibernate 6
  • Top 10 C# Keywords and Features

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!