Best way to handle static/constant values in Mule config - mule

What is the best way to handle static/constant values in Mule config? I have a many flows that utilize expressions that need some static values. I was thinking of just creating a simple Java class to hold these and using MEL to access them. But is there a better way and possibly just using Mule config? Maybe set flowVars everytime for these values or use spring propety placeholders?

Store these values in a properties file and use them with ${ } placeholders in your expressions.

#jonlee I would use spring property placeholder. here is the reference doc

Related

Display Cloudhub Logs in Json Pattern along with Custom fields

Our client is not interested in using any 3rd party Logger like JSON Logger or any other logger comnectors available. So is there any way to modify the default Anypoint Logging pattern in cloudhub in Json format like how a Json Logger does. Is there any way to add custom fields using default logger like api_name or flow_start_time, end_time? Currently I am creating a variable and defining required fields in a Json pattern and further configure the variable in the default logger which is a workaround and working fine but its just I was curious if this is possible in some easier way without writing any dwl?
You can add custom variables using Mule 4.4 MDC logging feature. Note that it is not available with previous versions.
You can also request to override the default logging configuration in CloudHub, otherwise the log4j2.xml in the application is ignored, and try to use the JsonLayout. I don't recommend it though.

how to skip the dynamic arguments when it is empty in payloadFactory wso2 esb as XML

We are using WSO2 ESB, and we are using payloadFactory mediator to transform the message. we have entered into scenario where we need to ignore the payload arguments when it is empty or null. can any one help us achieve this?
You can try using filter mediator wherein you check the arguments in xpath, if arguments exist then you can call payload mediator with all the arguments, else you can call another payload which doesn't contain those arguments.
However according to me the best practice would be to use an xslt mediator where you put all your logic in the xslt, this would make your sequence small in length and more readable.

Best way to load properties file during runtime in mule

I would like to know what would be the best way to load the properties file in mule for the following scenario.
I have a properties file where in I set all the email related fields set in it like templates, to and from etc.
All these need to be set to a specific object along with other changes to that object so I'm planning to use a Java transformer and now I need to load all those values from that properties file and send to transformer. So what would be a best approach to work in above scenario.
Load properties in Java transformer using core java load properties
Load properties using spring context and send it to transformer and access using inbound properties
Kindly let me know if there is any other better approach other than above
First, you should be able to load the property file using spring context as shown below:
<context:property-placeholder location="somename.properties" />
Then, you can set specific property value as flow variable as shown below:
<set-variable variableName="fromAddress" value="${xyz.fromAddress}" />
Finally, you can access this flow variable in your processor class as shown below:
String fromAddress = muleEvent.getFlowVariable("fromAddress");
I will suggest to use Java load properties if these properties are only used in one Transformer. There is one more benefit out of Java load properties is that after modifying your properties file you do not need to restart the application.

Is there a way to implement access decision manager on HTTP listener connector on the fly without creating a class or component?

I was wondering if there is way to apply access decision manager on HTTP listener connector path directly rather than a component in mule studio?
Something like localhost:8081/GetEmployee=ROLE_ADMIN
You can Use filter to achieve this. Put filter on query parameter.
Please refer this for more details.
https://docs.mulesoft.com/mule-user-guide/v/3.4/using-filters
HTH.

How to convert Object to String in mule esb?

I am working with Mule ESB and our goal is to use dropbox as a end point connector means to store data to dropbox(from CSV/doc or any other data source). We are able to store data to drop box but data stored in the form of object and that is not in readable format so how to convert object to string so that it can be in readable format ?
Mule already has Object to String transformer to transform String from Object :- https://developer.mulesoft.com/docs/display/current/Transformers
What I think you're after is called object serialization, and you have many choices about how to do it in a way that people can read it.
Perhaps the oldest way in java (which is the language Mule is based on) is to implement a toString() method and format your object's data as you like. Of course, this means your message payload must be an instance of a class you can make changes to. If you choose this method, you can simply add an <object-to-string-transformer /> as Anirban suggested.
Some common ways people do this, especially with Mule ESB, is to use XML or JSON to represent the information in the object. Mule includes strong support of XML and JSON. Many times, you can simply add a <json:object-to-json-transformer /> to your flow, and the payload will be converted automatically. For this to work, your payload needs to be simple types such as Maps and Lists, or an instance of a class with JAXB mappings.
Your question is a bit confusing .
if you are asking about the transformation in mule add this in your XML file <object-to-string-transformer doc:name="Object to String"/> after the dropbox component.