- 浏览: 198858 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
cyp890813:
多张报表打印成一个pdf文件,通过exportParamete ...
在Struts2中使用JasperReports生成报表 -
sp42:
哈哈 当年我翻译的文章
ext入门 -
yuexingchen2:
为什么我调用dao的时候,一直提示空指针异常?
spring2.5注释配置SqlMapClientDaoSupport -
beiyeren:
很好,谢谢
jsp2.0标记文件(tag)详解 -
hutengfei0701:
如果生成的报表HTML上还需要加入几个按钮之类的,怎么做? s ...
在Struts2中使用JasperReports生成报表
开发环境需求:
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%中;
创建服务实现类方式:
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>
注意: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,
生成Bindding信息:
之后保存
生成服务端:
确保%AXIS2_HOME%\bin目录 在系统变量%PATH%下
在wsdl文件所在目录运行命令 :
wsdl2java -o src -ss -ssi -sd -uri EditShoppingCartService.wsdl
运行命令成功:
1。生成服务端代码框架:
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进行服务打包,具体使用方法如下:
Step 2: 选择Axis2 Service Archiver,选择服务实现类的路径
Step 3: 选择WSDL文件
Step 4: 增加相应的jar文件
可以不添加,如果需要增加额外的jar文件,需要在此增加,文件打包之后会存储在lib目录中。
Step 5: 选择services.xml文件(选择通过wsdl2java生成的services.xml即可)
Step 6: 选择文件生成的路径
点击Finish按钮,生成EditShoppingCartService.aar文件。
如果使用Eclipse进行开发,可以方便的使用该工具生成.aar服务文件。
注意:默认情况下 schema文件并没有拷贝到aar文件中,需要手动拷贝过去,将
ShoppingCartSchema.xsd 放到EditShoppingCartService.aar\META-INF中:
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文件:
Web Service客户端开发:
设置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和包路径
建立JNDI
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>
再找到:
去掉注释
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后会报如下错误:
新建测试类:ADBClient_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 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();
}
}
}
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();
}
}
}
分别运行,能看到
好了,终于耐着性子做完了,
分析下:为什么采用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 架构的文章
http://mht19840918.iteye.com/blog/352442
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%中;
创建服务实现类方式:
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>
注意: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,
生成Bindding信息:
之后保存
生成服务端:
确保%AXIS2_HOME%\bin目录 在系统变量%PATH%下
在wsdl文件所在目录运行命令 :
wsdl2java -o src -ss -ssi -sd -uri EditShoppingCartService.wsdl
运行命令成功:
1。生成服务端代码框架:
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进行服务打包,具体使用方法如下:
Step 2: 选择Axis2 Service Archiver,选择服务实现类的路径
Step 3: 选择WSDL文件
Step 4: 增加相应的jar文件
可以不添加,如果需要增加额外的jar文件,需要在此增加,文件打包之后会存储在lib目录中。
Step 5: 选择services.xml文件(选择通过wsdl2java生成的services.xml即可)
Step 6: 选择文件生成的路径
点击Finish按钮,生成EditShoppingCartService.aar文件。
如果使用Eclipse进行开发,可以方便的使用该工具生成.aar服务文件。
注意:默认情况下 schema文件并没有拷贝到aar文件中,需要手动拷贝过去,将
ShoppingCartSchema.xsd 放到EditShoppingCartService.aar\META-INF中:
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文件:
Web Service客户端开发:
设置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和包路径
建立JNDI
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>
再找到:
去掉注释
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后会报如下错误:
新建测试类:ADBClient_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 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();
}
}
}
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();
}
}
}
分别运行,能看到
好了,终于耐着性子做完了,
分析下:为什么采用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 架构的文章
http://mht19840918.iteye.com/blog/352442
相关推荐
标题中的“基于soap over jms 的websphere mq与axis2的实现”涉及到的是在企业级应用中使用Web服务和消息中间件技术的具体实践。这里,`SOAP over JMS`指的是通过Java消息服务(JMS)传输SOAP消息,而`Websphere MQ`...
在本场景中,"用jms向WebSphere mq里发送消息"是指使用JMS接口来与WebSphere MQ进行交互,实现消息的发布和订阅。 首先,我们需要理解JMS的核心概念。JMS提供两种消息模型:点对点(Point-to-Point)和发布/订阅...
### SOAP over JMS协议详解 #### 引言 在IBM WebSphere Application Server产品中,Web服务引擎支持通过符合JMS标准的消息传输协议(作为HTTP的替代方案)来在客户端与服务器之间交换SOAP消息。本文档旨在详细介绍...
IBM WebSphere MQ 是一种基于消息队列的中间件,用于实现不同的应用程序之间的异步通信。下面是对 IBM WebSphere MQ 的入门教程的总结,涵盖了 WebSphere MQ 的原理、体系结构、重要特点和应用场景等方面的知识点。 ...
6. **API与开发**:WebSphere MQ提供了丰富的编程接口,包括Java、C、C++等,开发者可以使用这些接口编写应用程序,实现与消息队列的交互。 7. **最佳实践**:为了确保系统稳定和性能,建议定期备份配置,监控队列...
本文将深入探讨一个基于WebSphere MQ的简单Java Message Service (JMS) 实例,帮助你理解如何在实际项目中实现消息的发送。 首先,我们需要了解JMS。JMS是Java平台上的一个标准接口,它定义了用于在分布式环境中...
标题中的“基于Websphere MQ持久化消息实现异步转同步—方案二”是指在分布式系统中,通过使用Websphere MQ(WebSphere Message Broker,一种消息中间件)来处理异步通信,并通过消息的持久化特性,确保消息在异常...
* 架构说明:WebSphere MQ 的架构基于消息队列,能够实现高效、可靠和灵活的消息传递。 产品功能特性 WebSphere MQ 的产品功能特性包括: * 增强了订阅/发布的易用性:WebSphere MQ 支持订阅/发布式的消息传递,...
Linux 上的 WebSphere MQ 开发快速入门 本文将介绍如何在 Linux 上安装和配置 WebSphere MQ,以及如何使用 Java 应用程序开发 MQ ...通过示例应用程序,读者可以了解如何使用 WebSphere MQ 实现可靠的消息队列处理。
3. **编程接口**:了解如何使用各种编程语言(如Java的JMS API,C的API等)与WebSphere MQ交互。 4. **管理和监控**:学习如何配置、管理和监控WebSphere MQ环境,包括性能监控、故障排查和日志分析。 5. **安全性...
com.ibm.mq.axis2.jar com.ibm.mq.soap.jar com.ibm.mq.commonservices.jar com.ibm.mq.tools.ras.jar com.ibm.mq.defaultconfig.jar com.ibm.mq.traceControl.jar com.ibm.mq.headers.jar com.ibm.mq.jmqi.jar ...
这些 JAR 文件位于 `WebSphere MQ\java\lib` 目录下,是开发、配置和运行与 WebSphere MQ 集成的应用程序所必需的。 1. **WebSphere MQ 概述**: WebSphere MQ(原名 MQSeries)是 IBM 提供的一种企业级的消息队列...
6. 简化的使用和配置:v7版本特别强化了易用性,新的图形化客户端配置工具,如基于Eclipse的WebSphere MQ Explorer,大大简化了配置过程。 7. 跨平台支持:能够运行在多种操作系统之上,支持企业内部的异构计算环境...
- **消息模型**:WebSphere MQ基于发布/订阅和点对点两种消息传递模式。发布/订阅模式下,生产者发布消息到主题,消费者订阅特定主题接收消息;点对点模式则通过队列实现,消息被发送到队列,一个或多个接收者可以...
Websphere MQ的原理是基于异步通信的机制,使用消息队列来实现不同应用程序之间的数据交换。Websphere MQ的体系结构主要包括三个部分: * 消息队列(Message Queue):用于存储和转发消息的队列 * Queue Manager...
本电子书详细介绍了jms ,mq 的java编程,希望对有需要的朋友有所帮助。
在本文中,我们将深入探讨如何使用C#编程语言与IBM WebSphere MQ进行交互,实现消息的发送和接收。IBM WebSphere MQ(前身为MQSeries)是一种企业级的消息中间件,它提供了一种可靠且可扩展的方式,使得应用程序可以...
2. **WebSphere MQ JMS**:这是一种基于 Java 消息服务 (JMS) 的高级接口,它提供了一种更为抽象的方式来处理消息。JMS 是一个 Java 平台中的标准,允许应用程序向消息服务器发送消息,而无需关心底层的消息传递机制...