Issue
I am trying to get the OS name available in my flow so I can adjust variable depending on the operating system running.
I am new to spring beans, but so far the below will call the set function ( I see it in the log) but I need to be able to access the osName from inside my flow.
java class:
public class CustomVariables {
public CustomVariables(){}
public String osName;
public String getOsName(){
System.out.println("got value: "+ osName);
return osName;
}
public void setOsName(String name){
osName = System.getProperty("os.name").toLowerCase();
System.out.println("set value: "+ osName); //this prints in console on startup
}
}
mule.xml:
<spring:beans>
<spring:bean class="netstockconnector.CustomVariables">
<spring:property name="osName" value="{os.name}"> </spring:property>
</spring:bean>
</spring:beans>
in flow:
<logger message="${osName}" level="INFO" doc:name="Logger"></logger>
This just prints to the console "${osName}" rather than "mac os x" for instance. Any ideas?
Solution
There is a much simpler solution...
<logger message='#[System.getProperty("os.name")]' level="INFO" doc:name="Logger"></logger>
To trigger the Mule Expression Language, the expression to evaluate should be between #[expression to evaluate]
. By default MEL imports a set of java classes which includes java.lang.System, hence the direct utilization in the expression.
Answered By - Franck
Answer Checked By - Senaida (JavaFixing Volunteer)