Mule: How to configure custom component factory? - mule

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

Related

Accessing Mule Flow's MuleContext in CXF Java class within Flow

I am trying to implement a CXF Server flow as below. I want to synchronously invoke the VM from the Java component (after CXF component). However to synchronously invoke the VM, I need MuleContext (for eg: muleContext.send("vm://some_name", MuleMessage)). I am currently stuck, unable to find a way to access the Mule Flow's MuleContext inside Java component within the Flow.
Any help is highly appreciated..
Mule Flow Structure
Thanks,
Aneesh.
Check out the MuleSoft documentation https://docs.mulesoft.com/mule-user-guide/v/3.8/java-component-reference on writing a Java Component.
If your Java class implements the org.mule.api.lifecycle.Callable interface then you will be able to override the following method,
public Object onCall(MuleEventContext eventContext)
Inside this method you synchronously call the VM like this,
eventContext.sendEvent(message, endpoint)

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 ESB: How to use DataMapper with Global bean

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?

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

How mule invoke the component?

After go through some guides about Mule, I have a question about the component, as it is said in mule documentation,
A simple POJO (Plain Old Java Object) component that will be invoked
by Mule when a message is received. The class or object instance to be
used can be specified using a child object factory element, or via the
'class' attribute. If the 'class' attribute is used, an object
factory cannot be configured as well. Using the 'class' attribute is
equivilant to using the propotype object factory ('prototype-object'
child element).
in this documentation just said the component will be invoked by Mule when a message is received, but a problem is Mule how to know how many methods the component have, and which method should be invoked? or there must one method in the component and no matter the method name? and also mule how to deal with the parameters the method have?
Alternatively, you can use:
<invoke object-ref="..." method="..." methodArguments="..." />
which is way more convenient than configuring entry point resolvers.
yes, I got the answer, the answer is using mule entry point