在开源ESB中最活跃的就是Mule和ServiceMix了。为了便于大家更好的了解Mule和CXF,在此我通过一个实例来说明如何在Mule中使用CXF。
1.相关类
public class Product implements Serializable {
private String id;
private String description;
private int width;
private int height;
public Product() {
}
public Product(String id, String description, int width, int height) {
this.id = id;
this.description = description;
this.width = width;
this.height = height;
}
//相关的set,get方法。省略
}
@WebService
public interface ProductCatalogService {
@WebResult(name="item")
public List<String> listProducts();
@WebResult(name="product")
public Product getProductDetail(@WebParam(name="productId") String productId);
}
@WebService(endpointInterface = "com.honno.demo.product.ProductCatalogService",
serviceName = "ProductCatalogService")
public class ProductCatalogServiceImpl implements ProductCatalogService {
Map<String, Product> productMap = new HashMap<String, Product>();
public ProductCatalogServiceImpl() {
// Load some products
Product product = new Product("product1", "Square Widget", 10, 10);
productMap.put(product.getId(), product);
product = new Product("product2", "Round Widget", 5, 5);
productMap.put(product.getId(), product);
}
public List<String> listProducts() {
List<String> productListing = new ArrayList<String>();
Collection<Product> products = productMap.values();
for (Product p : products) {
productListing.add(p.getId() + " - " + p.getDescription());
}
return productListing;
}
public Product getProductDetail(String productId) {
Product product = null;
product = productMap.get(productId);
return product;
}
2.mule的配置文件
<spring:beans>
<spring:import resource="catalogContext.xml"/>
</spring:beans>
<model name="services">
<service name="ProductCatalogService">
<inbound>
<cxf:inbound-endpoint address="http://localhost:65082/services/ProductCatalogService" />
</inbound>
<component>
<spring-object bean="productCatalogService" />
</component>
</service>
</model>
3.生成wsdl文件
Mule成功启动后,在ie的地址栏中通过http://localhost:65082/services/ProductCatalogService?wsdl即可查看wsdl文件。
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://product.demo.honno.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ProductCatalogService" targetNamespace="http://product.demo.honno.com/">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://product.demo.honno.com/" attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://product.demo.honno.com/">
<xs:complexType name="product">
<xs:sequence>
<xs:element minOccurs="0" name="description" type="xs:string"/>
<xs:element name="height" type="xs:int"/>
<xs:element minOccurs="0" name="id" type="xs:string"/>
<xs:element name="width" type="xs:int"/>
</xs:sequence>
</xs:complexType>
<xs:element name="listProducts" type="listProducts"/>
<xs:complexType name="listProducts">
<xs:sequence/>
</xs:complexType>
<xs:element name="listProductsResponse" type="listProductsResponse"/>
<xs:complexType name="listProductsResponse">
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="item" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="getProductDetail" type="getProductDetail"/>
<xs:complexType name="getProductDetail">
<xs:sequence>
<xs:element minOccurs="0" name="productId" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:element name="getProductDetailResponse" type="getProductDetailResponse"/>
<xs:complexType name="getProductDetailResponse">
<xs:sequence>
<xs:element minOccurs="0" name="product" type="product"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="getProductDetailResponse">
<wsdl:part element="tns:getProductDetailResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="listProductsResponse">
<wsdl:part element="tns:listProductsResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="listProducts">
<wsdl:part element="tns:listProducts" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="getProductDetail">
<wsdl:part element="tns:getProductDetail" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="ProductCatalogService">
<wsdl:operation name="listProducts">
<wsdl:input message="tns:listProducts" name="listProducts">
</wsdl:input>
<wsdl:output message="tns:listProductsResponse" name="listProductsResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getProductDetail">
<wsdl:input message="tns:getProductDetail" name="getProductDetail">
</wsdl:input>
<wsdl:output message="tns:getProductDetailResponse" name="getProductDetailResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProductCatalogServiceSoapBinding" type="tns:ProductCatalogService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="listProducts">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="listProducts">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="listProductsResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getProductDetail">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="getProductDetail">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getProductDetailResponse">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProductCatalogService">
<wsdl:port binding="tns:ProductCatalogServiceSoapBinding" name="ProductCatalogServiceImplPort">
<soap:address location="http://localhost:65082/services/ProductCatalogService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
4.生成客户端
通过wsdl我们就可以生成客户端代码,对webservice进行调用了。
更多内容,包括更加详细的源代码,见[url] http://www.opensourceforce.org/?fromuid=217 [/url] (Mule的版块中可以找到相关代码)。
欢迎大家交流。
分享到:
- 2008-07-08 09:09
- 浏览 4035
- 评论(1)
- 论坛回复 / 浏览 (1 / 3142)
- 查看更多
相关推荐
来自与网络的学习信息,包含总体功能说明原理到项目的部署开发过程,以及与SPRING的整合使用,将SOA真实的应用到我们的项目中
收集了一些esb的资料,包括mule,servicemix等开源esb的使用等。
Mule ESB 项目在Linux中的部署与开发与应用案例
文档主要介绍了Mule ESB的使用方法,并结合具体实例加深对ESB的理解,对新手很有帮助哦!
MULE ESB-4.1企业版运行环境,将AnyPoint Studio开发的项目方到apps目录下即可,注意项目的运行环境需与该环境一致
开源ESB框架 Mule 2增加了基于Schema的spring xml配置,用于集成传统的web应用。表达式赋值被内建在运行时的消息传递中,因此头信息,Xquery或是其他的测试可以很容易的完成,不需要新建POJO或是这些活动转换器。
ESB解决方案-mule分享.docxESB解决方案-mule分享.docxESB解决方案-mule分享.docxESB解决方案-mule分享.docxESB解决方案-mule分享.docxESB解决方案-mule分享.docxESB解决方案-mule分享.docxESB解决方案-mule分享.docx
官网下载,Eclipse插件:WSO2 ESB tooling,适配WSO2 ESB 5.0.0。 仅 Eclipse Mars.2 Release (4.5.2) 版本可使用(我用的是Eclipse JEE Mare.2)。 如果需要Eclipse汉化,必须先安装 WSO2 ESB tooling,再安装...
企业服务总线ESB-解决方案与应用实例 ESB实施指南
MULE ESB-4.1社区办运行环境,将AnyPoint Studio开发的项目方到APPS目录下即可
这次演练的目的是向您介绍Mule Studio(基于eclipse的集成开发工具),并帮助您轻松地创建自己的应用。 本教程本教程将引导您如何使用 Mu
MuleEsb开源框架简介.pdf
资料是copy而来,如果侵权,请通知,不是故意冒犯,只是把好的资料共享给大家
mule -esb 源码
wso2esb-4.0.0.zip wso2esb-4.0.0.zip
MINT BASIC PROGRAMMING 英文版
ESB-ServiceMix的消息路由技术研究,罗晶,,本文沿着SOA-ESB-JBI-NMR-ServiceMix这个线路,探究SOA、ESB和JBI规范,以及这几者之间的联系。通过对遵循JBI规范的开源ESB—ServiceMix深入�
由.net开源ESB框架NServiceBus开发的Demo
ESB 节点驱动程序ESB nodejs 驱动程序 - 正在大量开发中安装您需要安装 zeromq 4 和 google protobuf。 然后: npm install esb-node-driver您将需要一个 redis 服务器,将他的 ip 作为域esb-redis放入 /etc/hosts ...