Using the No-Arguments Entry Point Resolver
My previous post on entry point resolvers (EPRs) focused on the Callable EPR but a more useful one if you have pre-existing code is the no-arguments entry point resolver. This will allow Mule to invoke a service method even if the method does not have any parameters.
This seems unusual at first glance since we typically think of messages being sent to a component so that they can be processed or handled in some way. Why would we want to send a message to a component if the message will not be handled?
If you have pre-existing code, you may easily have methods that do not accept any parameters. Perhaps these methods are factory methods and generate stuff for you, maybe they are methods that are coded to be able to extract data from some repository and you just want to re-use this code without having to refactor it. Either way, you need to force Mule to invoke the method.
You can do this by sending any message to this component. The payload is not important as this is going to be a form of command message rather than a normal message. You then need to be sure that Mule will invoke the right method.
Mule therefore has a no-arguments EPR just for this purpose. I created a simple class that had a method without any arguments:
public class NoArgService { public String queryName () { return "Antoine Borg"; } }
I then configured a Mule model to have a service that refers to this class and which has the no-args EPR configured too:
<model name="noArgs"> <no-arguments-entry-point-resolver/> <service name="noArgsService"> <inbound> <inbound-endpoint ref="forNoArgs"/> </inbound> <component class="com.ricston.tests.NoArgService"/> </service> </model>
I invoked this from a test case and got the expected result. As you can see, the no-args EPR finds the right method and invokes it. This makes sense for my small class but if I had multiple no-args methods, I could restrict the EPR to look for methods with a given name by configuring it like this:
<no-arguments-entry-point-resolver> <include-entry-point method="queryName"/> </no-arguments-entry-point-resolver>
This tells the EPR to include this name alone within its search.

If you enjoyed this post, make sure you subscribe to my RSS feed!
Tags: Command Message pattern, Entry Point Resolvers, no-args-entry-point-resolver