Mule—应用
2016-10-18 22:10
225 查看
Mule—应用
sf2gis@163.com
2016年10月18日创建
geoserver/nurc#[message.payload]
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
geoserver/bhxq/wms?#[message.inboundProperties['http.query.string']]
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
geoserver/bhxq/wms?#[message.inboundProperties['http.query.string']]
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
CXF参见:..\Java\Java-webservice-CXF.docx
Nginx同域化:..\Java\跨域WebService请求-Nginx_SOAP服务_Ajax客户端.docx
<?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>
//IHelloWorld.java
package com.lee;
import javax.jws.WebMethod;
import javax.jws.WebService;
/**
* @author sf2gis@163.com
*
*/
@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;
/**
* @author sf2gis@163.com
*
*/
@WebService
public class HelloWorldimplements IHelloWorld {
/* (non-Javadoc)
* @seecom.lee.IHelloWorld#say(java.lang.String)
*/
@Override
@WebMethod
public String say(String msg) {
// TODO Auto-generated method stub
return msg+",HelloWorld!";
}
/* (non-Javadoc)
* @seecom.lee.IHelloWorld#sayHello()
*/
@Override
@WebMethod
public String sayHello() {
// TODO Auto-generated method stub
return "Hello,World!";
}
}
所有后台服务转发实际地址:192.168.3.98/ws/dataInterface/getAllInterface?#[message.inboundProperties['http.query.string']]
type: "GET",
url: “http://localhost:8081/ws/dataInterface/getAllData”,
data: param,
dataType: "json",
success: setJson,
error: Error
});
sf2gis@163.com
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/wms1.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/wms2.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/ksh3.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/518226464.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;
/**
* @author sf2gis@163.com
*
*/
@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;
/**
* @author sf2gis@163.com
*
*/
@WebService
public class HelloWorldimplements IHelloWorld {
/* (non-Javadoc)
* @seecom.lee.IHelloWorld#say(java.lang.String)
*/
@Override
@WebMethod
public String say(String msg) {
// TODO Auto-generated method stub
return msg+",HelloWorld!";
}
/* (non-Javadoc)
* @seecom.lee.IHelloWorld#sayHello()
*/
@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
});
相关文章推荐
- 探秘ajax跨域请求
- 基于iframe实现ajax跨域请求 获取网页中ajax数据
- jquery ajax结合thinkphp的getjson实现跨域的方法
- jquery+thinkphp实现跨域抓取数据的方法
- PHP如何实现跨域
- JavaScript cookie 跨域访问之广告推广
- ie7下利用ajax跨域盗取cookie的解决办法
- javascript跨域的方法汇总
- 在Ajax中使用Flash实现跨域数据读取的实现方法
- AJAX实现跨域的三种方法(代理,JSONP,XHR2)
- js实现跨域访问的三种方法
- 如何设置iframe高度自适应在跨域情况下的可用方法
- 使用script的src实现跨域和类似ajax效果
- sso跨域写cookie的一段js脚本(推荐)
- js跨域问题之跨域iframe自适应大小实现代码
- JavaScript两种跨域技术全面介绍
- 深入浅析Jsonp解决ajax跨域问题
- 浅析JSONP解决Ajax跨域访问问题的思路详解
- ajax跨域(基础域名相同)表单提交的方法
- JS不能跨域借助jquery获取IP地址的方法