`
longgangbai
  • 浏览: 7250354 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

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 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:stdio="http://www.mulesoft.org/schema/mule/stdio"
       xmlns:ws="http://www.mulesoft.org/schema/mule/ws"
       xmlns:http="http://www.mulesoft.org/schema/mule/http"
       xmlns:pattern="http://www.mulesoft.org/schema/mule/pattern"
    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/ws http://www.mulesoft.org/schema/mule/ws/current/mule-ws.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/pattern http://www.mulesoft.org/schema/mule/pattern/current/mule-pattern.xsd
       http://www.mulesoft.org/schema/mule/stdio http://www.mulesoft.org/schema/mule/stdio/current/mule-stdio.xsd">



<flow name="local2remote-ws">
     <http:inbound-endpoint keep-alive="false" address="http://localhost:65000"
        encoding="UTF-8" disableTransportTransformer="false" exchange-pattern="request-response"/>
    <http:outbound-endpoint method="GET" keep-alive="false"
        address="http://webservice.webxml.com.cn#[header:INBOUND:http.request]" responseTimeout="10000" encoding="UTF-8"
        disableTransportTransformer="false" followRedirects="false" exchange-pattern="request-response" />
</flow>


  	    <pattern:web-service-proxy name="ws-proxy-pattern" inboundAddress="http://localhost:65081/services/getRegionDataset"
		    outboundAddress="http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx?op=getRegionDataset">
	   </pattern:web-service-proxy>

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

 测试:

 

public class MuleProxyMain {
    
    public static void main(String[] args)  {
        try {
            System.setProperty("java.endorsed.dirs","D:/android-workspace/MuleProxy/libs/endorsed");
            System.out.println(System.getProperty("java.endorsed.dirs"));
            String configFile = "mule-ws-conf-service.xml";
            String[] configFileArr = new String[] {configFile };
            MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
            MuleContext muleContext = muleContextFactory
                    .createMuleContext(new SpringXmlConfigurationBuilder(configFileArr));
            muleContext.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
    }
   

}

 

分享到:
评论
1 楼 gao911111 2014-02-26  
对于这种代理方式,如何实现安全认证呢?如何加入《ws-security》进行安全验证???

相关推荐

Global site tag (gtag.js) - Google Analytics