I have a requirement like an id will be passed through HTTP request and depending on that ID i need to invoke dynamically the properties values.
For one ID I need properties like
dgc.metamodel.CommunityToSync=Community1
dgc.metamodel.DomainToSync=Domain1
For another ID I need like
dgc.metamodel.CommunityToSync=Community2
dgc.metamodel.DomainToSync=Domain2
Is it possible to do this in Mule?
AFAIK, property file will be read at the first time server is run. Although there are many properties only one key (unique) which will be referenced.
However to accommodate this requirement, I think we should utilizing Java code. This code will responsible to read the certain property file based on request (id). Then read the property and set it to variable for further usage:
private Properties prop = new Properties();
private InputStream input = null;
public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException {
String id = ((ParameterMap)message.getInboundProperty("http.query.params")).get("id");
input = getClass().getResourceAsStream("../property" + id + ".properties");
prop.load(input);
message.setInvocationProperty("communityToSync", prop.getProperty("dgc.metamodel.CommunityToSync"));
message.setInvocationProperty("domainToSync", prop.getProperty("dgc.metamodel.DomainToSync"));
I tested it with a simple flow
<flow name="propertyFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/prop" allowedMethods="GET" doc:name="HTTP"/>
<custom-transformer class="example.ReadProperty" doc:name="Java"/>
<logger message="CommunityToSync = #[flowVars.communityToSync], DomainToSync = #[flowVars.domainToSync]" level="INFO" doc:name="Logger"/>
</flow>
Execute it through browser: http://localhost:8081/prop?id=1 or http://localhost:8081/prop?id=2 to get the different result.