`
erichua
  • 浏览: 516766 次
  • 性别: Icon_minigender_2
  • 来自: 远方
社区版块
存档分类
最新评论

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

    博客分类:
  • JAVA
阅读更多
整整折腾了3天终于通过CXF进行参数传递了。CXF的文档和sample都是存在问题的。这么一些简单的常用内容,硬是找不着。opensource的弊病。
目地:
通过webservice传递值以及错误信息。true:取result值,false:取errorNum和errorMsg

【Server】
1、Interface
@WebService
public 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"
		implementorClass="com.tnt.mms.webservice.DatasetExcuteImpl"
		implementor="#DatasetExcuteImpl" address="/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: client
		ClassPathXmlApplicationContext 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 one
	or more contributor license agreements. See the NOTICE file
	distributed with this work for additional information
	regarding copyright ownership. The ASF licenses this file
	to you under the Apache License, Version 2.0 (the
	"License"); you may not use this file except in compliance
	with the License. You may obtain a copy of the License at
	
	http://www.apache.org/licenses/LICENSE-2.0
	
	Unless 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 ANY
	KIND, either express or implied. See the License for the
	specific language governing permissions and limitations
	under 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.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">
	<!-- Configure CXF to use Aegis data binding instead of JAXB -->
	<bean id="aegisBean"
		class="org.apache.cxf.aegis.databinding.AegisDatabinding"
		scope="prototype" />
	<bean id="jaxwsAndAegisServiceFactory"
		class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
		scope="prototype">
		<property name="dataBinding" ref="aegisBean" />
		<property name="serviceConfigurations">
			<list>
				<bean
					class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration" />
				<bean
					class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration" />
				<bean
					class="org.apache.cxf.service.factory.DefaultServiceConfiguration" />
			</list>
		</property>
	</bean>
	<bean id="client" class="com.tnt.mms.webservice.DatasetExcute"
		factory-bean="clientFactory" factory-method="create" />

	<bean id="clientFactory"
		class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
		<property name="serviceClass"
			value="com.tnt.mms.webservice.DatasetExcute" />
		<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,没准能找到问题。
0
0
分享到:
评论
1 楼 futoviny 2017-04-28  
挺有用的   javax.xml.ws.Holder

相关推荐

    cxf-rt-rs-client-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-rs-client-3.0.1.jar; 赠送原API文档:cxf-rt-rs-client-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-client-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-rs-client-3.0.1.pom; 包含...

    cxf-rt-frontend-jaxrs-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-frontend-jaxrs-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxrs-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxrs-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxrs...

    cxf-rt-transports-http-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-transports-http-3.0.1.jar; 赠送原API文档:cxf-rt-transports-http-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-transports-http-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-transports-...

    cxf-rt-frontend-simple-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-frontend-simple-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-simple-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-simple-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-...

    cxf-rt-frontend-jaxws-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-frontend-jaxws-3.0.1.jar; 赠送原API文档:cxf-rt-frontend-jaxws-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-frontend-jaxws-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-frontend-jaxws...

    cxf-rt-bindings-soap-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-bindings-soap-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-soap-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-soap-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-soap-...

    cxf-core-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-core-3.0.1.jar; 赠送原API文档:cxf-core-3.0.1-javadoc.jar; 赠送源代码:cxf-core-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-core-3.0.1.pom; 包含翻译后的API文档:cxf-core-3.0.1-...

    cxf-rt-frontend-jaxws-3.0.16.jar 下载

    cxf-rt-frontend-jaxws-3.0.16.jar jar包下载3.0.16版本下载

    cxf-rt-bindings-xml-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-bindings-xml-3.0.1.jar; 赠送原API文档:cxf-rt-bindings-xml-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-bindings-xml-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-bindings-xml-3.0.1....

    cxf-rt-rs-extension-providers-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-rs-extension-providers-3.0.1.jar; 赠送原API文档:cxf-rt-rs-extension-providers-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-rs-extension-providers-3.0.1-sources.jar; 赠送Maven依赖信息...

    cxf-rt-ws-addr-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-ws-addr-3.0.1.jar; 赠送原API文档:cxf-rt-ws-addr-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-ws-addr-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-ws-addr-3.0.1.pom; 包含翻译后的API...

    cxf.xml,cxf-servlet.xml,cxf-extension-soap.xml

    &lt;import resource="classpath:META-INF/cxf/cxf.xml"/&gt; &lt;import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/&gt; &lt;import resource="classpath:META-INF/cxf/cxf-servlet.xml"/&gt;

    cxf-rt-databinding-jaxb-3.0.1-API文档-中文版.zip

    赠送jar包:cxf-rt-databinding-jaxb-3.0.1.jar; 赠送原API文档:cxf-rt-databinding-jaxb-3.0.1-javadoc.jar; 赠送源代码:cxf-rt-databinding-jaxb-3.0.1-sources.jar; 赠送Maven依赖信息文件:cxf-rt-...

    cxf-dosgi-ri-singlebundle-distribution-1.4.0.jar

    cxf-dosgi-ri-singlebundle-distribution-1.4.0.jar

    apache-cxf-2.7.18-src.zip 源码

    源码包"apache-cxf-2.7.18-src.zip"包含了CXF框架的核心组件和相关模块,是深入理解CXF工作原理和进行定制开发的重要资源。 CXF主要由以下几个核心部分组成: 1. **Bus**:CXF的总线(Bus)是其核心组件,它管理...

    cxf-rt-transports-http-jetty-3.0.2.zip

    标题 "cxf-rt-transports-http-jetty-3.0.2.zip" 指的是Apache CXF项目的一个特定版本的HTTP-Jetty传输模块。Apache CXF是一个流行的开源框架,用于构建和开发服务导向架构(SOA)和RESTful Web服务。这个版本,...

    apache-cxf-2.3.5-src.zip

    这个"apache-cxf-2.3.5-src.zip"文件是一个源代码压缩包,包含了Apache CXF 2.3.5版本的全部源码,这对于开发者深入理解其内部工作原理、进行定制化开发或调试是非常有价值的。 Apache CXF的核心功能包括: 1. **...

    cxfWebservice客户端全部jar包及极简调用方法.rar

    cxf-core-3.0.0.jar,cxf-rt-bindings-soap-3.0.0.jar,cxf-rt-databinding-jaxb-3.0.0.jar,cxf-rt-frontend-jaxws-3.0.0.jar,cxf-rt-frontend-simple-3.0.0.jar,cxf-rt-transports-http-3.0.0.jar,cxf-rt-...

    cxf-core-3.1.16.jar

    cxf-core-3.1.16版本jar包,用于java开发使用

    apache-cxf-3.1.1跟3.1.6所有jar包

    此外,还有其他如`cxf-rt-bindings-soap.jar`、`cxf-rt-databinding-jaxb.jar`、`cxf-rt-rs-extension-providers.jar`等,它们分别对应于不同的功能,如SOAP绑定、JAXB数据绑定和RESTful服务的提供者扩展。...

Global site tag (gtag.js) - Google Analytics