如何将ofbiz的服务暴露成webservice,并且利用soapui测试

理解本文之前需要了解以下几个东西:

ofbiz的服务定义和实现,webservice的含义和简单理解wsdl文件,soapui的简单使用

1.首先定义一个服务,并且在服务定义中增加一个export为true的属性,这样这个服务就暴露成webservice了

<service engine="java" name="TestSoap" location="com.sunyard.cpsp.ofbiztemplate.OfbizTemplateService" invoke="testSoap"
			export="true">
		<description>这是一个暴露成webservice的服务,java实现中有利用soapui测试的详细介绍</description>
		<attribute name="attr1" mode="INOUT" type="String"></attribute>
		<attribute name="attr2" mode="INOUT" type="Map"></attribute>
		<attribute name="attr3" mode="INOUT" type="Double"></attribute>
	</service>

2.写好这个服务的实现,我们这里采用的是java

public static Map<String, Object> testSoap(DispatchContext dctx,Map<String, Object> context){
		/**介绍如何结合soapui测试这个服务*/
		/*
		 * 1.浏览器中输入http://localhost:8080/webtools/control/SOAPService?wsdl可以查看所有ofbiz暴露成webservice的服务
		 * 2.选择TestSoap浏览器地址跳转到http://localhost:8080/webtools/control/SOAPService/TestSoap?wsdl这就是TestSoap的
		 * wsdl文件
		 * 3.在soapui中建立一个工程initil WSDL填上第二点中的wsdl文件(可以直接填这个地址)
		 * 4.soapui中的第一个request中填入合法的参数数据,详情参考http://meilv.iteye.com/blog/1317112
		 */
		
		Map<String, Object> result = ServiceUtil.returnSuccess("成功运行TestSoap服务");
		result.putAll(context);
		return result;
	}

 3.按照服务实现中注释查看ofbiz为每个服务生产的wsdl文件

 为什么地址是webtools模块下面的地址?那是因为在webtools的control中有下面这样一个request,所以使用这样一个地址来暴露webservice。因为这个request中的event类型是soap,所以control中一定要引用了soap这个handler

<request-map uri="SOAPService">
        <event type="soap"/>
        <response name="error" type="none"/>
        <response name="success" type="none"/>
</request-map>

4.soapui的request中的数据格式如下。实际上就是将context中的内容用xml表示了出来。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://ofbiz.apache.org/service/">
   <soapenv:Header/>
   <soapenv:Body>
      <ser:TestSoap>
         <map-Map>
            <!-- Map中的一个元素,其中key为String类型,value也为String类型-->
	<ser:map-Entry>
               <ser:map-Key>
                  <ser:std-String value="attr1"/>
               </ser:map-Key>
               <ser:map-Value>
                  <ser:std-String value="attr1"/>
               </ser:map-Value>
            </ser:map-Entry>
	<!-- Map中的一个元素,其中key为String类型,value也为Map类型-->   
	 <ser:map-Entry>
		<ser:map-Key>
			<ser:std-String value="attr2"/>
		</ser:map-Key>
		<ser:map-Value>
			<ser:map-Map>
				<ser:map-Entry>
               				<ser:map-Key>
                  				<ser:std-String value="attr21"/>
              				</ser:map-Key>
              				 <ser:map-Value>
                		 		 <ser:std-String value="attr21"/>
            		 		  </ser:map-Value>
           			 </ser:map-Entry>
			</ser:map-Map>
               </ser:map-Value>
	   </ser:map-Entry>
	<!-- Map中的一个元素,其中key为String类型,value也为Double类型-->
	  <ser:map-Entry>
               <ser:map-Key>
                  <ser:std-String value="attr3"/>
               </ser:map-Key>
               <ser:map-Value>
                  <ser:std-Double value="20"/>
               </ser:map-Value>
            </ser:map-Entry>
         </map-Map>
      </ser:TestSoap>
   </soapenv:Body>
</soapenv:Envelope>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值