加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

将ofbiz的Service导出为webservice及其调用的实例

发布时间:2020-12-17 00:56:31 所属栏目:安全 来源:网络整理
导读:Service定义: service name="test.add" engine="java" auth=" true " export=" true "? ? ?? ?location="org.aries.erp.practice.TestServices"? ? ?? ?invoke="add" ? ?? attribute name="a" type="Integer" mode="IN" optional="false" /attribute ? ?? a
Service定义:
<service name="test.add" engine="java" auth=" true" export=" true"?
? ?? ?location="org.aries.erp.practice.TestServices"?
? ?? ?invoke="add">
? ?? <attribute name="a" type="Integer" mode="IN" optional="false" ></attribute>
? ?? <attribute name="b" type="Integer" mode="IN" optional="false"></attribute>
? ?? <attribute name="result" type="Integer" mode="OUT" optional="false"></attribute>
? ? </service>

Service代码:

? ? ? ?public static Map<String,Object> add(DispatchContext dctx,Map<String,Object> context){

Map<String,Object> resultMap = ServiceUtil.returnSuccess();
Integer a = (Integer) context.get("a");
Integer b = (Integer) context.get("b");
resultMap.put("result",a + b);
return resultMap;
}


调用其服务的代码:

? ? ? ? XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
? ? ? ? config.setServerURL(new URL(" http://127.0.0.1:8080/webtools/control/xmlrpc"));
? ? ? ? config.setEnabledForExceptions(true);
? ? ? ? config.setEnabledForExtensions(true);

? ? ? ? XmlRpcClient client = new XmlRpcClient();
? ? ? ? client.setConfig(config);

? ? ? ? Map paramMap = new HashMap();
? ? ? ? paramMap.put("a",3); ? ? ? ? ? ? ? ? ? ? //参数
? ? ? ? paramMap.put("b",5); ? ? ? ? ? ? ? ? ? ? //参数
? ? ? ? paramMap.put("login.username","admin"); ? ? ? ? ?//用户名
? ? ? ? paramMap.put("login.password","ofbiz"); ? ? ? ? ? ?//密码

? ? ? ? Object[] params = new Object[]{paramMap};

? ? ? ? Map result = (Map) client.execute(" test.add",params);

? ? ? ? System.out.println(result.toString());

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读