OFBIZ webservice简介

 

Opentaps(OFBiz 9.04之后)中webservice用的是AXIS2,最开始自己在网上搜了好多资料,自己拿回来测试,发现都不对。后自己再找了下AXIS的资料说,那种报错很有可能是由于两个版本不对引起的,所以就决定看看OFBiz里面用的是哪个版本,当时我彻底无语了,里面两个版本的包竟然都有,真不知道是什么意思。但是我认为应该是AXIS2,OFBiz这么与时俱进的东西,应该不太可能用06年就不更新的架包。

废话少说,直接说开发步骤吧:

一:在项目中引入AXIS2,由于AXIS2的依赖包好几个,客户端应该不需要那么多,但是以防万一,我们把AXIS2下面lib目录的所有jar包一并加入到开发工程的classpath下。

 

 

 

二:开发webservice必须知道wsdl才能比较好的。首先我们在OFBiz中打开一个service,让它能被发不成webservice。这个非常简单,在OFBiz中你只要在service定义的xml中,把要发布的service添加一个属性export=”true”,重启服务就能看到。下面以一个实例来说明:

<!--[if !supportLists]-->① <!--[endif]-->:我们找到application/order/servicedef/services.xml文件,打开找到最后一个service,这里有个自带的SOAP测试服务,我们添加一个service,export="true"加上去,最后变成:

 

方法java代码为:

 

<!--[if !supportLists]-->② <!--[endif]-->:现在只是发布了,但是我们必须要知道怎样请求才能得到这个服务,ofbiz提供了一个event来处理它,就是<handler name="soap" type="request" class="org.ofbiz.webapp.event.SOAPEventHandler"/>,要使用它,你必须把这个定义在你的controller.xml文件中,当然,如果你已经引入了<include location="component://common/webcommon/WEB-INF/common-controller.xml"/>,那么就不需要了,这个里面已经定义好了。直接使用就行了。

 

<!--[if !supportLists]-->③ <!--[endif]-->重启服务,在浏览器中输入

http://localhost:8080/ordermgr/control/SOAPServices/testSoap?wsdl,如果你看到了你刚才发布的服务,说明已经成功。如下图:

 

三:客户端编写。

客户端代码编写最主要是要知道服务端想要的是什么东西,首先我们的服务类的定义我们可以看到是需要一个输入输出,一个输入,三个输出的,也就是两个进,两个出。在wsdl中我们可以看到

 

 

说明我们需要传入的是一个map-Map形式的Model,并且salt和userid是必须的。由于我们没有设置验证信息,所以login.username和login.password是可以不需要的。直接上代码比较好一些。

在测试的时候我仅仅弄了一个很简单的例子,由于axiom比较复杂,还要详细研究下。类说明:ClientGenricValue,封装的是要传入数据的类型,键key和值。ClientUtil

package com.wx;

 

public class ClientGenericValue {

 

private String type;

private String key;

private String value;

public String getType() {

return type;

}

public void setType(String type) {

this.type = type;

}

public String getKey() {

return key;

}

public void setKey(String key) {

this.key = key;

}

public String getValue() {

return value;

}

public void setValue(String value) {

this.value = value;

}

 

 

}

 

 

package com.wx;

 

import java.util.List;

 

import org.apache.axiom.om.OMAbstractFactory;

import org.apache.axiom.om.OMElement;

import org.apache.axiom.om.OMFactory;

import org.apache.axiom.om.OMNamespace;

import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.client.ServiceClient;

 

public class ClientUtil {

 

private static OMFactory factory = OMAbstractFactory.getOMFactory();

private String endPoint;

private List<ClientGenericValue> valueList;

private String om;

private String serviceName;

 

public ClientUtil(String endPoint, String serviceName , String om,

List<ClientGenericValue> valueList) {

this.endPoint = endPoint;

this.serviceName = serviceName;

this.om = om;

this.valueList = valueList;

}

 

 

 

public ServiceClient createClient() throws AxisFault {

ServiceClient client = new ServiceClient();

Options options = new Options();

 

EndpointReference targetERP = new EndpointReference(endPoint); //定义目的EndpointReference,就是服务地址

options.setTo(targetERP);

options.setTimeOutInMilliSeconds(400000); //定义超时,这里可以不定义

 

client.setOptions(options);

return client;

}

 

public OMElement send() throws AxisFault{

OMNamespace ns = factory.createOMNamespace("http://ofbiz.apache.org/service/", serviceName);

OMElement root = factory.createOMElement(serviceName, ns);

 

OMElement data = factory.createOMElement("map-HashMap", null);

root.addChild(data);

for(ClientGenericValue value : valueList){

OMElement mapKey = factory.createOMElement("map-Entry", null);

 

OMElement keyElement = factory.createOMElement("map-Key", null);

OMElement keyValue = factory.createOMElement("std-String", null);

keyValue.addAttribute(factory.createOMAttribute("value", null, value.getKey()));

keyElement.addChild(keyValue);

 

 

OMElement valueElement = factory.createOMElement("map-Value", null);

OMElement valueValue = factory.createOMElement(value.getType(), null);

valueValue.addAttribute(factory.createOMAttribute("value", null, value.getValue()));

valueElement.addChild(valueValue);

 

mapKey.addChild(keyElement);

mapKey.addChild(valueElement);

 

data.addChild(mapKey);

}

System.out.println(root);

OMElement result = createClient().sendReceive(root);

return result;

}

 

 

 

public String getEndPoint() {

return endPoint;

}

 

public void setEndPoint(String endPoint) {

this.endPoint = endPoint;

}

 

}

 

package com.wx;

 

import java.util.ArrayList;

import java.util.List;

 

import org.apache.axiom.om.OMElement;

import org.apache.axis2.AxisFault;

 

public class ClientTest {

 

/**

* @param args

* @throws AxisFault

*/

public static void main(String[] args) {

String endPoint = "http://localhost:8080/ordermgr/control/SOAPServices/testSoap";

String serviceName = "testSoap";

String om = "http://ofbiz.apache.org/service/";

List<ClientGenericValue> valueList = getTestData();

 

 

ClientUtil cu = new ClientUtil(endPoint, serviceName, om, valueList);

 

try {

OMElement result = cu.send();

System.out.println("Sent Hello, got : " + result.toString());

} catch (AxisFault e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

 

}

 

public static List<ClientGenericValue> getTestData(){

List<ClientGenericValue> valueList = new ArrayList<ClientGenericValue>();

ClientGenericValue value1 = new ClientGenericValue();

value1.setType("std-String");

value1.setKey("userid");

value1.setValue("11111");

 

ClientGenericValue value2 = new ClientGenericValue();

value2.setType("std-String");

value2.setKey("salt");

value2.setValue("The power of OFBiz");

 

// ClientGenericValue value3 = new ClientGenericValue();

// value3.setType("eeval-OrderItemTypeAttr");

// value3.setKey("testing");

// value3.setValue("org.ofbiz.entity.GenericValue"); //这个可以不用填写的

 

valueList.add(value1);

valueList.add(value2);

// valueList.add(value3);

return valueList;

}

}

 

转载于:https://www.cnblogs.com/Ivan-j2ee/archive/2012/12/12/2813920.html

转 OFBIZ webservice简介相关推荐

  1. Webservice简介

    简介 RPC(Remote Procedure Call,远程过程调用),通常包含两个部分,序列化和通信协议. 常用序列化协议包括json,xml,hession,protobuf,thrift,te ...

  2. webservice 简介 跨编程语言 跨操作系统 远程调用技术

    目录 引子 WebService 特点介绍 WebService 到底是什么? 为什么需要使用 WebService WebService 体系结构 WebService 三种基本元素之 SOAP W ...

  3. 一 WebService 简介

    WebService 实现 SOAP REST SOAP的实现: Apache SOAP soap的首个实现,一种过时的SOAP实现,Windchill开发时使用 Apache AXIS 一种过时的S ...

  4. 浅谈WebService的调用转

    0.前言 前段时间,公司和电信有个合作,产品对接电信的某个平台,使用了WebService接口的调用,实现了业务受理以及单点登录.终于使用到了WebService,楼主还是比较兴奋的,目前功能已经上线 ...

  5. WebService技术详解CXF

    WebService WebService简介 Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Servic ...

  6. Android使用ksoap2调用C#中的webservice实现图像上传

    目录: 一. android使用ksoap2调用webservice 二. 异步调用 三. Android使用ksoap2调用C#中的webservice实现图像上传参考方法 四. 图像传输中Base ...

  7. Java直接AXIS调用远程WebService

    最近项目中需要BPM系统远程调用MESS接口(WebService类型),特此记录资料如下. 一.WebService简介 Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的 ...

  8. WebService入门学习一

    参考:https://blog.csdn.net/c99463904/article/details/76018436 1.WebService简介? Web Service技术, 能使得运行在不同机 ...

  9. Java远程调用WebService接口

    WebService简介 Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间, ...

最新文章

  1. PHP数据库连接池SQL Relay安装使用
  2. 一文看懂集成学习(详解 bagging、boosting 以及他们的4点区别)
  3. LeetCode Range Addition II
  4. Python基础综合练习
  5. 开源一个ShellCode生成框架
  6. 2、MySQL错误日志(Error Log)详解
  7. MySQL索引优化实战
  8. C语言简易行编辑器,简单的行编辑器C语言.doc
  9. java synchronized 关键字(1)对象监视器为Object
  10. c#获取对象的唯一标识_DDD领域驱动设计实战 - 创建实体身份标识的常用策略
  11. 信息学奥赛一本通 1154:亲和数
  12. win10安装python3_win10 64位肿么安装python3.x
  13. 函数式编程,我心中的 C 位!
  14. 全国计算机二级基础知识ppt,有关全国计算机二级基础知识.ppt
  15. ②⓪②⓪ → ②⓪②①
  16. 电路基础和电路模拟——复习
  17. Wind的实时行情API使用
  18. 【实验室顾问】俞扬教授 (CCF-IEEE CS青年科学家奖获得者)
  19. 英文网站建设应该如何做?如何建好一个英文网站?
  20. MNN源码阅读之模型转换

热门文章

  1. 数据库备份DBS商业化发布
  2. Fedex Ship Manager Software安装
  3. Console-算法[for]-国王与老人的六十四格
  4. “西邮漫记”--自由照耀中国
  5. TCP/IP、Http的区别
  6. git push --no-thin
  7. linux实例 批量修改图片文件名
  8. Extracting Text From Image
  9. Stimulsoft reports .net中创建变量
  10. sendBroadcast与sendStickyBroadcast的区别