天天看點

Mule—應用1 應用:消息轉發-WMS消息體轉發2應用:GET請求參數轉發-WMSGetFeatureInfo消息轉發3應用:地圖頁面-請求内容轉發4應用:釋出SOAP服務5應用:多個網站同域化處理

Mule—應用

[email protected]

2016年10月18日建立

1 應用:消息轉發-WMS消息體轉發

1.1 目标:轉發WMS的,将外部請求的HTTP轉發到内部HTTP。

1.2 原理:HTTP轉發。

1.3 流程:建立流程,設定入口HTTP,設定出口HTTP。

1.3.1 建立流程

1.3.2 設定入口HTTP:入口HTTP設定暴露HTTP,供外部調用。

localhost:8081/wms

1.3.3 設定出口HTTP:出口HTTP設定内部提供服務的HTTP。

注意:需要将外部請求的GET參數轉化為内部GET參數,設定PATH參數

geoserver/nurc#[message.payload]

1.3.4 運作結果

原始請求:

http://localhost:8081/wms?service=WMS&version=1.1.0&request=GetMap&layers=nurc:Arc_Sample&styles=&bbox=-183.6,-183.6,183.6,183.6&width=768&height=768&srs=EPSG:4326&format=image%2Fpng

#【message.paylaod】=

/wms?service=WMS&version=1.1.0&request=GetMap&layers=nurc:Arc_Sample&styles=&bbox=-183.6,-183.6,183.6,183.6&width=768&height=768&srs=EPSG:4326&format=image%2Fpng

2應用:GET請求參數轉發-WMSGetFeatureInfo消息轉發

2.1 目标:轉發WMS的,将外部請求的HTTP GET轉發到内部HTTP。

2.2 原理:抽取原始的HTTP請求參數,轉發到目标位址。

#[message.inboundProperties['http.query.string']]能夠擷取請求參數。

2.3 流程:建立流程,設定入口HTTP,設定出口HTTP。

2.3.1 建立流程

2.3.2 設定入口HTTP:入口HTTP設定暴露HTTP,供外部調用。

localhost:8081/geoserver/bhxq/wms

2.3.3 設定出口HTTP:出口HTTP設定内部提供服務的HTTP。

注意:需要将外部請求的GET參數轉化為内部GET參數,設定PATH參數

geoserver/bhxq/wms?#[message.inboundProperties['http.query.string']]

2.3.4 運作結果

原始請求:

http://localhost:8081/geoserver/bhxq/wms?&service=WMS&request=GetFeatureInfo&version=1.1.1&layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&styles=&format=image%2Fpng&transparent=true&width=1680&height=920&srs=EPSG%3A3857&bbox=12960509.641977917%2C4634224.150873668%2C13217338.057016108%2C4774868.282918389&query_layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&X=826&Y=333

#[message.inboundProperties['http.query.string']]值:

&service=WMS&request=GetFeatureInfo&version=1.1.1&layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&styles=&format=image%2Fpng&transparent=true&width=1680&height=920&srs=EPSG%3A3857&bbox=12960509.641977917%2C4634224.150873668%2C13217338.057016108%2C4774868.282918389&query_layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&X=826&Y=333

3應用:地圖頁面-請求内容轉發

3.1 目标:轉發相對路徑請求,将外部請求的HTTP頁面轉發到内部HTTP URL。

3.2 原理:抽取原始的HTTP請求相對位址,轉發到目标位址。

#[message.inboundProperties['http.relative.path']]可以擷取相對路徑。

3.3 流程:建立流程,設定入口HTTP,設定出口HTTP。

3.3.1 建立流程

3.3.2 設定入口HTTP:入口HTTP設定暴露HTTP,供外部調用。

localhost:8081/ksh

3.3.3 設定出口HTTP:出口HTTP設定内部提供服務的HTTP。

注意:需要将外部請求的GET參數轉化為内部GET參數,設定PATH參數

geoserver/bhxq/wms?#[message.inboundProperties['http.query.string']]

3.3.4 運作結果

原始請求:

http://localhost:8081/geoserver/bhxq/wms?&service=WMS&request=GetFeatureInfo&version=1.1.1&layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&styles=&format=image%2Fpng&transparent=true&width=1680&height=920&srs=EPSG%3A3857&bbox=12960509.641977917%2C4634224.150873668%2C13217338.057016108%2C4774868.282918389&query_layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&X=826&Y=333

#[message.inboundProperties['http.query.string']]值:

&service=WMS&request=GetFeatureInfo&version=1.1.1&layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&styles=&format=image%2Fpng&transparent=true&width=1680&height=920&srs=EPSG%3A3857&bbox=12960509.641977917%2C4634224.150873668%2C13217338.057016108%2C4774868.282918389&query_layers=bhxq%3A%E8%A1%8C%E6%94%BF%E5%9C%B0%E5%90%8D&X=826&Y=333

4應用:釋出SOAP服務

4.1 目标:釋出SOAP服務,對外提供SOAP服務。

4.2 原理:CXF釋出SOAP服務,ESB代理轉發。

Mule內建CXF釋出SOAP服務,格式遵守CXF規則。在Mule中釋出服務,內建、調試時與其它功能不友善,建議使用CXF+Tomcat釋出SOAP服務,使用HTTP POST 代理通路SOAP服務進行管理,使用Nginx同域化處理。

CXF參見:..\Java\Java-webservice-CXF.docx

Nginx同域化:..\Java\跨域WebService請求-Nginx_SOAP服務_Ajax用戶端.docx

4.3 流程:建立流程,設定入口HTTP,建立服務類,設定SOAP。

參考:http://blog.csdn.net/alanwei04/article/details/51822646

4.3.1 建立流程:入口HTTP對外暴露,ECHO顯示請求,SOAP為服務屬性,Java為服務類。

//配置xml:

<?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/corehttp://www.mulesoft.org/schema/mule/core/current/mule.xsd

http://www.mulesoft.org/schema/mule/httphttp://www.mulesoft.org/schema/mule/http/current/mule-http.xsd

http://www.mulesoft.org/schema/mule/cxfhttp://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd">

    <flowname="WebServiceDemoFlow1"doc:name="WebServiceDemoFlow1">

        <http:inbound-endpointexchange-pattern="request-response" host="localhost"port="8081" doc:name="HTTP" path="soap"/>

        <echo-componentdoc:name="Echo"/>

        <cxf:jaxws-servicedoc:name="SOAP" serviceClass="com.lee.IHelloWorld"/>

        <componentclass="com.lee.HelloWorld" doc:name="Java"/>

    </flow>

</mule>

4.3.2 設定入口HTTP:對外暴露的HTTP位址。

4.3.3 建立服務類:建立soap服務的接口和類。

由于ESB使用CXF釋出SOAP服務,服務接口和服務類需要遵守CXF要求,使用@WebSerice和@WebMethod注釋服務。

//IHelloWorld.java

package com.lee;

import javax.jws.WebMethod;

import javax.jws.WebService;

@WebService

public interface IHelloWorld{

      @WebMethod

      String say(String msg);

      @WebMethod

      String sayHello();

}

//HelloWorld.java

package com.lee;

import javax.jws.WebMethod;

import javax.jws.WebService;

@WebService

public class HelloWorldimplements IHelloWorld {

      @Override

      @WebMethod

      public String say(String msg) {

           // TODO Auto-generated method stub

           return msg+",HelloWorld!";

      }

      @Override

      @WebMethod

      public String sayHello() {

           // TODO Auto-generated method stub

           return "Hello,World!";

      }

}

4.3.4 設定SOAP:指定SOAP的服務接口,指定Java類作為SOAP的實作類。

4.3.5 運作結果:http://localhost:8081/soap/hello?wsdl

5應用:多個網站同域化處理

5.1 目标:将前端頁面,背景服務歸入同域。

5.2 原理:在同域下轉發跨域請求。

指定目标域localhost:8081,所有請求轉發到前端頁面localhost:8020;指定背景服務域位址位于localhost:8081,所有背景服務轉發到192.168.3.98。則前端頁面和背景服務都位于localhost:8081同域之中。

5.3 流程

5.3.1 前端頁面轉發:指定前端頁面為8081

指定同域localhost:8081,指向前端頁面localhost:8020,指定請求的頁面相對位址#[message.inboundProperties['http.relative.path']]

5.3.2 背景服務轉發:指定背景服務為8081

指定背景服務域位址:localhost:8081/ws/dataInterface/getAllInterface。

所有背景服務轉發實際位址:192.168.3.98/ws/dataInterface/getAllInterface?#[message.inboundProperties['http.query.string']]

5.3.3 請求:前端指向8081請求服務。

      $.ajax({

           type: "GET",

           url: “http://localhost:8081/ws/dataInterface/getAllData”,

           data: param,

           dataType: "json",

           success: setJson,

           error: Error

      });

繼續閱讀