Mule学习之路_1.MuleClient调用Mule发布的服务
发布时间:2020-12-16 23:59:39 所属栏目:安全 来源:网络整理
导读:据了解Mule通过Flow发布的服务默认就是通过CXF发布的,首先创建服务和实现类 Service:HelloWorld package com.easyway.esb.mule;import javax.jws.WebService;@WebServicepublic interface HelloWorld{ String sayHi(String text);} 实现类:HelloWorldImpl
据了解Mule通过Flow发布的服务默认就是通过CXF发布的,首先创建服务和实现类
Service:HelloWorld package com.easyway.esb.mule; import javax.jws.WebService; @WebService public interface HelloWorld { String sayHi(String text); } 实现类:HelloWorldImpl package com.easyway.esb.mule; import javax.jws.WebService; @WebService(endpointInterface = "com.easyway.esb.mule.HelloWorld",serviceName = "HelloWorld") public class HelloWorldImpl implements HelloWorld { public String sayHi(String text) { return "Hello," + text; } }Flow文件 --JAXWS.xml <?xml version="1.0" encoding="UTF-8"?> <mule xmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking" xmlns:rmi="http://www.mulesoft.org/schema/mule/rmi" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:pattern="http://www.mulesoft.org/schema/mule/pattern" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:vm="http://www.mulesoft.org/schema/mule/vm" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="EE-3.4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/rmi http://www.mulesoft.org/schema/mule/rmi/current/mule-rmi.xsd http://www.mulesoft.org/schema/mule/pattern http://www.mulesoft.org/schema/mule/pattern/current/mule-pattern.xsd http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd 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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> <flow name="helloService" doc:name="helloService"> <http:inbound-endpoint exchange-pattern="request-response" address="http://localhost:9090/hello" doc:name="HTTP"/> <cxf:jaxws-service serviceClass="com.easyway.esb.mule.HelloWorldImpl" doc:name="SOAP"/> <component class="com.easyway.esb.mule.HelloWorldImpl" doc:name="Java"/> </flow> </mule> 客户端代码 import org.mule.api.FutureMessageResult; import org.mule.api.MuleContext; import org.mule.api.MuleException; import org.mule.api.MuleMessage; import org.mule.api.config.ConfigurationBuilder; import org.mule.api.config.ConfigurationException; import org.mule.api.context.MuleContextBuilder; import org.mule.api.context.MuleContextFactory; import org.mule.config.spring.SpringXmlConfigurationBuilder; import org.mule.context.DefaultMuleContextBuilder; import org.mule.context.DefaultMuleContextFactory; import org.mule.module.client.MuleClient; public class MuleClientMain { public static void main(String[] args) throws Exception{ // Create a MuleContextFactory MuleContextFactory muleContextFactory = new DefaultMuleContextFactory(); //create the configuration builder and optionally pass in one or more of these ConfigurationBuilder builder = new SpringXmlConfigurationBuilder("JAXWS.xml"); //The actual context builder to use MuleContextBuilder contextBuilder = new DefaultMuleContextBuilder(); //Create the context MuleContext context = muleContextFactory.createMuleContext(builder,contextBuilder); //Start the context context.start(); MuleClient client = new MuleClient(context); String url = "cxf:http://localhost:9090/hello?method=sayHi"; ? ? ? MuleMessage message = client.send(url,"eagle",null); ? ? ? ? String s = message.getPayloadAsString(); ? ? ? System.out.println(s); } }启动项目ruan as Mule Application
可以通过http://localhost:9090/hello可以看到SOAP信息
在输入方法名,参数,就可以得到返回值
http://localhost:9090/hello/sayHi/arg0/WuDi --syaHi为方法名,arg0为第一个参数,因为这个方法只有一个参数
如果有多个参数可以通过这个方式传 sayHi/arg0/bbb/arg1/aaa/arg3/...
WuDi为实参,
得到
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <ns2:sayHiResponse xmlns:ns2="http://mule.esb.easyway.com/"> <return>Hello,WuDi</return> </ns2:sayHiResponse> </soap:Body> </soap:Envelope>到此,实现了HelloWorld例子 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- angularjs – 在Angular Directive的链接函数中使用ng-clic
- bash – 在不同长度的字符串中交换特定位置的字符
- 第四章 Shell 流程控制
- 如何使用JSR-223在sbt控制台中获取Scala解释器?
- CustomValidator ScriptManager+webservice验证用户名是否存
- scala – 迁移到游戏! 2.5导致此错误:NoSuchMethodError:
- 在将应用程序部署为战争时,Grails是否运行Bootstrap.groovy
- WebService大讲堂之Axis2(3):使用services.xml文件发布Web
- Angular 2 / Web Api – json解析错误语法错误意外的输入结
- scala – 节流或去抖方法调用