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.
Related
I have a line that reads like this in my flow:
<jms:inbound-endpoint queue="${queue.name}" connector-ref="${inbound.connector}" doc:name="Inbound Endpoint">
Where the "${inbound.connector}" property refers to a string in my properties file:
inbound.connector=Active_MQ
The reason I am doing this is because the connector-ref will vary depending on the environment. Sometimes it will be an Active_MQ connector, sometimes it will be a JMS Connector.
The properties file is under src/main/resources, as it should be. I have other properties in the flow that are read from the properties file just fine, such as the "queue.name" property. However, for some reason when I try to start Mule it is returning an error saying:
NoSuchBeanDefinitionException: No bean named '${inbound.connector}' is defined.
As far as I know the connector-ref value is just a string, so this should work in theory. I don't understand this error. Is the connector-ref in fact not a string, and this approach is illegal?
Internally mule runtime creates/initializes all the connector objects(spring bean) like HTTP Connectors, DATASOURCE connectors and various other connector's when the application comes up. All these connectors are nothing but a spring beans as Mule is written on top of Springframework. So it is not possible to make it dynamic by passing in a string value where it expects a object.
I have a properties file shared on several apps. To access this properties into one app, I use this tag:
<context:property-placeholder location="classpath:br/com/empresa/configuracao/mule-apps.properties"/>
On several Mule components, like database attributes connections, I use the following expression to access the properties, p.e.: ${db.user}. It works!
But on Java Transformer, how I access the properties?
I tried the following instructions, but returned null:
System.getProperty("db.user");
message.getInboundProperty("db.user");
message.getOutboundProperty("db.user");
message.getInvocationProperty("db.user");
Is there a way to access properties into Mule Java Transformer?
This question has been answered for components here: How to get property from context property placeholder tag inside custom java component The exact same logic applies to transformers.
Use property injection:
<custom-transformer class="org.myCompany.CustomTransformer">
<property name="dbUser" value="${db.user}" />
</custom-transformer>
Don't forget to add setDbUser on your custom component!
You could use the old way of retrieving a property:
#Value("${db.user")
private String dbUser;
How can I access Spring properties defined in app.properties from Mule FuncionalTestCase?
For example, in my production config I have a ${sessionExpiresInSecondsValue} passed in to a bean property. What I want to do is get this value and use it with the FunctionalTestComponent to wait for the same amount of time as that value and I don't want to harcode so the test go out of sync with the value.
The easiest is to get this bean that receives ${sessionExpiresInSecondsValue} from the registry, via MuleContext, and call getSessionExpiresInSecondsValue() on it.
I have an application with Spring 3 and struts 2. I have my own properties files with custom messages. These files are loaded dynamically with spring while startup. And I use PropertyCache.getMessage() from any where in my code to get those custom messages. These message resources are fully controlled by my application and spring.
Now I have a scenario of file upload. The upload limit is configured in global struts constants and with "fileUpload" interceptors. As per the theory, when a user tries to upload big files the framework will show up its message (i know how to customize it with struts).
Since I am using my own resources, I want to show up my custom message (not going to use "struts.messages.error.file.too.large") using my own "PropertyCache.getMessage()" method.
How is it possible to override struts error message so that the framework will pick up the message from my own resource instead of struts constant/struts global properties?
Well i do not see any direct solutions to your problem as the above message is being set under the fileUploader interceptor,its quite possible that there might be some more flexible and best solution out there.
For now i can suggest you to create a FileUploaderInterceptor and you can use your Spring message reader functionality to read message from your custom message file and replace Struts2 getTextMessage() method
FileUploadInterceptor
I would like to have a reference of the actual used data source (eg: com.ibm.xsp.model.domino.wrapped.DominoDocument) in a managed bean object. Is it possible to have such a property? And how do you implement this approach?
Data source itself is a request scope bean. It is bad idea to keep it as property, I would suggest that your bean's methods accept data source as parameter.
Another approach would be to keep String value of data source name, and get it via JSF binding.