Mule ESB 学习笔记(11)Web Service Proxy(这里是一个可以正常运行的例子)

一、WebSevice Proxy 简介


     WebService Proxy ESB中最常见的使用场景之一,即通过 ESB 直接转发 WebService Client  SOAP 请求,并将 WebServcie

Provider  SOAP 响应转发给 WebService Client ,此时的ESB就是一个WebService Proxy

 

二、WebSevice Proxy  Mule 中的产生背景
       Mule3.0 新增了一些比较有亮点的新特性 ,其中包括“ pattern-based configuration ”这个概念。 pattern-based configuration

的主要目是将常用的功能模式化,达到简化配置文件的目的,主要包括四种模式: Simple Service  Web Service Proxy  Bridge 

Validator Web Service Proxy Pattern 正是本文中提到的 WebService Proxy 这里有关于它的更多介绍。

三、Web Service Proxy 实现

1WSProxy 的实现机制


WSProxy 实现机制的组件图如下所示
MuleWSProxy  3 个组件组成:
(1) MessageSource
    
它通过 MessageLister 接收或者产生 MuleMessage ,本实例中采用 DefaultInboundEndpoint 作为MessageSource ,并通过

socket 接收 SOAP消息。这里有关于 MessageSource 的介绍。
(2) AbstractProxyRequestProcessor
    
负责处理MuleEvent,重写WSDL地址。其实现类有两个,分别是: StaticWsdlProxyRequestProcessor 

DynamicWsdlProxyRequestProcessor ,本实例中采用的是 DynamicWsdlProxyRequestProcessor 
(3) OutboundEndpoint
    
负责分发和接收SOAP消息。

2WSProxy 运行期数据流图

     
运行期数据流图如下所示

运行期数据流:
(1) DefaultInboundEndpoint 中, HttpServerConnection 负责在 http://localhost:8080 上接收 SOAP 请求,

MessageProcessorChain 是一系列的 MessageProcessor ,对 MuleEvent 进行处理,主要包括:

ExceptionHandlingMessageProcessor  InboundEndpointMimeTypeCheckingMessageProcessor 

InboundEndpointPropertyMessageProcessor  InboundLoggingMessageProcessor MessageProcessor 
(2) MessageProcessorChain 中,通过 DynamicWsdlProxyRequestProcessor 重写 WSDL 访问地址,即将 proxy WSDL 地址重新为

remote WSDL 地址。
(3) DefaultOutboundEndpoint 中,主要通过 HttpClientMessageDispatcher 调用 HttpClient 发送和接收SOAP 消息。

Web Service Proxy

    Web Service Proxy用来将客户端的WS请求直接转发至相应的远程WS服务端处理,并返回处理结果。Mule本身不做任何处理。

2.1 配置方式1

  • 示例配置

<flow name="local2remote-ws">

    <http:inbound-endpoint keep-alive="false" address="http://localhost:65000"

        encoding="UTF-8" disableTransportTransformer="false" exchange-pattern="request-response" doc:name="HTTP"

        doc:description="" />

    <http:outbound-endpoint method="GET" keep-alive="false"

        address="http://localhost:5050#[header:INBOUND:http.request]" responseTimeout="10000" encoding="UTF-8"

        disableTransportTransformer="false" followRedirects="false" exchange-pattern="request-response"

        doc:name="HTTP" doc:description="" />

</ flow >

  

  • 说明
  • 注意 outbound-endpoint  address 参数中的表达式。
  • 测试方法
  • 浏览器中通过“ http://localhost:65000/webservice/EchoService?wsdl ”(将内容复制,保存为 *.wsdl ),然后使用 SoapUI 测试。
  • 2.2 配置方式2
  • 示例配置
  • <pattern:web-service-proxy name="ws-proxy" inboundAddress=http://localhost:65082/services/Echo2
  • outboundAddress="http://localhost:65082/services/Echo1?method=echo">

</pattern:web-service-proxy>

 

 

 

 

 

 

 

  • 说明

 

Mule 为这种常见的场景提供了现成的模式,以简化配置。

 

 

 

 

  • 测试方法

 

通过“ http://localhost:65082/services/Echo2?wsdl ”获取 wsdl 文件,然后使用 SoapUI 测试。2.3 配置方式3

 <ws:proxy name="mule-Ws-Proxy" inboundAddress="http://localhost:8080/services/WeatherWS
               outboundAddress="
http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx"/>

 

 

 

 

 

 

 

说明

 

 

Mule 为这种常见的场景提供了现成的模式,以简化配置。

 

 

 

 

  • 测试方法

 

通过“ http://localhost:8080/services/WeatherWS?wsdl ”获取 wsdl 文件,然后使用 SoapUI 测试。  完整的mule配置文件:

 

Xml代码    收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <mule xmlns="http://www.mulesoft.org/schema/mule/core"  
  3.        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.        xmlns:spring="http://www.springframework.org/schema/beans"  
  5.        xmlns:stdio="http://www.mulesoft.org/schema/mule/stdio"  
  6.        xmlns:ws="http://www.mulesoft.org/schema/mule/ws"  
  7.        xmlns:http="http://www.mulesoft.org/schema/mule/http"  
  8.        xmlns:pattern="http://www.mulesoft.org/schema/mule/pattern"  
  9.     xsi:schemaLocation="  
  10.        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd  
  11.        http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd  
  12.        http://www.mulesoft.org/schema/mule/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.xsd  
  13.        http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd  
  14.        http://www.mulesoft.org/schema/mule/pattern http://www.mulesoft.org/schema/mule/pattern/current/mule-pattern.xsd  
  15.        http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/current/mule-stdio.xsd">  
  16.   
  17.   
  18. <!-- 
  19. <flow name="local2remote-ws">  
  20.      <http:inbound-endpoint keep-alive="false" address="http://localhost:65000"  
  21.         encoding="UTF-8" disableTransportTransformer="false" exchange-pattern="request-response"/>  
  22.     <http:outbound-endpoint method="GET" keep-alive="false"  
  23.         address="http://webservice.webxml.com.cn#[header:INBOUND:http.request]" responseTimeout="10000" encoding="UTF-8"  
  24.         disableTransportTransformer="false" followRedirects="false" exchange-pattern="request-response" />  
  25. </flow>
  26. -->
  27. <flow name="local2remote-ws">
      <http:inbound-endpoint keep-alive="false"
       address="http://localhost:8088/MSPGS/MPService" encoding="UTF-8"
       disableTransportTransformer="false" exchange-pattern="request-response" />
      <http:outbound-endpoint method="GET"
       keep-alive="false"
       address="http://10.10.31.25/MSPGWebPub/MSPGS/MPService.svc"
       responseTimeout="10000" encoding="UTF-8" disableTransportTransformer="false"
       followRedirects="false" exchange-pattern="request-response" />
     </flow>  
  28.   
  29.   
  30.  <pattern:web-service-proxy name="ws-proxy-pattern" inboundAddress="http://localhost:65081/services/getRegionDataset"  
  31.             outboundAddress="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?op=getRegionDataset">  
  32.  </pattern:web-service-proxy>  
  33.   
  34.  <ws:proxy name="mule-Ws-Proxy" inboundAddress="http://localhost:8080/services/WeatherWS"   
  35.                outboundAddress="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx"/>  
  36. </mule>  

 测试:

Java代码    收藏代码
  1. public class MuleProxyMain {  
  2.       
  3.     public static void main(String[] args)  {  
  4.         try {  
  5.             System.setProperty("java.endorsed.dirs","D:/android-workspace/MuleProxy/libs/endorsed");  
  6.             System.out.println(System.getProperty("java.endorsed.dirs"));  
  7.             String configFile = "mule-ws-conf-service.xml";  
  8.             String[] configFileArr = new String[] {configFile };  
  9.             MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();  
  10.             MuleContext muleContext = muleContextFactory  
  11.                     .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr));  
  12.             muleContext.start();  
  13.         } catch (Exception e) {  
  14.             e.printStackTrace();  
  15.         }  
  16.       
  17.     }  
  18.      
  19.   
  20. }  

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值