基于soap over jms 的WebSphere MQ与AXIS2实现

开发环境需求:
JDK 5.0
本文档中使用的所有工具都是运行在JDK 5.0的基础之上的。
ObjectWeb Lomboz for JavaEE Development 3.3
ObjectWeb Lomboz 3.3是构建在Eclipse Europa 3.3基础之上的,该平台中包含了大量的Java EE开发的plugins,可以帮助开发人员快速构建应用程序。
Apache Tomcat 5.5
本文档将使用 Apache Tomcat 作为 AXIS2 SOAP Engine 的 servlet 容器。下载核心 ZIP 文件。本教程将使用 Apache Tomcat 5.5.17
Axis2
Axis2是Apache开发的SOAP引擎,该文档中用于部署Service
Axis2 Code Generator和Axis2 Service Archiver插件
这是Axis2提供的Eclipse插件,用于产生服务代码和打包aar服务部署文件文件,如果使用ObjectWeb Lomboz 3.3则不需要再次安装。
soapUI
soapUI是一个Web Service测试工具,本文档使用此工具实现对Web Service的测试。使用的版本是soapUI 2.0.2
WebSphere MQ6.0 WebSphere的消息中间件。
安装:自己摸索,主要说下AXIS2的安装:
本文采用的版本1.4,具体为文件为axis2-1.4-bin.zip和 axis2-1.4-war.zip
AXIS2 SOAP Engine启动有2中方式:
1. Standard Alone方式,其中axis2-1.4-bin.zip为AXIS2 Standard Alone版本,解压缩后即可直接运行;
注意: 本文需要在安装完成后,设置系统变量%AXIS2_HOME%,为解压缩根目录,例如:D:\axis2-1.4, 并且要将%AXIS2_HOME%\bin加入到系统变量%PATH%中;
[b]创建服务实现类方式:[/b]
WSDL First方式创建服务实现类
1.打开Eclipse:新建工程 名字:SOATrainingIBS
2.在工程根目录下新建一个文件夹名字(wsdl)
3.右键目录wsdl,新建Schema文件:EditShoppingCartXMLSchema.xsd
内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="abstraction/composite/business.shoppingbook.EditShoppingCartService/XMLSchema"
xmlns:tns="abstraction/composite/business.shoppingbook.EditShoppingCartService/XMLSchema"
elementFormDefault="qualified">
<complexType name="ItemType">
<sequence>
<element name="bookId" type="string" minOccurs="1" maxOccurs="1">
</element>
<element name="bookName" type="string" minOccurs="0"
maxOccurs="1">
</element>
<element name="bookPrice" type="double" minOccurs="1"
maxOccurs="1">
</element>
<element name="MyPrice" type="double" minOccurs="1"
maxOccurs="1">
</element>
<element name="amount" type="int" minOccurs="1" maxOccurs="1">
</element>
<element name="subTotal" type="double" minOccurs="1"
maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="ItemListType">
<sequence>
<element name="item" type="tns:ItemType" minOccurs="0"
maxOccurs="unbounded">
</element>
</sequence>
</complexType>
<complexType name="CustomerType">
<sequence>
<element name="customerId" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="customerName" type="string" minOccurs="0"
maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="ShoppingCartType">
<sequence>
<element name="customer" type="tns:CustomerType" minOccurs="1"
maxOccurs="1">
</element>
<element name="itemList" type="tns:ItemListType" minOccurs="0"
maxOccurs="1">
</element>
<element name="realTotal" type="double" minOccurs="1"
maxOccurs="1">
</element>
<element name="originalTotal" type="double" minOccurs="1"
maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="BasicFaultType">
<sequence>
<element name="errorCode" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="errorMessage" type="string" minOccurs="1"
maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="BasicResponseCodeType">
<sequence>
<element name="resCode" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="resMessage" type="string"></element>
</sequence>
</complexType>
<complexType name="BasicResponseBooleanType">
<sequence>
<element name="result" type="boolean" minOccurs="1"
maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="BookType">
<sequence>
<element name="id" type="string" minOccurs="1" maxOccurs="1">
</element>
<element name="name" type="string" minOccurs="0" maxOccurs="1">
</element>
<element name="price" type="double" minOccurs="1" maxOccurs="1">
</element>
<element name="category" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="author" type="string" minOccurs="1" maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="BookListType">
<sequence>
<element name="book" type="tns:BookType" minOccurs="0"
maxOccurs="unbounded">
</element>
</sequence>
</complexType>
<complexType name="RemoveItemRequestType">
<sequence>
<element name="customerId" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="itemBookId" type="string" minOccurs="1"
maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="ModifyItemAmountRequestType">
<sequence>
<element name="customerId" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="itemBookId" type="string" minOccurs="1"
maxOccurs="1">
</element>
<element name="itemAmount" type="int" minOccurs="1"
maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="BookIdRequestType">
<sequence>
<element name="bookId" type="string" minOccurs="1" maxOccurs="1">
</element>
</sequence>
</complexType>
<complexType name="BookIdListRequestType">
<sequence>
<element name="bookId" type="tns:BookIdRequestType"
minOccurs="0" maxOccurs="unbounded">
</element>
</sequence>
</complexType>
</schema>

同目录下新建 EditShoppingCartService.wsdl
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="abstraction/composite/business.shoppingbook.EditShoppingCartService"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="EditShoppingCartService"
targetNamespace="abstraction/composite/business.shoppingbook.EditShoppingCartService">
<wsdl:types>
<xsd:schema
targetNamespace="abstraction/composite/business.shoppingbook.EditShoppingCartService"
xmlns:Q1="abstraction/composite/business.shoppingbook.EditShoppingCartService/XMLSchema">
<xsd:import schemaLocation="EditShoppingCartXMLSchema.xsd"
namespace="abstraction/composite/business.shoppingbook.EditShoppingCartService/XMLSchema">
</xsd:import>
<xsd:element name="queryShoppingCartByCustomer" type="Q1:CustomerType">
</xsd:element>
<xsd:element name="queryShoppingCartByCustomerResponse"
type="Q1:ShoppingCartType">
</xsd:element>
<xsd:element name="queryShoppingCartByCustomer_fault"
type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="clearShoppingCartByCustomer" type="Q1:CustomerType">
</xsd:element>
<xsd:element name="clearShoppingCartByCustomerResponse"
type="Q1:BasicResponseCodeType">
</xsd:element>
<xsd:element name="clearShoppingCartByCustomer_fault"
type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="removeBookItem" type="Q1:RemoveItemRequestType">
</xsd:element>
<xsd:element name="removeBookItemResponse" type="Q1:ShoppingCartType">
</xsd:element>
<xsd:element name="removeShoppingCartBookItem_fault"
type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="removeBookItem_fault" type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="modifyBookItemAmount" type="Q1:ModifyItemAmountRequestType">
</xsd:element>
<xsd:element name="modifyBookItemAmountResponse" type="Q1:ShoppingCartType">
</xsd:element>
<xsd:element name="modifyBookItemAmount_fault" type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="addBookItemToWishList" type="Q1:BookIdRequestType">
</xsd:element>
<xsd:element name="addBookItemToWishListResponse" type="Q1:BasicResponseBooleanType">
</xsd:element>
<xsd:element name="addBookItemToWishList_fault" type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="addAllBookItemToWishList" type="Q1:BookIdListRequestType">
</xsd:element>
<xsd:element name="addAllBookItemToWishListResponse"
type="Q1:BasicResponseBooleanType">
</xsd:element>
<xsd:element name="addAllBookItemToWishList_fault" type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsCategory"
type="Q1:BookIdListRequestType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsCategoryResponse"
type="Q1:BookListType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsCategory_fault"
type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsBookAuthor"
type="Q1:BookIdListRequestType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsBookAuthorResponse"
type="Q1:BookListType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsBookAuthor_fault"
type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsBuyerHistory"
type="Q1:BookIdListRequestType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsBuyerHistoryResponse"
type="Q1:BookListType">
</xsd:element>
<xsd:element name="queryRelatedBooksByItemsBuyerHistory_fault"
type="Q1:BasicFaultType">
</xsd:element>
<xsd:element name="checkUserIfLogin" type="Q1:CustomerType">
</xsd:element>
<xsd:element name="checkUserIfLoginResponse" type="Q1:BasicResponseBooleanType">
</xsd:element>
<xsd:element name="checkUserIfLogin_fault" type="Q1:BasicFaultType">
</xsd:element>
</xsd:schema>
</wsdl:types>
<wsdl:message name="queryShoppingCartByCustomerRequest">
<wsdl:part element="tns:queryShoppingCartByCustomer" name="queryShoppingCartByCustomerRequest" />
</wsdl:message>
<wsdl:message name="queryShoppingCartByCustomerResponse">
<wsdl:part element="tns:queryShoppingCartByCustomerResponse"
name="queryShoppingCartByCustomerResponse" />
</wsdl:message>
<wsdl:message name="queryShoppingCartByCustomer_faultMsg">
<wsdl:part name="queryShoppingCartByCustomerFault" element="tns:queryShoppingCartByCustomer_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="clearShoppingCartByCustomerRequest">
<wsdl:part name="clearShoppingCartByCustomerRequest"
element="tns:clearShoppingCartByCustomer">
</wsdl:part>
</wsdl:message>
<wsdl:message name="clearShoppingCartByCustomerResponse">
<wsdl:part name="clearShoppingCartByCustomerResponse"
element="tns:clearShoppingCartByCustomerResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="clearShoppingCartByCustomer_faultMsg">
<wsdl:part name="clearShoppingCartByCustomerFault" element="tns:clearShoppingCartByCustomer_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="removeBookItemRequest">
<wsdl:part name="removeBookItemRequest" element="tns:removeBookItem">
</wsdl:part>
</wsdl:message>
<wsdl:message name="removeBookItemResponse">
<wsdl:part name="removeBookItemResponse" element="tns:removeBookItemResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="removeShoppingCartBookItem_faultMsg">
<wsdl:part name="removeShoppingCartBookItemFault" element="tns:removeShoppingCartBookItem_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="removeBookItem_faultMsg">
<wsdl:part name="removeBookItemFault" element="tns:removeBookItem_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="modifyBookItemAmountRequest">
<wsdl:part name="modifyBookItemAmountRequest" element="tns:modifyBookItemAmount">
</wsdl:part>
</wsdl:message>
<wsdl:message name="modifyBookItemAmountResponse">
<wsdl:part name="modifyBookItemAmountResponse" element="tns:modifyBookItemAmountResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="modifyBookItemAmount_faultMsg">
<wsdl:part name="parameters" element="tns:modifyBookItemAmount_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="addBookItemToWishListRequest">
<wsdl:part name="addBookItemToWishListRequest" element="tns:addBookItemToWishList">
</wsdl:part>
</wsdl:message>
<wsdl:message name="addBookItemToWishListResponse">
<wsdl:part name="addBookItemToWishListResponse" element="tns:addBookItemToWishListResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="addBookItemToWishList_faultMsg">
<wsdl:part name="addBookItemToWishListFault" element="tns:addBookItemToWishList_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="addAllBookItemToWishListRequest">
<wsdl:part name="addAllBookItemToWishListRequest" element="tns:addAllBookItemToWishList">
</wsdl:part>
</wsdl:message>
<wsdl:message name="addAllBookItemToWishListResponse">
<wsdl:part name="addAllBookItemToWishListResponse" element="tns:addAllBookItemToWishListResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="addAllBookItemToWishList_faultMsg">
<wsdl:part name="addAllBookItemToWishListFault" element="tns:addAllBookItemToWishList_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsCategoryRequest">
<wsdl:part name="queryRelatedBooksByItemsCategoryRequest"
element="tns:queryRelatedBooksByItemsCategory">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsCategoryResponse">
<wsdl:part name="queryRelatedBooksByItemsCategoryResponse"
element="tns:queryRelatedBooksByItemsCategoryResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsCategory_faultMsg">
<wsdl:part name="queryRelatedBooksByItemsCategoryFault"
element="tns:queryRelatedBooksByItemsCategory_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsBookAuthorRequest">
<wsdl:part name="queryRelatedBooksByItemsBookAuthorRequest"
element="tns:queryRelatedBooksByItemsBookAuthor">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsBookAuthorResponse">
<wsdl:part name="queryRelatedBooksByItemsBookAuthorResponse"
element="tns:queryRelatedBooksByItemsBookAuthorResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsBookAuthor_faultMsg">
<wsdl:part name="queryRelatedBooksByItemsBookAuthorFault"
element="tns:queryRelatedBooksByItemsBookAuthor_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsBuyerHistoryRequest">
<wsdl:part name="queryRelatedBooksByItemsBuyerHistoryRequest"
element="tns:queryRelatedBooksByItemsBuyerHistory">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsBuyerHistoryResponse">
<wsdl:part name="queryRelatedBooksByItemsBuyerHistoryResponse"
element="tns:queryRelatedBooksByItemsBuyerHistoryResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="queryRelatedBooksByItemsBuyerHistory_faultMsg">
<wsdl:part name="queryRelatedBooksByItemsBuyerHistoryFault"
element="tns:queryRelatedBooksByItemsBuyerHistory_fault">
</wsdl:part>
</wsdl:message>
<wsdl:message name="checkUserIfLoginRequest">
<wsdl:part name="checkUserIfLoginRequest" element="tns:checkUserIfLogin">
</wsdl:part>
</wsdl:message>
<wsdl:message name="checkUserIfLoginResponse">
<wsdl:part name="checkUserIfLoginResponse" element="tns:checkUserIfLoginResponse">
</wsdl:part>
</wsdl:message>
<wsdl:message name="checkUserIfLogin_faultMsg">
<wsdl:part name="checkUserIfLoginFault" element="tns:checkUserIfLogin_fault">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="EditShoppingCartService">
<wsdl:operation name="queryShoppingCartByCustomer">
<wsdl:input message="tns:queryShoppingCartByCustomerRequest" />
<wsdl:output message="tns:queryShoppingCartByCustomerResponse" />
<wsdl:fault name="fault"
message="tns:queryShoppingCartByCustomer_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="clearShoppingCartByCustomer">
<wsdl:input message="tns:clearShoppingCartByCustomerRequest">
</wsdl:input>
<wsdl:output message="tns:clearShoppingCartByCustomerResponse">
</wsdl:output>
<wsdl:fault name="fault"
message="tns:clearShoppingCartByCustomer_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="removeBookItem">
<wsdl:input message="tns:removeBookItemRequest"></wsdl:input>
<wsdl:output message="tns:removeBookItemResponse"></wsdl:output>
<wsdl:fault name="fault" message="tns:removeBookItem_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="modifyBookItemAmount">
<wsdl:input message="tns:modifyBookItemAmountRequest"></wsdl:input>
<wsdl:output message="tns:modifyBookItemAmountResponse"></wsdl:output>
<wsdl:fault name="fault" message="tns:modifyBookItemAmount_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="addBookItemToWishList">
<wsdl:input message="tns:addBookItemToWishListRequest"></wsdl:input>
<wsdl:output message="tns:addBookItemToWishListResponse"></wsdl:output>
<wsdl:fault name="fault" message="tns:addBookItemToWishList_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="addAllBookItemToWishList">
<wsdl:input message="tns:addAllBookItemToWishListRequest"></wsdl:input>
<wsdl:output message="tns:addAllBookItemToWishListResponse">
</wsdl:output>
<wsdl:fault name="fault" message="tns:addAllBookItemToWishList_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="queryRelatedBooksByItemsCategory">
<wsdl:input message="tns:queryRelatedBooksByItemsCategoryRequest">
</wsdl:input>
<wsdl:output message="tns:queryRelatedBooksByItemsCategoryResponse">
</wsdl:output>
<wsdl:fault name="fault"
message="tns:queryRelatedBooksByItemsCategory_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="queryRelatedBooksByItemsBookAuthor">
<wsdl:input message="tns:queryRelatedBooksByItemsBookAuthorRequest">
</wsdl:input>
<wsdl:output message="tns:queryRelatedBooksByItemsBookAuthorResponse">
</wsdl:output>
<wsdl:fault name="fault"
message="tns:queryRelatedBooksByItemsBookAuthor_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="queryRelatedBooksByItemsBuyerHistory">
<wsdl:input message="tns:queryRelatedBooksByItemsBuyerHistoryRequest">
</wsdl:input>
<wsdl:output message="tns:queryRelatedBooksByItemsBuyerHistoryResponse">
</wsdl:output>
<wsdl:fault name="fault"
message="tns:queryRelatedBooksByItemsBuyerHistory_faultMsg">
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="checkUserIfLogin">
<wsdl:input message="tns:checkUserIfLoginRequest"></wsdl:input>
<wsdl:output message="tns:checkUserIfLoginResponse"></wsdl:output>
<wsdl:fault name="fault" message="tns:checkUserIfLogin_faultMsg">
</wsdl:fault>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="EditShoppingCartServiceSOAP" type="tns:EditShoppingCartService">
<soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="queryShoppingCartByCustomer">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/queryShoppingCartByCustomer" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="clearShoppingCartByCustomer">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/clearShoppingCartByCustomer" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="removeBookItem">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/removeBookItem" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="modifyBookItemAmount">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/modifyBookItemAmount" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="addBookItemToWishList">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/addBookItemToWishList" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="addAllBookItemToWishList">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/addAllBookItemToWishList" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="queryRelatedBooksByItemsCategory">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/queryRelatedBooksByItemsCategory" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="queryRelatedBooksByItemsBookAuthor">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/queryRelatedBooksByItemsBookAuthor" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="queryRelatedBooksByItemsBuyerHistory">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/queryRelatedBooksByItemsBuyerHistory" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
<wsdl:operation name="checkUserIfLogin">
<soap:operation
soapAction="abstraction/composite/business.shoppingbook.EditShoppingCartService/checkUserIfLogin" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
<wsdl:fault name="fault">
<soap:fault use="literal" name="fault" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="EditShoppingCartService">
<wsdl:port binding="tns:EditShoppingCartServiceSOAP" name="EditShoppingCartServiceSOAP">
<soap:address
location="http://127.0.0.1:8080/axis2/services/EditShoppingCartService" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
[b]注意:[/b]Namespace的命名规范
用下面这种方式来分类服务
source/structure/context
资源/结构/环境
示例:
Legacy/composite/business
现有资源/复合服务/业务

legacy/atomic/business.claims.autos.registration_service
现有资源/原子服务/业务类.索赔部门.汽车.登记服务

abstraction.process/cluster/business.loan_verification_service
提取过程/集群服务/业务类.贷款确认服务

abstraction.portfolio/cluster/business.fixed _income_division.fixed _income_cluster
提取分组/集群服务/业务.固定收入部门.固定收益服务群

至于XMLSchema都做了什么,其实就是定义WSDL所需数据类型。

之后一个很重要的环节就是,打开EditShoppingCartService.wsdl,

[img]/upload/attachment/86218/3990e75e-efe2-3e1b-a8ce-b329c8003f99.jpg[/img]
[img]/upload/attachment/86220/2d40cf1b-6103-369d-b686-d8cc8165b492.jpg[/img]
生成Bindding信息:

[img]/upload/attachment/86226/a6951320-81ca-3fc9-8557-1dae5f98b540.jpg[/img]
之后保存
[b]生成服务端:[/b]
确保%AXIS2_HOME%\bin目录 在系统变量%PATH%下
在wsdl文件所在目录运行命令 :
wsdl2java -o src -ss -ssi -sd -uri EditShoppingCartService.wsdl
[img]/upload/attachment/86230/a53b96d1-8109-3c04-bc8a-ce190c5cc8ef.jpg[/img]
运行命令成功:
[img]/upload/attachment/86232/f6b83c8e-11d6-3912-a517-c690bed42a34.jpg[/img]
1。生成服务端代码框架:
[img]/upload/attachment/86234/53c23c90-882a-3a83-8225-842b5c2dd257.jpg[/img]
2.完善服务类实现方法:
将通过wsdl2java生成的服务端代码加入工程java文件目录:
可以通过eclipse添加Source Folder或直接把代码靠进src下
3.加入axis2的JAR
4.加入webSphere MQ的jar 位于%webSphere MQ%\Java\lib
5.修改wsdl\src\src\editshoppingcartservice\shoppingbook\business\composite\abstractionEditShoppingCartServiceSkeleton.java
改为:
/**
* EditShoppingCartServiceSkeleton.java
*
* This file was auto-generated from WSDL
* by the Apache Axis2 version: 1.4 Built on : Apr 26, 2008 (06:24:30 EDT)
*/
package editshoppingcartservice.shoppingbook.business.composite.abstraction;

import java.util.ArrayList;
import java.util.HashMap;

import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.BasicFaultType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.BasicResponseBooleanType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.BasicResponseCodeType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.BookListType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.BookType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.CustomerType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.ItemListType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.ItemType;
import xmlschema.editshoppingcartservice.shoppingbook.business.composite.abstraction.ShoppingCartType;

/**
* EditShoppingCartServiceSkeleton java skeleton for the axisService
*/
public class EditShoppingCartServiceSkeleton implements
EditShoppingCartServiceSkeletonInterface {

private static HashMap shoppingcartMap = new HashMap();
private static HashMap relatedbooksMap = new HashMap();
private static boolean isinit = false;

public EditShoppingCartServiceSkeleton() {
if (!isinit) {
ShoppingCartType sct1 = new ShoppingCartType();
CustomerType ct = new CustomerType();
ct.setCustomerId("001");
ct.setCustomerName("customer name1");
sct1.setCustomer(ct);

ItemListType ilt1 = new ItemListType();
ItemType item1 = new ItemType();
item1.setBookId("b001");
item1.setBookName("book1 name1");
item1.setBookPrice(30);
item1.setMyPrice(25);
item1.setAmount(2);
item1.setSubTotal(50);

ItemType item2 = new ItemType();
item2.setBookId("b002");
item2.setBookName("book2 name2");
item2.setBookPrice(20);
item2.setMyPrice(10);
item2.setAmount(3);
item2.setSubTotal(30);

ilt1.addItem(item1);
ilt1.addItem(item2);
sct1.setItemList(ilt1);
sct1.setOriginalTotal(120);
sct1.setRealTotal(80);

shoppingcartMap.put(sct1.getCustomer().getCustomerId(), sct1);

ShoppingCartType sct2 = new ShoppingCartType();
CustomerType ct2 = new CustomerType();
ct2.setCustomerId("002");
ct2.setCustomerName("customer name2");
sct2.setCustomer(ct2);

ItemListType ilt2 = new ItemListType();
ItemType item3 = new ItemType();
item3.setBookId("b003");
item3.setBookName("book3 name3");
item3.setBookPrice(40);
item3.setMyPrice(30);
item3.setAmount(2);
item3.setSubTotal(60);

ItemType item4 = new ItemType();
item4.setBookId("b004");
item4.setBookName("book4 name4");
item4.setBookPrice(50);
item4.setMyPrice(40);
item4.setAmount(3);
item4.setSubTotal(120);

ilt2.addItem(item3);
ilt2.addItem(item4);
sct2.setItemList(ilt2);
sct2.setOriginalTotal(230);
sct2.setRealTotal(180);

shoppingcartMap.put(sct2.getCustomer().getCustomerId(), sct2);

// BookListType blist1=new BookListType();
BookType book1 = new BookType();
book1.setId("b101");
book1.setName("name101");
book1.setAuthor("author101");
book1.setPrice(101);
book1.setCategory("category101");
// blist1.addBook(book1);

// BookListType blist2=new BookListType();
BookType book2 = new BookType();
book2.setId("b102");
book2.setName("name102");
book2.setAuthor("author102");
book2.setPrice(102);
book2.setCategory("category102");
// blist2.addBook(book2);

// BookListType blist3=new BookListType();
BookType book3 = new BookType();
book3.setId("b103");
book3.setName("name103");
book3.setAuthor("author103");
book3.setPrice(103);
book3.setCategory("category103");
// blist3.addBook(book3);

this.relatedbooksMap.put("b101", book1);
this.relatedbooksMap.put("b102", book2);
this.relatedbooksMap.put("b103", book3);

isinit = true;
}
}

/**
* Auto generated method signature
*
* @param clearShoppingCartByCustomer0
* @throws ClearShoppingCartByCustomer_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.ClearShoppingCartByCustomerResponse clearShoppingCartByCustomer(
editshoppingcartservice.shoppingbook.business.composite.abstraction.ClearShoppingCartByCustomer clearShoppingCartByCustomer)
throws ClearShoppingCartByCustomer_faultMsg {
// TODO : fill this with the necessary business logic

System.out.println("clearShoppingCartByCustomer.....");
ClearShoppingCartByCustomerResponse res = new ClearShoppingCartByCustomerResponse();

String customerId = clearShoppingCartByCustomer
.getClearShoppingCartByCustomer().getCustomerId();
if (customerId != null && customerId.length() > 0) {
if (this.shoppingcartMap.containsKey(customerId)) {
System.out.println("this.shoppingcartMap.containsKey('"
+ customerId + "')");

this.shoppingcartMap.remove(customerId);

} else {
ClearShoppingCartByCustomer_faultMsg faultmsg = new ClearShoppingCartByCustomer_faultMsg();
ClearShoppingCartByCustomer_fault fault = new ClearShoppingCartByCustomer_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e001");// 不存在该customer的购物车数据
param.setErrorMessage("不存在该customer的购物车数据");
fault.setClearShoppingCartByCustomer_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}
} else {
ClearShoppingCartByCustomer_faultMsg faultmsg = new ClearShoppingCartByCustomer_faultMsg();
ClearShoppingCartByCustomer_fault fault = new ClearShoppingCartByCustomer_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e002");// 输入参数customer为空
param.setErrorMessage("输入参数customer为空");
fault.setClearShoppingCartByCustomer_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}
BasicResponseCodeType param = new BasicResponseCodeType();
param.setResCode("0");
param.setResMessage("清空购物车成功!");
res.setClearShoppingCartByCustomerResponse(param);
return res;

// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName() + "#clearShoppingCartByCustomer");
}

/**
* Auto generated method signature
*
* @param addAllBookItemToWishList2
* @throws AddAllBookItemToWishList_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.AddAllBookItemToWishListResponse addAllBookItemToWishList(
editshoppingcartservice.shoppingbook.business.composite.abstraction.AddAllBookItemToWishList addAllBookItemToWishList2)
throws AddAllBookItemToWishList_faultMsg {
// TODO : fill this with the necessary business logic
System.out.println("addAllBookItemToWishList.....");
AddAllBookItemToWishListResponse res = new AddAllBookItemToWishListResponse();
BasicResponseBooleanType bres = new BasicResponseBooleanType();
bres.setResult(true);
res.setAddAllBookItemToWishListResponse(bres);
return res;

// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName() + "#addAllBookItemToWishList");
}

/**
* Auto generated method signature
*
* @param removeBookItem4
* @throws RemoveBookItem_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.RemoveBookItemResponse removeBookItem(
editshoppingcartservice.shoppingbook.business.composite.abstraction.RemoveBookItem removeBookItem)
throws RemoveBookItem_faultMsg {
System.out.println("removeBookItem.....");
RemoveBookItemResponse res = new RemoveBookItemResponse();

String customerId = removeBookItem.getRemoveBookItem().getCustomerId();

if (customerId != null && customerId.length() > 0) {
if (this.shoppingcartMap.containsKey(customerId)) {
System.out.println("this.shoppingcartMap.containsKey('"
+ customerId + "')");
ShoppingCartType shoppingcart = (ShoppingCartType) this.shoppingcartMap
.get(customerId);
String bookId = removeBookItem.getRemoveBookItem()
.getItemBookId();

shoppingcart = this.removeShoppingCartItemBybookId(
shoppingcart, bookId);

if (shoppingcart == null) {
RemoveBookItem_faultMsg faultmsg = new RemoveBookItem_faultMsg();
RemoveBookItem_fault fault = new RemoveBookItem_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e003");// 不存在该customer的购物车数据
param.setErrorMessage("该customer(" + customerId
+ ")购物车,不存在bookId(" + bookId + ")数据!");
fault.setRemoveBookItem_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;

}
this.shoppingcartMap.put(customerId, shoppingcart);
res.setRemoveBookItemResponse(shoppingcart);
} else {
RemoveBookItem_faultMsg faultmsg = new RemoveBookItem_faultMsg();
RemoveBookItem_fault fault = new RemoveBookItem_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e001");// 不存在该customer的购物车数据
param.setErrorMessage("不存在该customer的购物车数据");
fault.setRemoveBookItem_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}
} else {
RemoveBookItem_faultMsg faultmsg = new RemoveBookItem_faultMsg();
RemoveBookItem_fault fault = new RemoveBookItem_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e002");// 输入参数customer为空
param.setErrorMessage("输入参数customer为空");
fault.setRemoveBookItem_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}
return res;

// TODO : fill this with the necessary business logic
// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName() + "#removeBookItem");
}

/**
* Auto generated method signature
*
* @param queryRelatedBooksByItemsBookAuthor6
* @throws QueryRelatedBooksByItemsBookAuthor_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryRelatedBooksByItemsBookAuthorResponse queryRelatedBooksByItemsBookAuthor(
editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryRelatedBooksByItemsBookAuthor queryRelatedBooksByItemsBookAuthor6)
throws QueryRelatedBooksByItemsBookAuthor_faultMsg {
// TODO : fill this with the necessary business logic
System.out.println("queryRelatedBooksByItemsBookAuthor.....");
BookType book1 = (BookType) this.relatedbooksMap.get("b101");
BookListType blist1 = new BookListType();
blist1.addBook(book1);
QueryRelatedBooksByItemsBookAuthorResponse res = new QueryRelatedBooksByItemsBookAuthorResponse();
res.setQueryRelatedBooksByItemsBookAuthorResponse(blist1);
return res;

// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName()
// + "#queryRelatedBooksByItemsBookAuthor");
}

/**
* Auto generated method signature
*
* @param addBookItemToWishList8
* @throws AddBookItemToWishList_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.AddBookItemToWishListResponse addBookItemToWishList(
editshoppingcartservice.shoppingbook.business.composite.abstraction.AddBookItemToWishList addBookItemToWishList8)
throws AddBookItemToWishList_faultMsg {

System.out.println("addBookItemToWishList.....");
AddBookItemToWishListResponse res = new AddBookItemToWishListResponse();
BasicResponseBooleanType bres = new BasicResponseBooleanType();
bres.setResult(true);
res.setAddBookItemToWishListResponse(bres);
return res;
// TODO : fill this with the necessary business logic
// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName() + "#addBookItemToWishList");
}

/**
* Auto generated method signature
*
* @param modifyBookItemAmount10
* @throws ModifyBookItemAmount_faultMsg:
*/

private ItemType getShoppingCartItemBybookId(ShoppingCartType shoppingcart,
String bookId) {
ItemType ret = null;
ItemType[] itemlist = shoppingcart.getItemList().getItem();
for (int i = 0; i < itemlist.length; i++) {
ItemType item = (ItemType) itemlist[i];
if (item.getBookId().equals(bookId)) {
return item;
}
}
return ret;
}

private void updateShoppingCarPrice(ShoppingCartType shoppingcart) {
ItemType[] itemlist = shoppingcart.getItemList().getItem();
double totalMprice = 0;
double totalOprice = 0;

for (int i = 0; i < itemlist.length; i++) {
ItemType item = (ItemType) itemlist[i];
totalMprice += item.getMyPrice() * item.getAmount();
totalOprice += item.getBookPrice() * item.getAmount();
}
shoppingcart.setOriginalTotal(totalOprice);
shoppingcart.setRealTotal(totalMprice);
}

private ShoppingCartType updateShoppingCartItemBybookId(
ShoppingCartType shoppingcart, String bookId, int amount) {
ShoppingCartType ret = null;
ItemType[] itemlist = shoppingcart.getItemList().getItem();
for (int i = 0; i < itemlist.length; i++) {
ItemType item = (ItemType) itemlist[i];
if (item.getBookId().equals(bookId)) {
item.setAmount(amount);
item.setSubTotal(amount * item.getMyPrice());
updateShoppingCarPrice(shoppingcart);
return shoppingcart;
}
}
return ret;
}

private ShoppingCartType removeShoppingCartItemBybookId(
ShoppingCartType shoppingcart, String bookId) {
ShoppingCartType ret = null;
ItemType[] itemlist = shoppingcart.getItemList().getItem();
ArrayList temp = new ArrayList();
boolean flag = false;
for (int i = 0; i < itemlist.length; i++) {
ItemType item = (ItemType) itemlist[i];
if (item.getBookId().equals(bookId)) {
// item = null;
// itemlist[i]=null;
// updateShoppingCarPrice(shoppingcart);
// return shoppingcart;
flag = true;
} else {
temp.add(item);
}
}

ItemType[] newitemlist = new ItemType[temp.size()];
for (int i = 0; i < temp.size(); i++) {
newitemlist[i] = (ItemType) temp.get(i);
}
if (flag) {
ItemListType listtype = new ItemListType();
listtype.setItem(newitemlist);
shoppingcart.setItemList(listtype);
updateShoppingCarPrice(shoppingcart);
return shoppingcart;
} else {
return ret;
}

}

public editshoppingcartservice.shoppingbook.business.composite.abstraction.ModifyBookItemAmountResponse modifyBookItemAmount(
editshoppingcartservice.shoppingbook.business.composite.abstraction.ModifyBookItemAmount modifyBookItemAmount)
throws ModifyBookItemAmount_faultMsg {
System.out.println("modifyBookItemAmount.....");
ModifyBookItemAmountResponse res = new ModifyBookItemAmountResponse();

String customerId = modifyBookItemAmount.getModifyBookItemAmount()
.getCustomerId();
if (customerId != null && customerId.length() > 0) {
if (this.shoppingcartMap.containsKey(customerId)) {
System.out.println("this.shoppingcartMap.containsKey('"
+ customerId + "')");
ShoppingCartType shoppingcart = (ShoppingCartType) this.shoppingcartMap
.get(customerId);
String bookId = modifyBookItemAmount.getModifyBookItemAmount()
.getItemBookId();
int amount = modifyBookItemAmount.getModifyBookItemAmount()
.getItemAmount();
shoppingcart = this.updateShoppingCartItemBybookId(
shoppingcart, bookId, amount);
if (shoppingcart == null) {
ModifyBookItemAmount_faultMsg faultmsg = new ModifyBookItemAmount_faultMsg();
ModifyBookItemAmount_fault fault = new ModifyBookItemAmount_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e003");// 不存在该customer的购物车数据
param.setErrorMessage("该customer(" + customerId
+ ")购物车,不存在bookId(" + bookId + ")数据!");
fault.setModifyBookItemAmount_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;

}
this.shoppingcartMap.put(customerId, shoppingcart);
res.setModifyBookItemAmountResponse(shoppingcart);
} else {
ModifyBookItemAmount_faultMsg faultmsg = new ModifyBookItemAmount_faultMsg();
ModifyBookItemAmount_fault fault = new ModifyBookItemAmount_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e001");// 不存在该customer的购物车数据
param.setErrorMessage("不存在该customer的购物车数据");
fault.setModifyBookItemAmount_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}
} else {
ModifyBookItemAmount_faultMsg faultmsg = new ModifyBookItemAmount_faultMsg();
ModifyBookItemAmount_fault fault = new ModifyBookItemAmount_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e002");// 输入参数customer为空
param.setErrorMessage("输入参数customer为空");
fault.setModifyBookItemAmount_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}
return res;
// TODO : fill this with the necessary business logic
// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName() + "#modifyBookItemAmount");
}

/**
* Auto generated method signature
*
* @param queryRelatedBooksByItemsBuyerHistory12
* @throws QueryRelatedBooksByItemsBuyerHistory_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryRelatedBooksByItemsBuyerHistoryResponse queryRelatedBooksByItemsBuyerHistory(
editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryRelatedBooksByItemsBuyerHistory queryRelatedBooksByItemsBuyerHistory12)
throws QueryRelatedBooksByItemsBuyerHistory_faultMsg {
// TODO : fill this with the necessary business logic

System.out.println("queryRelatedBooksByItemsBuyerHistory.....");
BookType book3 = (BookType) this.relatedbooksMap.get("b103");
BookListType blist3 = new BookListType();
blist3.addBook(book3);
QueryRelatedBooksByItemsBuyerHistoryResponse res = new QueryRelatedBooksByItemsBuyerHistoryResponse();
res.setQueryRelatedBooksByItemsBuyerHistoryResponse(blist3);
return res;

// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName()
// + "#queryRelatedBooksByItemsBuyerHistory");
}

/**
* Auto generated method signature
*
* @param checkUserIfLogin14
* @throws CheckUserIfLogin_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.CheckUserIfLoginResponse checkUserIfLogin(
editshoppingcartservice.shoppingbook.business.composite.abstraction.CheckUserIfLogin checkUserIfLogin)
throws CheckUserIfLogin_faultMsg {
// TODO : fill this with the necessary business logic
System.out.println("checkUserIfLogin.....");
CheckUserIfLoginResponse res = new CheckUserIfLoginResponse();
BasicResponseBooleanType bres = new BasicResponseBooleanType();
bres.setResult(false);
res.setCheckUserIfLoginResponse(bres);
String customerId = checkUserIfLogin.getCheckUserIfLogin()
.getCustomerId();
if (customerId != null && customerId.length() > 0) {
if (customerId.startsWith("L")) {
bres.setResult(true);
res.setCheckUserIfLoginResponse(bres);
}
} else {
CheckUserIfLogin_faultMsg faultmsg = new CheckUserIfLogin_faultMsg();
CheckUserIfLogin_fault fault = new CheckUserIfLogin_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e002");// 输入参数customer为空
param.setErrorMessage("输入参数customer为空");
fault.setCheckUserIfLogin_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}

return res;
// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName() + "#checkUserIfLogin");
}

/**
* Auto generated method signature
*
* @param queryRelatedBooksByItemsCategory16
* @throws QueryRelatedBooksByItemsCategory_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryRelatedBooksByItemsCategoryResponse queryRelatedBooksByItemsCategory(
editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryRelatedBooksByItemsCategory queryRelatedBooksByItemsCategory16)
throws QueryRelatedBooksByItemsCategory_faultMsg {
// TODO : fill this with the necessary business logic

System.out.println("queryRelatedBooksByItemsCategory.....");
BookType book2 = (BookType) this.relatedbooksMap.get("b102");
BookListType blist2 = new BookListType();
blist2.addBook(book2);
QueryRelatedBooksByItemsCategoryResponse res = new QueryRelatedBooksByItemsCategoryResponse();
res.setQueryRelatedBooksByItemsCategoryResponse(blist2);
return res;

// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName()
// + "#queryRelatedBooksByItemsCategory");
}

/**
* Auto generated method signature
*
* @param queryShoppingCartByCustomer18
* @throws QueryShoppingCartByCustomer_faultMsg :
*/

public editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryShoppingCartByCustomerResponse queryShoppingCartByCustomer(
editshoppingcartservice.shoppingbook.business.composite.abstraction.QueryShoppingCartByCustomer queryShoppingCartByCustomer)
throws QueryShoppingCartByCustomer_faultMsg {

System.out.println("queryShoppingCartByCustomerId.....");
QueryShoppingCartByCustomerResponse res = new QueryShoppingCartByCustomerResponse();

String customerId = queryShoppingCartByCustomer
.getQueryShoppingCartByCustomer().getCustomerId();
if (customerId != null && customerId.length() > 0) {
if (this.shoppingcartMap.containsKey(customerId)) {
System.out.println("this.shoppingcartMap.containsKey('"
+ customerId + "')");

res
.setQueryShoppingCartByCustomerResponse(((ShoppingCartType) this.shoppingcartMap
.get(customerId)));
} else {
QueryShoppingCartByCustomer_faultMsg faultmsg = new QueryShoppingCartByCustomer_faultMsg();
QueryShoppingCartByCustomer_fault fault = new QueryShoppingCartByCustomer_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e001");// 不存在该customer的购物车数据
param.setErrorMessage("不存在该customer的购物车数据");
fault.setQueryShoppingCartByCustomer_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}
} else {
QueryShoppingCartByCustomer_faultMsg faultmsg = new QueryShoppingCartByCustomer_faultMsg();
QueryShoppingCartByCustomer_fault fault = new QueryShoppingCartByCustomer_fault();
BasicFaultType param = new BasicFaultType();
param.setErrorCode("e002");// 输入参数customer为空
param.setErrorMessage("输入参数customer为空");
fault.setQueryShoppingCartByCustomer_fault(param);
faultmsg.setFaultMessage(fault);
throw faultmsg;
}

return res;

// TODO : fill this with the necessary business logic
// throw new java.lang.UnsupportedOperationException("Please implement "
// + this.getClass().getName() + "#queryShoppingCartByCustomer");
}

}
保存,打包服务,生成.aar文件
生成服务打包文件EditShoppingCartService.aar,拷贝WEB_INF/services文件中自动部署,或者通过axis2服务管理台上传服务。如果使用服务上传,需要把axis2.xml文件中的hotupdate属性设置成true,否则服务不会自动更新。
.aar实际上是一个类似于.jar的文件,文件中的格式如下所示:

EditShoppingCartService.aar
├─editshoppingcartservice
│ └─business
│ └─demo
│ └─atomic
│ └─process
│ └─abstraction
├─lib
├─META-INF
└─xmlschema
└─editshoppingcartservice
└─business
└─demo
└─atomic
└─process
└─abstraction


在这里,采用了Eclipse的插件Axis2 Service Archiver进行服务打包,具体使用方法如下:
[img]/upload/attachment/86252/5cb290ee-c3f8-37f8-b390-48a716de0231.jpg[/img]
Step 2: 选择Axis2 Service Archiver,选择服务实现类的路径
[img]/upload/attachment/86254/e5ffcc48-c269-3c5c-b9de-b13c1fc8c09d.jpg[/img]
Step 3: 选择WSDL文件
[img]/upload/attachment/86256/8847225e-01b9-3fee-8f65-f3e2c4a4e65d.jpg[/img]
Step 4: 增加相应的jar文件
可以不添加,如果需要增加额外的jar文件,需要在此增加,文件打包之后会存储在lib目录中。
Step 5: 选择services.xml文件(选择通过wsdl2java生成的services.xml即可)
[img]/upload/attachment/86264/3aaa1fde-e513-3d9b-a436-b068386c53cd.jpg[/img]
Step 6: 选择文件生成的路径
[img]/upload/attachment/86266/787de998-63bd-3f11-9f16-768a2df6ed2d.jpg[/img]
点击Finish按钮,生成EditShoppingCartService.aar文件。
如果使用Eclipse进行开发,可以方便的使用该工具生成.aar服务文件。
注意:默认情况下 schema文件并没有拷贝到aar文件中,需要手动拷贝过去,将
ShoppingCartSchema.xsd 放到EditShoppingCartService.aar\META-INF中:
[img]/upload/attachment/86270/6df76b56-c3d7-3138-afc1-052c8525e1f7.jpg[/img]
3.1.1.5 部署AXIS2 SOAP Engine
将axis2.war 拷贝到%TOMCAT_HOME%\webapps\,启动tomcat,即运行命令%TOMCAT_HOME%\bin\startup.bat;
在浏览器输入:http://localhost:8080/axis2,进入工作台登录输入用户:admin 密码:axis2 ,上传EditShoppingCartService.aar,通过验证后,服务即被发布
http://127.0.0.1:8080/axis2/services/EditShoppingCartService?wsdl或者
http://127.0.0.1:8080/axis2/services/EditShoppingCartService?wsdl20
查看WSDL或WSDL2.0文件:
[b]Web Service客户端开发[/b]:
设置path 保证%AXIS2_HOME\bin%在里面:
运行命令wsdl2java -o src –a -s –p demo.test.client.adb -uri http://127.0.0.1:8080/axis2/services/EditShoppingCartService?wsdl


其中参数uri为wsdl路径,可以是硬盘文件,也可以是http地址http://127.0.0.1:8080/axis2/services/EditShoppingCartService?wsdl
其他参数:
-o <path> Specify a directory path for the generated code.
-p <pkg1> Specify a custom package name for the generated code.
-a Generate async style code only (Default: off).
-s Generate sync style code only (Default: off)

运行成功后生成ADB绑定类:
导入Source Folder
如eclipse提示出错,检查JAR和包路径
[b]建立JNDI[/b]
1. 用文本编辑器打开文件:
[MQ_安装目录]/Java/bin/ JMSAdmin.config
注释这行:
#INITIAL_CONTEXT_FACTORY=com.sun.jndi.ldap.LdapCtxFactory
打开这行注释:
INITIAL_CONTEXT_FACTORY=com.sun.jndi.fscontext.RefFSContextFactory
注释这行:
#PROVIDER_URL=ldap://polaris/o=ibm,c=us
打开这行注释:
PROVIDER_URL=file:/C:/JNDI-Directory
2. 建立目录:C:/JNDI-Directory
3. 打开 “WebSphere MQ Resource Manager”,新建队列管理器QM,建立本地队列“EditShoppingCartService”,注意必须和webservice同名。
4. 运行[MQ_安装目录]/Java/bin/JMSAdmin.bat, 输入如下命令:
输入命令:
def qcf(QueueConnectionFactory) qmgr(QM)
def q(EditShoppingCartService) queue(EditShoppingCartService)
end 回车 退出

5.5. 打开[TOMCAT_HOME]/webapps/axis2/WEB-INF/conf/axis2.xml 编辑如下部分内容:
<transportReceiver name="jms" class="org.apache.axis2.transport.jms.JMSListener">
<parameter name="myTopicConnectionFactory">
<parameter name="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</parameter>
<parameter name="java.naming.provider.url">file:/C:/JNDI-Directory</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
</parameter>
<parameter name="myQueueConnectionFactory">
<parameter name="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</parameter>
<parameter name="java.naming.provider.url">file:/C:/JNDI-Directory</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
</parameter>
<parameter name="default">
<parameter name="java.naming.factory.initial">com.sun.jndi.fscontext.RefFSContextFactory</parameter>
<parameter name="java.naming.provider.url">file:/C:/JNDI-Directory</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName">QueueConnectionFactory</parameter>
</parameter>
</transportReceiver>
再找到:
[img]/upload/attachment/86293/fc3fe462-fd69-3242-8dcc-f35525e93dee.jpg[/img]
去掉注释

6. 拷贝MQ jar 文件[MQ安装目录]\Java\lib下
(com.ibm.mq.jar, com.ibm.mqjms.jar, connector.jar, dhbcore.jar, fscontext.jar, providerutil.jar) 到[TOMCAT_安装目录]/webapps/axis2/WEB-INF/lib下
7. 重新启动tomcat
8.根目录下新建resource文件夹,然后1. 将修改后的[TOMCAT_HOME]/webapps/axis2/WEB-INF/conf/axis2.xml拷贝到工程目录\resource下 ,然后再resource文件夹下新建modules文件夹,并拷贝%Tomcat_home%\webapps\axis2\WEB-INF\modules\addressing-1.4.mar到resource\modules为什么这么做,稍后讲。
9、2. 如果AXIS2 SOAP Engine中还发布了其他的service,则需要为这些service建立队列和JNDI,否则启动tomcat后会报如下错误:
[img]/upload/attachment/86276/fdc5ad9d-ec13-3567-9084-944e5f7dcdf2.jpg[/img]
[b]新建测试类:ADBClient_mq_jms.java[/b],同步调用测试:
参考代码如下:
package demo.test.client.mq;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;

import demo.test.client.adb.EditShoppingCartServiceStub;
import demo.test.client.adb.EditShoppingCartServiceStub.CustomerType;
import demo.test.client.adb.EditShoppingCartServiceStub.QueryShoppingCartByCustomer;
import demo.test.client.adb.EditShoppingCartServiceStub.QueryShoppingCartByCustomerResponse;

public class ADBClient_mq_jms {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
try {

String epr = "jms:/EditShoppingCartService"
+ "?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory"
+ "&java.naming.provider.url=file:/C:/JNDI-Directory"
+ "&java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory";


ConfigurationContext configContext = ConfigurationContextFactory
.createConfigurationContextFromFileSystem("./resource",
"resource/axis2.xml");

EditShoppingCartServiceStub stub = new EditShoppingCartServiceStub(
configContext,epr);
QueryShoppingCartByCustomer req = new QueryShoppingCartByCustomer();

CustomerType param = new CustomerType();
param.setCustomerId("001");
req.setQueryShoppingCartByCustomer(param);
QueryShoppingCartByCustomerResponse res = stub
.queryShoppingCartByCustomer(req);
System.out.println("response:");
System.out.println("ShoppiongCart MyTotalPrice:");
System.out.println(res.getQueryShoppingCartByCustomerResponse()
.getRealTotal());
} catch (AxisFault ex) {
ex.printStackTrace();

} catch (Exception ex1) {
ex1.printStackTrace();
}
}
}
[img]/upload/attachment/86278/229f1070-770f-3b63-aba6-dcb72e555723.jpg[/img]
5.3.3.3 ADB异步方式:ADBClient_async_mq_jms.java
新建测试类:
package demo.test.client.mq;

import org.apache.axis2.AxisFault;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.context.ConfigurationContextFactory;
import org.apache.axis2.transport.jms.JMSConstants;

import demo.test.client.adb.EditShoppingCartServiceCallbackHandler;
import demo.test.client.adb.EditShoppingCartServiceStub;
import demo.test.client.adb.EditShoppingCartServiceStub.CustomerType;
import demo.test.client.adb.EditShoppingCartServiceStub.QueryShoppingCartByCustomer;
import demo.test.client.adb.EditShoppingCartServiceStub.QueryShoppingCartByCustomerResponse;

public class ADBClient_async_mq_jms {

/**
* @param args
*/
public static void main(String[] args) {
try {


String targetEPRStr = "jms:/EditShoppingCartService"
+ "?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory"
+ "&java.naming.provider.url=file:/C:/JNDI-Directory"
+ "&java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory";

ConfigurationContext configContext = ConfigurationContextFactory
.createConfigurationContextFromFileSystem("./resource",
"resource/axis2.xml");

configContext.setProperty(JMSConstants.REPLY_PARAM,
"ADBAsyncReplayQueue");

EditShoppingCartServiceStub stub = new EditShoppingCartServiceStub(
configContext, targetEPRStr);

QueryShoppingCartByCustomer req = new QueryShoppingCartByCustomer();
CustomerType param = new CustomerType();
param.setCustomerId("001");
req.setQueryShoppingCartByCustomer(param);

EditShoppingCartServiceCallbackHandler callback = new EditShoppingCartServiceCallbackHandler() {

public void receiveResultqueryShoppingCartByCustomer(
QueryShoppingCartByCustomerResponse result) {

System.out.println("Call back Resutlt:");
System.out.println("ShoppiongCart MyTotalPrice:");
System.out.println(result
.getQueryShoppingCartByCustomerResponse()
.getRealTotal());
}

public void receiveErrorqueryShoppingCartByCustomer(
java.lang.Exception e) {
}
};
stub.startqueryShoppingCartByCustomer(req, callback);
System.out.println("send Request!!");
Thread.sleep(5000);

} catch (AxisFault ex) {
ex.printStackTrace();

} catch (Exception ex1) {
ex1.printStackTrace();
}
}
}
分别运行,能看到

[img]/upload/attachment/86280/dd84e357-441d-3353-8540-fb671d41661d.jpg[/img]

好了,终于耐着性子做完了,
分析下:为什么采用JMS协议而不用http(s),最主要的原因,是处于webService的安全问题以及可靠性和可伸缩性,SOAP 与传输无关,可以绑定到任何协议;SOAP over JMS 是针对标准 SOAP over HTTP 消息的替代消息机制。SOAP over JMS 经证明比 SOAP over HTTP 更加可靠和可伸缩。其可靠性和可伸缩性反映了在我们的例子中用作 JMS 提供者的 WebSphere MQ 的可靠性和可伸缩性。它之所以可靠是因为消息传递得到了保证,可伸缩是因为它可以支持大容量连接。
SOAP over JMS 还允许 Web 服务客户端异步调用服务而不等待响应。尽管同步和异步传输协议都可以实现异步调用风格,但是 JMS 使得异步调用的实现对服务请求者和服务提供者来说都更加容易。
有兴趣的请参考我的另一篇讨论SOAP over JMS 架构的文章
[url]http://mht19840918.iteye.com/blog/352442[/url]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值