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
Newsletter
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Security Is a Platform Property, Not a Pipeline Step
  • An XGBoost Property Valuation Postmortem: Leakage, Overfitting, and SHAP Surprises
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache

Trending

  • Giving AI Agents Safe Access to Legacy Systems: Introducing legacy2mcp
  • Google Cloud KMS vs. AWS KMS: Java Encryption Guide
  • The Self-Hosting Math Changed While We Were Still Arguing About Sovereignty
  • GenAI Security Gateway: An End-to-End Architecture

Draft This article hasn't been published, so readers can't see it.

In moderation This article is waiting for review, so readers can't see it yet.

Deleted This article has been deleted, so readers can't see it.

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
·
Dec. 23, 16 · Tutorial
Post on X (opens in a new tab) Share on LinkedIn (opens in a new tab)
5.2K Views

Join the DZone community Save articles, join the discussion, and download Refcards and Trend Reports with a free account.

Join for free Already a member? Log in

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

  • Security Is a Platform Property, Not a Pipeline Step
  • An XGBoost Property Valuation Postmortem: Leakage, Overfitting, and SHAP Surprises
  • Comprehensive Guide to Property-Based Testing in Go: Principles and Implementation
  • Implement Hibernate Second-Level Cache With NCache

Partner Resources

×

Comments

Loading comments

The comments didn't load

Please try again in a moment.

Likes

Loading

The next likes didn't load. Please try again.

The likes didn't load

Please try again in a moment.

See who liked this

Log in or join DZone for free to see who liked this article.

Log in Join for free
  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook