在開源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的版塊中可以找到相關代碼)。
歡迎大家交流。
開源ESB--Mule與CXF的簡單實例
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
ESB Evaluation
cissyring
2020-07-01 19:33:21
How to configure CXF HTTP Client
iteye_5081
2020-06-29 18:01:02
CXF 2.0.4 Released
CXF 2.0.4 已經正式發佈了,大家可以通過下面的地址下載.http://cwiki.apache.org/confluence/display/
iteye_5081
2020-06-29 18:01:02
CXF 2.0.5 發佈了
這個版本應該是CXF 在Apache incubator下面的最後一次發佈。 據可靠線報,CXF即將在這個月中正式宣佈畢業併成爲Apache頂級項目。
iteye_5081
2020-06-29 18:00:50
ERP與SOA相結合:基於SOA的ERP體系架構
近年來,ERP在我國已被越來越多的企業認同和接受.實施ERP已成爲企業信息化的重要標誌之一。但目前大多數企業在應用ERP系統時均面臨着以下兩方面
鸿风
2020-06-19 08:05:16
SynchroESB
光芒再现0394
2020-06-15 15:44:22
開啓ESB之路
marktowhen
2020-06-02 01:45:04
使用IBM integration toolkit開發第一個代理webservices服務
流年逝水染轻尘
2020-04-15 20:28:52
Mule ESB介紹及使用
15810356216
2020-02-28 18:40:41
什麼是ESB
shin_zhong
2020-02-25 21:25:16
ESB只是技術
shin_zhong
2020-02-25 21:24:56
理解微服務架構
Quant_Learner
2020-02-25 14:18:07
共同研究學習開源ESB框架
honnom
2020-02-24 00:12:18