mule的第一个应用非常简单。却也可以看出mule的运行机制。上例中,实现的是hello world 的例子,过程为:用户输入内容,回车,然后显示hello,[输入的内容]。这个实现非常简单,但是,却也存在一些问题,mule是怎么知道显示这些内容的,现在就研究这个。
也许大家觉得,在xxxx.xml中已经配置了类路径,mule当然可以找到这个类,问题就在这里,mule找到了实现类,那他是如何找到对应的方法的呢?ok,做一下尝试
将inteface修改为:
package demo.mule.umo;
public interface helloworld {
public string sayhello(string str);
public string sayhello();
}
package demo.mule.umo;
public interface helloworld {
public string sayhello(string str);
public string sayhello();
}
实现类修改为:
package demo.mule.umo.impl;
import demo.mule.umo.helloworld;
public class helloworldimpl
implements helloworld {
@override
public string sayhello(string str) {
return "hello," + str;
}
public string sayhello() {
return "hello world";
package demo.mule.umo.impl;
import demo.mule.umo.helloworld;
public class helloworldimpl implements helloworld {
@override
public string sayhello(string str) {
return "hello," + str;
public string sayhello() {
return "hello world";
运行项目:运行成功!
修改interface为:
public string sayhello2(string str);
public string sayhello2(string str);
修改实现类为:
public string sayhello2(string str) {
return "hello2 ," + str;
public string sayhello2(string str) {
return "hello2 ," + str;
运行:抛出error
error 2011-02-09
17:04:41,874 [helloumo.2] org.mule.service.defaultserviceexceptionstrategy:
********************************************************************************
message : [
the required property "method" is not set on the event
callableentrypointresolver:object "demo.mule.umo.impl.helloworldimpl@12f1bf0" does not implement required
interface "interface org.mule.api.lifecycle.callable"
found too many possible methods on object "demo.mule.umo.impl.helloworldimpl" that accept parameters
"{class java.lang.string}" using resolver
"reflectionentrypointresolver{ignoredmethods=[getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring, notifyall]{transformfirst=true, acceptvoidmethods=false}"
found too many possible methods on object
"demo.mule.umo.impl.helloworldimpl" that accept parameters "{class java.lang.string}" using resolver
"reflectionentrypointresolver{ignoredmethods=[getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring, notifyall]{transformfirst=false, acceptvoidmethods=false}"
]
type : org.mule.model.resolvers.entrypointnotfoundexception
code : mule_error--2
javadoc : http://www.mulesource.org/docs/site/current2/apidocs/org/mule/model/resolvers/entrypointnotfoundexception.html
exception stack is:
1. [
] (org.mule.model.resolvers.entrypointnotfoundexception)
org.mule.model.resolvers.defaultentrypointresolverset:63 (http://www.mulesource.org/docs/site/current2/apidocs/org/mule/model/resolvers/entrypointnotfoundexception.html)
root exception stack trace:
org.mule.model.resolvers.entrypointnotfoundexception: [
at org.mule.model.resolvers.defaultentrypointresolverset.invoke(defaultentrypointresolverset.java:63)
at org.mule.component.defaultlifecycleadapter.invoke(defaultlifecycleadapter.java:205)
at org.mule.component.abstractjavacomponent.invokecomponentinstance(abstractjavacomponent.java:83)
at org.mule.component.abstractjavacomponent.doinvoke(abstractjavacomponent.java:74)
at org.mule.component.abstractcomponent.invokeinternal(abstractcomponent.java:133)
at org.mule.component.abstractcomponent.invoke(abstractcomponent.java:161)
at org.mule.service.abstractservice.invokecomponent(abstractservice.java:929)
at org.mule.model.seda.sedaservice.access$100(sedaservice.java:56)
at org.mule.model.seda.sedaservice$componentstageworker.run(sedaservice.java:574)
at org.mule.work.workercontext.run(workercontext.java:310)
at edu.emory.mathcs.backport.java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:575)
at java.lang.thread.run(thread.java:619)
error 2011-02-09 17:04:41,874 [helloumo.2] org.mule.service.defaultserviceexceptionstrategy:
********************************************************************************
message : [
the required property "method" is not set on the event
callableentrypointresolver:object "demo.mule.umo.impl.helloworldimpl@12f1bf0" does not implement required interface "interface org.mule.api.lifecycle.callable"
found too many possible methods on object "demo.mule.umo.impl.helloworldimpl" that accept parameters "{class java.lang.string}" using resolver "reflectionentrypointresolver{ignoredmethods=[getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring, notifyall]{transformfirst=true, acceptvoidmethods=false}"
found too many possible methods on object "demo.mule.umo.impl.helloworldimpl" that accept parameters "{class java.lang.string}" using resolver "reflectionentrypointresolver{ignoredmethods=[getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring, notifyall]{transformfirst=false, acceptvoidmethods=false}"
]
type : org.mule.model.resolvers.entrypointnotfoundexception
code : mule_error--2
javadoc : http://www.mulesource.org/docs/site/current2/apidocs/org/mule/model/resolvers/entrypointnotfoundexception.html
exception stack is:
1. [
] (org.mule.model.resolvers.entrypointnotfoundexception)
org.mule.model.resolvers.defaultentrypointresolverset:63 (http://www.mulesource.org/docs/site/current2/apidocs/org/mule/model/resolvers/entrypointnotfoundexception.html)
root exception stack trace:
org.mule.model.resolvers.entrypointnotfoundexception: [
at org.mule.model.resolvers.defaultentrypointresolverset.invoke(defaultentrypointresolverset.java:63)
at org.mule.component.defaultlifecycleadapter.invoke(defaultlifecycleadapter.java:205)
at org.mule.component.abstractjavacomponent.invokecomponentinstance(abstractjavacomponent.java:83)
at org.mule.component.abstractjavacomponent.doinvoke(abstractjavacomponent.java:74)
at org.mule.component.abstractcomponent.invokeinternal(abstractcomponent.java:133)
at org.mule.component.abstractcomponent.invoke(abstractcomponent.java:161)
at org.mule.service.abstractservice.invokecomponent(abstractservice.java:929)
at org.mule.model.seda.sedaservice.access$100(sedaservice.java:56)
at org.mule.model.seda.sedaservice$componentstageworker.run(sedaservice.java:574)
at org.mule.work.workercontext.run(workercontext.java:310)
at edu.emory.mathcs.backport.java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1061)
at edu.emory.mathcs.backport.java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:575)
at java.lang.thread.run(thread.java:619)
修改interface:
public string sayhello2();
public string sayhello2();
修改实现类:
public string sayhello2() {
return "hello2 world";
public string sayhello2() {
return "hello2 world";
17:07:27,811 [helloumo.2] org.mule.service.defaultserviceexceptionstrategy:
callableentrypointresolver:object "demo.mule.umo.impl.helloworldimpl@1f02b85" does not implement required
could not find entry point on: "demo.mule.umo.impl.helloworldimpl" with arguments:
error 2011-02-09 17:07:27,811 [helloumo.2] org.mule.service.defaultserviceexceptionstrategy:
callableentrypointresolver:object "demo.mule.umo.impl.helloworldimpl@1f02b85" does not implement required interface "interface org.mule.api.lifecycle.callable"
could not find entry point on: "demo.mule.umo.impl.helloworldimpl" with arguments: "{class java.lang.string}" using resolver "reflectionentrypointresolver{ignoredmethods=[getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring, notifyall]{transformfirst=true, acceptvoidmethods=false}"
could not find entry point on: "demo.mule.umo.impl.helloworldimpl" with arguments: "{class java.lang.string}" using resolver "reflectionentrypointresolver{ignoredmethods=[getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring, notifyall]{transformfirst=false, acceptvoidmethods=false}"
比较两次抛出的error,不难发现这句话“
could not find entry point on: "demo.mule.umo.impl.helloworldimpl" with arguments: "{class java.lang.string}" using resolver "reflectionentrypointresolver{ignoredmethods=[getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring,
notifyall]{transformfirst=true, acceptvoidmethods=false}"
”,真相大白:mule通过<inbound></inbound>中得到的结果,作为寻找方法中参数的依据,由于该项目中,从终端输入的内容,项目接收时为string类型,因此,mule将查找参数类型为string的方法,同时,mule将抛弃所有符合“getclass, clone, equals, hashcode, getinvocationhandler, get*, wait, is*, notify, tostring, notifyall”的方法,如果符合条件的只有一个,那正好调用,否则,就抛出error。
如果程序中很可以确定是哪个方法,大可让他自己去找,成人之美,若是不能确定是哪个方法,那么就只能够指腹为婚了,进行如下配置:
将尝试二的配置文件修改为:
<?xml version="1.0" encoding="utf-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
xsi:schemalocation="
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd">
<stdio:connector name="systemstreamconnector"
promptmessage="please enter yout name: " messagedelaytime="1000"/>
<model name="hellosample">
<service name="helloumo">
<inbound>
<stdio:inbound-endpoint system="in" />
</inbound>
<component class="demo.mule.umo.impl.helloworldimpl">
<method-entry-point-resolver>
<include-entry-point method="sayhello2"/>
</method-entry-point-resolver>
</component>
<outbound>
<pass-through-router>
<stdio:outbound-endpoint system="out" />
</pass-through-router>
</outbound>
</service>
</model>
</mule>
<?xml version="1.0" encoding="utf-8"?>
<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
xmlns:stdio="http://www.mulesource.org/schema/mule/stdio/2.2"
xsi:schemalocation="
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.mulesource.org/schema/mule/stdio/2.2 http://www.mulesource.org/schema/mule/stdio/2.2/mule-stdio.xsd">
<stdio:connector name="systemstreamconnector"
promptmessage="please enter yout name: " messagedelaytime="1000"/>
<model name="hellosample">
<service name="helloumo">
<inbound>
<stdio:inbound-endpoint system="in" />
</inbound>
<component class="demo.mule.umo.impl.helloworldimpl">
<method-entry-point-resolver>
<include-entry-point method="sayhello2"/>
</method-entry-point-resolver>
</component>
<outbound>
<pass-through-router>
<stdio:outbound-endpoint system="out" />
</pass-through-router>
</outbound>
</service>
</model>
</mule>
设置方法切入点,运行,成功!