webService代理
Web Service Proxy用来将客户端的WS请求直接转发至相应的远程WS服务端处理,并返回处理结果。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:pattern="http://www.mulesoft.org/schema/mule/pattern" xsi:schemaLocation=" http://www.mulesoft.org/schema/mule/pattern http://www.mulesoft.org/schema/mule/pattern/3.1/mule-pattern.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/3.1/mule.xsd"> <pattern:web-service-proxy name="WSProxyService" inboundAddress=http://localhost:9000/ws/ outboundAddress="http://localhost:8080/TestWs/services/Testws?wsdl"/> </mule>
inboundAddress=http://localhost:9000/ws/如果写为inboundAddress=http://localhost:9000/ws
使用http://localhost:9000/ws +任何字符都能访问。。
发布webService
<?xmlversion="1.0"encoding="UTF-8"?> <mulexmlns:tracking="http://www.mulesoft.org/schema/mule/ee/tracking"xmlns:http="http://www.mulesoft.org/schema/mule/http"xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"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.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.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/ee/tracking http://www.mulesoft.org/schema/mule/ee/tracking/current/mule-tracking-ee.xsd"> <flowname="MyServiceFlow1"doc:name="MyServiceFlow1"> <http:inbound-endpointexchange-pattern="request-response"address="http://localhost:10020/ser"doc:name="HTTP"/> <cxf:jaxws-serviceserviceClass="cn.service.User"doc:name="SOAP"/> <componentdoc:name="Java"> <singleton-objectclass="cn.service.User"/> </component> </flow> </mule>
调用webService
<?xmlversion="1.0"encoding="UTF-8"?> <mulexmlns:http="http://www.mulesoft.org/schema/mule/http"xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"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.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"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/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd"> <flowname="MyTestFlow1"doc:name="MyTestFlow1"> <http:inbound-endpoint exchange-pattern="request-response" doc:name="HTTP"address="http://localhost:10010/ser"/> <cxf:jaxws-clientoperation="getHello"serviceClass="cn.cq.test.Testws" doc:name="SOAP"/> <custom-transformerclass="cn.bean.UserBean"doc:name="Java"> <spring:propertyname="name"value="11"/> </custom-transformer> <http:outbound-endpointexchange-pattern="request-response"method="POST"address="http://localhost:8080/TestWs/services/Testws"doc:name="HTTP"/> <loggermessage="log!"level="INFO"doc:name="Logger"/> </flow> </mule>
记录log
publicclassMyLogextendsLogComponent { @Override publicObject onCall(MuleEventContext eventContext)throwsException { System.out.println("----------log--------------"); System.out.println("eventContext.getEndpointURI():"+eventContext.getEndpointURI()); System.out.println(eventContext.getMessageAsString()); returnnull; } }
获取客户端ip
publicclassMyTransformerextendsAbstractMessageTransformer { @Override publicObject transformMessage(MuleMessage m, String outputEncoding) throwsTransformerException { System.out.println("transformMessage.............."); Set<String> s= m.getInboundPropertyNames(); for(String ss:s){ System.out.println(ss+" "+m.getInboundProperty(ss)); } System.out.println("----------transform end------------"); returnnull; } }
通过webservice保存文件
<?xmlversion="1.0"encoding="UTF-8"?> <mulexmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"xmlns:http="http://www.mulesoft.org/schema/mule/http"xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"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.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.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/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd"> <flowname="myTestServiceFlow1"doc:name="myTestServiceFlow1"> <http:inbound-endpointexchange-pattern="request-response"address="http://localhost:9527/mytestservice"doc:name="HTTP"/> <cxf:jaxws-servicedoc:name="SOAP"serviceClass="cn.mymule.myservice.MyService"/> <componentdoc:name="Java"> <singleton-objectclass="cn.mymule.myservice.MyService"/> </component> <byte-array-to-string-transformer doc:name="Transform-to-String"/> <file:outbound-endpointpath="D:\" outputPattern="ShippingOrder-#[function:datestamp].txt"doc:name="LegacyFulfillment"responseTimeout="10000"/> </flow> </mule>
包装返回bean
接口方法返回值定义为Object,使用DataMapper将实现类返回bean映射为用户所需数据的bean返回
<?xmlversion="1.0"encoding="UTF-8"?> <mulexmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:data-mapper="http://www.mulesoft.org/schema/mule/ee/data-mapper"xmlns:http="http://www.mulesoft.org/schema/mule/http"xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf"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.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.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/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd http://www.mulesoft.org/schema/mule/ee/data-mapper http://www.mulesoft.org/schema/mule/ee/data-mapper/current/mule-data-mapper.xsd"> <data-mapper:configname="new_mapping_grf"transformationGraphPath="new_mapping.grf"doc:name="new_mapping_grf"/> <flowname="myTestServiceFlow1"doc:name="myTestServiceFlow1"> <http:inbound-endpointexchange-pattern="request-response"address="http://localhost:9527/mytestservice"doc:name="HTTP"/> <cxf:jaxws-servicedoc:name="SOAP"serviceClass="cn.mymule.myservice.MyService"/> <componentdoc:name="Java"> <singleton-objectclass="cn.mymule.myservice.MyService"/> </component> <data-mapper:transformconfig-ref="new_mapping_grf"doc:name="DataMapper"/> </flow> </mule>
主要通过官网、网上各种教程和http://my.oschina.net/moon/blog/40125这个blog学习的