这是嵌入在Mule中的RESTful接口,它接受用户名并输出“hello,$ name”
以下是mule-config.xml
中内容的一部分 <model name="greetingModel">
<service name="greetingService">
<inbound>
<inbound-endpoint address="http://localhost:9004"/>
</inbound>
<outbound>
<filtering-router>
<outbound-endpoint address="vm://greeting"/>
<restlet:uri-template-filter pattern="/hello/{set-payload.name}" verbs="GET"/>
</filtering-router>
</outbound>
</service>
<service name="greeting">
<inbound>
<inbound-endpoint address="vm://greeting" exchange-pattern="request-response"></inbound-endpoint>
</inbound>
<component class="com.ggd543.mulerestletdemo.GreetingComponent"></component>
</service>
</model>
和组件类
package com.ggd543.mulerestletdemo
import org.mule.api.lifecycle.Callable
import org.mule.api.MuleEventContext
class GreetingComponent extends Callable {
def onCall(eventContext: MuleEventContext) = {
val name = eventContext.getMessage.getPayload.asInstanceOf[String]
sayHello(name)
}
def sayHello(name: String) = {
val msg = "hello, "+name
println(msg)
msg
}
}
成功部署应用后,我尝试在浏览器中访问http://localhost:9004/hello/archer,但没有任何反复发生。
mule-config.xml
是否有任何问题?
PS:我的骡子版本是3.1.2而我使用的是mule-transport-restlet-1.1.3.jar
答案 0 :(得分:1)
问题是由于VM端点上的交换模式不一致。尝试:
<model name="greetingModel">
<service name="greetingService">
<inbound>
<inbound-endpoint address="http://localhost:9004"/>
</inbound>
<outbound>
<filtering-router>
<outbound-endpoint address="vm://greeting" exchange-pattern="request-response"/>
<restlet:uri-template-filter pattern="/hello/{set-payload.name}" verbs="GET"/>
</filtering-router>
</outbound>
</service>
<service name="greeting">
<inbound>
<inbound-endpoint address="vm://greeting" exchange-pattern="request-response"/>
</inbound>
<component class="com.ggd543.mulerestletdemo.GreetingComponent" />
</service>
</model>