日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

转 OFBIZ webservice简介

發(fā)布時(shí)間:2023/12/20 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 转 OFBIZ webservice简介 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

OFBIZ webservice簡(jiǎn)介

?

Opentaps(OFBiz 9.04之后)中webservice用的是AXIS2,最開(kāi)始自己在網(wǎng)上搜了好多資料,自己拿回來(lái)測(cè)試,發(fā)現(xiàn)都不對(duì)。后自己再找了下AXIS的資料說(shuō),那種報(bào)錯(cuò)很有可能是由于兩個(gè)版本不對(duì)引起的,所以就決定看看OFBiz里面用的是哪個(gè)版本,當(dāng)時(shí)我徹底無(wú)語(yǔ)了,里面兩個(gè)版本的包竟然都有,真不知道是什么意思。但是我認(rèn)為應(yīng)該是AXIS2,OFBiz這么與時(shí)俱進(jìn)的東西,應(yīng)該不太可能用06年就不更新的架包。

廢話(huà)少說(shuō),直接說(shuō)開(kāi)發(fā)步驟吧:

一:在項(xiàng)目中引入AXIS2,由于AXIS2的依賴(lài)包好幾個(gè),客戶(hù)端應(yīng)該不需要那么多,但是以防萬(wàn)一,我們把AXIS2下面lib目錄的所有jar包一并加入到開(kāi)發(fā)工程的classpath下。

?

?

?

二:開(kāi)發(fā)webservice必須知道wsdl才能比較好的。首先我們?cè)贠FBiz中打開(kāi)一個(gè)service,讓它能被發(fā)不成webservice。這個(gè)非常簡(jiǎn)單,在OFBiz中你只要在service定義的xml中,把要發(fā)布的service添加一個(gè)屬性export=”true”,重啟服務(wù)就能看到。下面以一個(gè)實(shí)例來(lái)說(shuō)明:

<!--[if !supportLists]-->① <!--[endif]-->:我們找到application/order/servicedef/services.xml文件,打開(kāi)找到最后一個(gè)service,這里有個(gè)自帶的SOAP測(cè)試服務(wù),我們添加一個(gè)service,export="true"加上去,最后變成:

?

方法java代碼為:

?

<!--[if !supportLists]-->② <!--[endif]-->:現(xiàn)在只是發(fā)布了,但是我們必須要知道怎樣請(qǐng)求才能得到這個(gè)服務(wù),ofbiz提供了一個(gè)event來(lái)處理它,就是<handler name="soap" type="request" class="org.ofbiz.webapp.event.SOAPEventHandler"/>,要使用它,你必須把這個(gè)定義在你的controller.xml文件中,當(dāng)然,如果你已經(jīng)引入了<include location="component://common/webcommon/WEB-INF/common-controller.xml"/>,那么就不需要了,這個(gè)里面已經(jīng)定義好了。直接使用就行了。

?

<!--[if !supportLists]-->③ <!--[endif]-->重啟服務(wù),在瀏覽器中輸入

http://localhost:8080/ordermgr/control/SOAPServices/testSoap?wsdl,如果你看到了你剛才發(fā)布的服務(wù),說(shuō)明已經(jīng)成功。如下圖:

?

三:客戶(hù)端編寫(xiě)。

客戶(hù)端代碼編寫(xiě)最主要是要知道服務(wù)端想要的是什么東西,首先我們的服務(wù)類(lèi)的定義我們可以看到是需要一個(gè)輸入輸出,一個(gè)輸入,三個(gè)輸出的,也就是兩個(gè)進(jìn),兩個(gè)出。在wsdl中我們可以看到

?

?

說(shuō)明我們需要傳入的是一個(gè)map-Map形式的Model,并且salt和userid是必須的。由于我們沒(méi)有設(shè)置驗(yàn)證信息,所以login.username和login.password是可以不需要的。直接上代碼比較好一些。

在測(cè)試的時(shí)候我僅僅弄了一個(gè)很簡(jiǎn)單的例子,由于axiom比較復(fù)雜,還要詳細(xì)研究下。類(lèi)說(shuō)明:ClientGenricValue,封裝的是要傳入數(shù)據(jù)的類(lèi)型,鍵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,就是服務(wù)地址

options.setTo(targetERP);

options.setTimeOutInMilliSeconds(400000); //定義超時(shí),這里可以不定義

?

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"); //這個(gè)可以不用填寫(xiě)的

?

valueList.add(value1);

valueList.add(value2);

// valueList.add(value3);

return valueList;

}

}

?

轉(zhuǎn)載于:https://www.cnblogs.com/Ivan-j2ee/archive/2012/12/12/2813920.html

總結(jié)

以上是生活随笔為你收集整理的转 OFBIZ webservice简介的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。