?
public class DummyAjaxComponent { public DummyJsonBean process(String name) { return new DummyJsonBean(name); } }
?
?
/** * * <p>功能描述,该部分必须以中文句号结尾。<p> * * 创建日期 2013-8-19<br> * @author $Author$<br> * @version $Revision$ $Date$ * @since 3.0.0 */ public class DummyAjaxComponent2 { public String process(DummyJsonBean bean) { return "Received: " + bean; } }
?
?
?
import org.codehaus.jackson.annotate.JsonProperty; /** * * <p>功能描述,该部分必须以中文句号结尾。<p> * * 创建日期 2013-8-19<br> * @author $Author$<br> * @version $Revision$ $Date$ * @since 3.0.0 */ public class DummyJsonBean { @JsonProperty private String name; public DummyJsonBean() { } public DummyJsonBean(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String toString() { return "DummyJsonBean{" + "name='" + name + '\'' + '}'; } }
?
?
mule配置文件:
<?xml version="1.0" encoding="UTF-8"?> <mule xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ajax="http://www.mulesoft.org/schema/mule/ajax" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:test="http://www.mulesoft.org/schema/mule/test" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/test http://www.mulesoft.org/schema/mule/test/current/mule-test.xsd http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/ajax http://www.mulesoft.org/schema/mule/ajax/current/mule-ajax.xsd"> <ajax:servlet-endpoint name="ajax-endpoint1" channel="/test1"/> <ajax:servlet-endpoint name="ajax-endpoint2" channel="/test2"/> <model name="main"> <service name="clientSubscribe-test1"> <description>This service will send an instance of JsonBean to any clients listening on "/test1" channel</description> <inbound> <vm:inbound-endpoint path="in1" exchange-pattern="one-way"/> </inbound> <component class="com.easyway.esb.mule.ajax.DummyAjaxComponent"/> <outbound> <pass-through-router> <outbound-endpoint ref="ajax-endpoint1"/> </pass-through-router> </outbound> </service> <service name="clientPublish-test2"> <description>This service will receive on "/test2" channel but the request will be converted to a JsonBean instance</description> <inbound> <inbound-endpoint ref="ajax-endpoint2"> <json:json-to-object-transformer returnClass="com.easyway.esb.mule.ajax.DummyJsonBean"/> </inbound-endpoint> </inbound> <component class="com.easyway.esb.mule.ajax.DummyAjaxComponent2"/> <outbound> <pass-through-router> <vm:outbound-endpoint path="in2" exchange-pattern="one-way"/>