MuleSoft Dataweave Language: Reading Properties From Files Dynamically
This quick tutorial will show you how to read a properties file dynamically in Mule, using MuleSoft's Dataweave language.
Join the DZone community and get the full member experience.
Join For FreeIn this tutorial, we will see how we can use MuleSoft's Dataweave language to read a properties file dynamically.
As a first step, let's create a new Mule project using Anypoint Studio. After creating the project, let's define our code list as follows:
GB=United Kingdom
USA=United State of America
DE=Germany
JPN=Japan
CHN=China
We will name it 'codelist.properties.' Place it under your Mule project 'src/main/resouces' folder.
Next, let's add the properties file in our global configuration. We will add a new property place holder. For this step, go to Global Elements -> Create -> Property Place.
Let's create a flow with an HTTP inbound connector.
We have set the path to be '/country' and Allowed Methods to be 'GET' only. For HTTP Connector configuration, we have used the following settings:
As a next step, let us assume we will get a query parameter named 'code' in our request. We will set that parameter in a local variable named 'countryCode.'
In the final step, lets add a Transform Message component and call the dataweave function 'p.'
We can test the service after deploying the application in Anypoint Studio. You can use a browser or Postman to hit the service.
For request, try any one of the following URL's.
http://localhost:8081/country?code=GB
http://localhost:8081/country?code=USA
http://localhost:8081/country?code=DE
http://localhost:8081/country?code=JPN
The response will come back as follows (based on the code you've sent across as the query parameter):
{
"country": "United Kingdom"
}
I hope this article helps you understand how to read properties file dynamically using the Mulesoft Dataweave language.
Opinions expressed by DZone contributors are their own.
Comments