Mule ESB: How to use DataMapper with Global bean - mule

I'm on Mule ESB 3.6 EE.
Trying to figure out how to leverage DataMapper component for populating properties of a global bean.
Basically, I have a bean defined like this:
<spring:beans>
<spring:bean id="testBean" name="testBean" class="com.test.MyTest" scope="prototype"/>
</spring:beans>
and I would like to populate it with using DataMapper. However, I can't figure out how to specify the bean object name (testBean) in the mapper wizard. The only option I can see is POJO where I can specify the class name but not the particular bean name.
So, any ideas how this could be solved?

Related

Mule: Extracting connector-ref to properties file

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.

How access property into Mule Java Transformer

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;

Mule: How to configure custom component factory?

I want a custom factory to create my java component.
Is it possible in Mule?
Use Spring to instantiate your component from the custom factory and refer to the created bean with:
<component>
<spring-object bean="yourBean"/>
<component>
Reference: http://www.mulesoft.org/documentation/display/current/Using+Spring+Beans+as+Flow+Components

Is it possible to define a spring bean backed by a dynamic language in Mule ESB?

I'm attempting to define a spring bean using as below:
<lang:groovy id="mmmm" name="GroovyRssGeneralTestServer" script-source="${app.home}/groovy/RssGeneralTestServerImpl.groovy">
<lang:property name="xmlFile" value="${app.home}/rss/GeneralTestServer.xml" />
</lang:groovy>
I've tried several different locations for the script-source, but have had no luck in getting mule to find the source for the groovy script.
Second, I'm curious whether I can even wire up a groovy component to use this bean even if I do get it configured correctly above?
Why are you trying Spring bean when there is a Groovy component in Mule that can execute external Groovy script ? Please refer :- http://www.mulesoft.org/documentation/display/current/Groovy+Component+Reference
and this :-
http://groovy.codehaus.org/Dynamic+language+beans+in+Spring
Hope this help

Setting global-property via java code

I need to set the global property grammatically. Functionally it should do exactly what the following statement should be doing
<global-property name="host-name" value="localhost" doc:name="Global Property"/>
I believe I should be able to access this property using ${host-name}. In this specific scenarion I don't want to load the property from properties file.
If you just want to resolve placeholders like ${host-name} you can extend the Spring PropertyPlaceholderConfigurer class with a custom implementation of method resolvePlaceholder, and add it as a Spring bean like this:
<spring:beans>
<spring:bean id="myConfigurer" class="my.test.MyConfigurer"/>
</spring:beans>
Your custom resolvePlaceholder is then called to resolve any unresolved properties.
It is also fairly simple to set actually set properties in the Mule context registry by getting the context from a message (message.getMuleContext()) or by implementing a MuleContextAware bean, but in those cases the property will not yet be available at the time when the property placeholders are resolved.
You would set the property like this:
context.getRegistry().registerObject("myKey", "myVal")
and access it later like this:
context.getRegistry().get("myKey")