首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

CXF学习札记-让通过参数传递数据

2012-11-08 
CXF学习笔记---让通过参数传递数据整整折腾了3天终于通过CXF进行参数传递了。CXF的文档和sample都是存在问

CXF学习笔记---让通过参数传递数据
整整折腾了3天终于通过CXF进行参数传递了。CXF的文档和sample都是存在问题的。这么一些简单的常用内容,硬是找不着。opensource的弊病。
目地:
通过webservice传递值以及错误信息。true:取result值,false:取errorNum和errorMsg

【Server】
1、Interface

@WebServicepublic interface DatasetExcute {//List<TableDataInfo> excuteSql(String sql);String excuteSqlWithReturnXml(String sql);//Document excuteSqlWithReturnDoc(String sql);public boolean excuteSqlWithReturnDocAndMsg(@WebParam(name = "excuteSql",  header = true,mode = WebParam.Mode.IN)String sql, @WebParam(name = "excuteResult", targetNamespace = "",mode = WebParam.Mode.OUT)javax.xml.ws.Holder<java.lang.String> result, @WebParam(name = "errorNumber", targetNamespace = "", mode = WebParam.Mode.OUT)javax.xml.ws.Holder<java.lang.String> errorNumber, @WebParam(name = "errorMsg", targetNamespace = "", mode = WebParam.Mode.OUT)javax.xml.ws.Holder<java.lang.String> errorMsg);}

2.impletement文件
@WebService(endpointInterface = "com.tnt.mms.webservice.DatasetExcute")public class DatasetExcuteImpl implements DatasetExcute {private NativeDAO nativeDAO;public void setNativeDAO(NativeDAO nativeDAO) {this.nativeDAO = nativeDAO;}//// public List<TableDataInfo> excuteSql(String sql) {//  //// List<TableDataInfo> ret=nativeDAO.bulkOperationWithReturnAndFields(sql);// return ret;//// }public String excuteSqlWithReturnXml(String sql) {String xmlRet = nativeDAO.bulkOperationWithReturnXml(sql);return xmlRet;}public Document excuteSqlWithReturnDoc(String sql) {Document xmlRet = nativeDAO.bulkOperationWithReturnDoc(sql);return xmlRet;}public boolean excuteSqlWithReturnDocAndMsg(String sql,javax.xml.ws.Holder<java.lang.String> result,javax.xml.ws.Holder<java.lang.String> errorNumber,javax.xml.ws.Holder<java.lang.String> errorMsg) {boolean blnReturn = false;try {result.value = nativeDAO.bulkOperationWithReturnXml(sql);blnReturn = true;} catch (Exception e) {errorNumber.value = "ES0001";errorMsg.value = "Database Error!";}return blnReturn;}}


3、描述文件
<jaxws:endpoint id="DatasetExcute"implementoraddress="/DatasetExcute"><!-- 用参数传递,就不要用aegis<jaxws:serviceFactory><ref bean="jaxws-and-aegis-service-factory" /></jaxws:serviceFactory>--></jaxws:endpoint>


【client test】
public final class Client_DbExcute {private Client_DbExcute() {}public static void main(String args[]) throws Exception {// START SNIPPET: clientClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "com/tnt/mms/webservice/client/client-DbExcute.xml" });try {DatasetExcute client = (DatasetExcute) context.getBean("client");// List<TableDataInfo> list=null;// list = client.excuteSql("select* from vendor");// String list = client.excuteSqlWithReturnXml("select* from vendor// where vendorID like '111%'");// Document list = client// .excuteSqlWithReturnDoc("select* from vendor where vendorID like// '111%'");.StringBuffer sql = new StringBuffer();sql.append("if object_id('tempdb..#UOM150232076') is not null begin");sql.append(" drop table #UOM150232076    ");sql.append(" end");sql.append("  begin tran");sql.append(" select distinct itemid, pack, EngUOM as UOM,");sql.append("coalesce(ManualWeight,0) as ManualWeight, coalesce(GST,0) as GST,");sql.append("        ' ' as flag, getdate() as chgtime, '754410' as chgby");sql.append(" into #UOM150232076");sql.append("  from [tntdb150].RIS_test.dbo.Pos");sql.append("  where itemid = '663247'");sql.append(" order by pack");sql.append(" if @@ROWCOUNT=0");sql.append("  insert into #UOM150232076 (  itemid , pack          ,  UOM,");sql.append("ManualWeight, GST, flag,   chgtime,      chgby)");sql.append("           values('663247', 1000 * 0 + 1.0, 'ea',");sql.append("0,   0,  ' ', getdate(), '754410')");sql.append(" select * from #UOM150232076");sql.append(" if @@error <> 0");sql.append("    rollback tran");sql.append(" else");sql.append("   commit tran");//Document list = client//.excuteSqlWithReturnDoc("select* from vendor where vendorID='10118'");        //Document list = client//.excuteSqlWithReturnDoc(sql.toString());//list.getFirstChild().getTextContent();//XmlUtil.save(list, "c:/test.xml");//String list1= "";//String  errorNumber="", errorMsg = "";Holder<String> list1=new Holder<String>();Holder<String> errorNumber=new Holder<String>();Holder<String> errorMsg=new Holder<String>();boolean ret=client.excuteSqlWithReturnDocAndMsg("select * from vendor where vendorID like '111%'", list1, errorNumber, errorMsg);if(ret){System.out.println("result: "+ list1+":"+list1.value);XmlUtil.writeXml(list1.value, "c:/ls.xml");}else{System.out.println("Error: "+ errorNumber.value+":"+errorMsg.value);}System.exit(0);// END SNIPPET: client} catch (Exception e) {e.printStackTrace();System.out.println("error: " + e.getMessage());}}}


2.配置文件
<?xml version="1.0" encoding="UTF-8"?><!--Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the"License"); you may not use this file except in compliancewith the License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing,software distributed under the License is distributed on an"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANYKIND, either express or implied. See the License for thespecific language governing permissions and limitationsunder the License.--><!-- START SNIPPET: beans --><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:jaxws="http://cxf.apache.org/jaxws"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsdhttp://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd"><!-- Configure CXF to use Aegis data binding instead of JAXB --><bean id="aegisBean"/><bean id="jaxwsAndAegisServiceFactory"ref="aegisBean" /><property name="serviceConfigurations"><list><bean/><bean/><bean/></list></property></bean><bean id="client" factory-method="create" /><bean id="clientFactory"/><property name="address"value="http://localhost:8080/extjsmms/services/DatasetExcute" /><!--  --><property name="serviceFactory"ref="jaxwsAndAegisServiceFactory" /></bean></beans><!-- END SNIPPET: beans -->


【总结】
1.当用到参数传递值时千万不要用acegi,不知道bug否,xfire的时候就发现有这个问题现在也未解决。
2.后续要认真研究aegis,没准能找到问题。

热点排行