Mule3.4.0 和Servlet整合
<?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:spring="http://www.springframework.org/schema/beans" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd"> <model name="REST Functional TestCase"> <service name="RESTServiceWrapper1"> <inbound> <inbound-endpoint address="vm://in1" exchange-pattern="request-response"/> </inbound> <http:rest-service-component serviceUrl="http://www.webservicex.net/stockquote.asmx/GetQuote" httpMethod="POST"> <http:payloadParameterName value="symbol"/> </http:rest-service-component> </service> <service name="RESTServiceWrapper2"> <inbound> <inbound-endpoint address="vm://in2" exchange-pattern="request-response"/> </inbound> <http:rest-service-component serviceUrl="http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate" httpMethod="POST"> <http:payloadParameterName value="FromCurrency"/> <http:payloadParameterName value="ToCurrency"/> </http:rest-service-component> </service> <service name="RESTServiceWrapper3"> <inbound> <inbound-endpoint address="vm://in3" exchange-pattern="request-response"/> </inbound> <http:rest-service-component serviceUrl="http://www.webservicex.net/stockquote.asmx/GetQuote" httpMethod="GET"> <http:payloadParameterName value="symbol"/> </http:rest-service-component> </service> <service name="RESTServiceWrapper4"> <inbound> <inbound-endpoint address="vm://in4" exchange-pattern="request-response"/> </inbound> <http:rest-service-component serviceUrl="http://www.webservicex.net/CurrencyConvertor.asmx/ConversionRate" httpMethod="GET"> <http:payloadParameterName value="FromCurrency"/> <http:payloadParameterName value="ToCurrency"/> </http:rest-service-component> </service> </model></mule>
?
?
import org.mule.DefaultMuleMessage;import org.mule.api.MuleContext;import org.mule.api.MuleMessage;import org.mule.api.client.LocalMuleClient;import org.mule.api.config.ConfigurationException;import org.mule.api.context.MuleContextFactory;import org.mule.api.lifecycle.InitialisationException;import org.mule.config.spring.SpringXmlConfigurationBuilder;import org.mule.context.DefaultMuleContextFactory;/** * <p>功能描述,该部分必须以中文句号结尾。<p> * * 创建日期 2013-8-17<br> * @author $Author$<br> * @version $Revision$ $Date$ * @since 3.0.0 */public class MuleServletMain { public static void main(String[] args) { try {// System.setProperty("java.endorsed.dirs","D:/android-workspace/MuleAxis/libs/endorsed"); String configFile = "mule-config.xml"; String[] configFileArr = new String[] {configFile }; MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); MuleContext context = muleContextFactory .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr)); context.start(); LocalMuleClient client = context.getClient(); MuleMessage reply = client.send("vm://in1", new DefaultMuleMessage("IBM", context)); System.out.println("response ="+reply.getPayloadAsString()); reply = client.send("vm://in2", new DefaultMuleMessage(new Object[]{"ARS","ARS"}, context)); System.out.println("response ="+reply.getPayloadAsString()); reply = client.send("vm://in3", new DefaultMuleMessage(new Object[]{"IBM"}, context)); System.out.println("response ="+reply.getPayloadAsString()); reply = client.send("vm://in4", new DefaultMuleMessage(new Object[]{"ARS","ARS"}, context)); System.out.println("response ="+reply.getPayloadAsString()); } catch (Exception e) { e.printStackTrace(); } }}
?