soapUI模拟外部request请求 通过CI 操作组件
基本流程:创建消息(包括请求消息和响应消息),服务,服务操作, 创建package class ,使用soapUI 模拟外部request请求
步骤
创建消息。请求消息使用原有的头表和明细表维护,而响应消息需要新建表维护。
创建 接口响应消息表 record 命名为:ZL_INT_ORD_RST ,向其中添加两个field,ZL_ORDERID和 MESSAGE_TEXT,并设置ZL_ORDERID为key,search key ,list box item。
在PS系统:主菜单–PeopleTools–集成代理程序–集成设置–消息目录下,添加新值。
订单请求消息目录:①类型选择:行集合 ②名称:ZL_REQ_MESAG ③版本:V1
描述:订单请求消息目录。向根节点添加记录:
订单响应消息目录:①类型选择:行集合 ②名称:ZL_RESP_MESAGE ③版本:V1
描述:订单响应消息目录。向根节点添加记录:
创建 服务 与 服务操作。
在PS系统:主菜单–PeopleTools–集成代理程序–集成设置–服务目录下,添加新值。
在PS系统:主菜单–PeopleTools–集成代理程序–集成设置–服务操作目录下,添加新值。
基于服务创建同名的服务操作。赋权,生成路由,插入消息。
创建package class 。
- 在工程中插入Application Package : SIE_TRN2019_PKG(软件包名称),TRN2019(路径),右键路径,插入新建class类 ZL_ORDER_ON_REQU,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| import PS_PT:Integration:IRequestHandler;
class ZL_ORDER_ON_REQU implements PS_PT:Integration:IRequestHandler method ZL_ORDER_ON_REQU(); method OnRequest(&_MSG As Message) Returns Message; method OnError(&_MSG As Message) Returns string; end-class;
Declare Function fun PeopleCode ZL_COMMITMENT.COMMITMENT_CNTL FieldFormula;
method ZL_ORDER_ON_REQU %Super = create PS_PT:Integration:IRequestHandler(); end-method;
method OnRequest /+ &_MSG as Message +/ /+ Returns Message +/ /+ Extends/implements PS_PT:Integration:IRequestHandler.OnRequest +/ Local Message &response; Local XmlDoc &requestDoc, &responseDoc; Local Rowset &rst; Local integer &I, &J; &rst = &_MSG.GetRowset(); Local boolean &ret = fun(&rst);
Local Record &hdl = &rst.GetRow(1).GetRecord(Record.ZL_ORDER_HEL); MessageBox(0, "", 9999, 9999, "&ret===" | &ret); SQLExec("DELETE FROM PS_ZL_INT_ORD_RST WHERE ZL_ORDERID=:1", &hdl.ZL_ORDERID.Value); Local Record &respRcd = CreateRecord(Record.ZL_INT_ORD_RST); &respRcd.ZL_ORDERID.Value = &hdl.ZL_ORDERID.Value; If &ret = True Then &respRcd.MESSAGE_TEXT.Value = "订单接口数据同步成功。"; Else &respRcd.MESSAGE_TEXT.Value = "订单接口数据同步失败。"; End-If;
&respRcd.Insert(); CommitWork();
&response = CreateMessage(Operation.ZL_ORDER_SRV, %IntBroker_Response); Local Rowset &respRst = &response.GetRowset(); Local Rowset &respRst1 = CreateRowset(Record.ZL_INT_ORD_RST);
Local integer &numRowCount = &respRst1.Fill("WHERE FILL.ZL_ORDERID=:1", &hdl.ZL_ORDERID.Value); If &numRowCount = 0 Then throw CreateException(30002, 13, "无数据!"); End-If; &respRst1.CopyTo(&respRst); Return &response; end-method;
method OnError /+ &_MSG as Message +/ /+ Returns String +/ /+ Extends/implements PS_PT:Integration:IRequestHandler.OnError +/ Local integer &nMsgNumber, &nMsgSetNumber; Local string &sText; &nMsgNumber = &_MSG.IBException.MessageNumber; &nMsgSetNumber = &_MSG.IBException.MessageSetNumber; &sText = &_MSG.IBException.ToString();
Return &sText; end-method;
|
- 在ZL_COMMITMENT.COMMITMENT_CNTL Fieldformula 中编写PeopleCode,代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| Local ApiObject &oSession, &oZlOrdercomCi; Local ApiObject &oZlOrderDetCollection, &oZlOrderDet;
Function errorHandler() Local ApiObject &oPSMessageCollection, &oPSMessage; Local number &i; Local string &sErrMsgSetNum, &sErrMsgNum, &sErrMsgText, &sErrType; &oPSMessageCollection = &oSession.PSMessages; For &i = 1 To &oPSMessageCollection.Count &oPSMessage = &oPSMessageCollection.Item(&i); &sErrMsgSetNum = &oPSMessage.MessageSetNumber; &sErrMsgNum = &oPSMessage.MessageNumber; &sErrMsgText = &oPSMessage.Text; rem &fileLog.WriteLine(&sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText); MessageBox(0, "", 9999, 9999, "" | &sErrType | " (" | &sErrMsgSetNum | "," | &sErrMsgNum | ") - " | &sErrMsgText); End-For; rem ***** Delete the Messages from the collection *****; &oPSMessageCollection.DeleteAll(); End-Function;
Function fun(&rst) Returns boolean; try &oSession = %Session; &oSession.PSMessagesMode = 1; rem ***** Get the Component Interface *****; &oZlOrdercomCi = &oSession.GetCompIntfc(CompIntfc.ZL_ORDERCOM_CI); If &oZlOrdercomCi = Null Then errorHandler(); throw CreateException(0, 0, " getCi faidled"); End-If; rem ***** Set the Component Interface Mode *****;
&oZlOrdercomCi.InteractiveMode = True; &oZlOrdercomCi.GetHistoryItems = True; &oZlOrdercomCi.EditHistoryItems = True; If Not &oZlOrdercomCi.Get() Then rem ***** Execute Create ******; If Not &oZlOrdercomCi.Create() Then; rem ***** Unable to Create Component Interface for the Add keys provided. *****; errorHandler(); throw CreateException(0, 0, "Create failed"); End-If; End-If; &oZlOrdercomCi.ZL_ORDERID = &rst.getrow(1).ZL_ORDER_HEL.ZL_ORDERID.VALUE;
&oZlOrdercomCi.ZL_ORDERDESC = &rst.getrow(1).ZL_ORDER_HEL.ZL_ORDERDESC.VALUE; &oZlOrderDetCollection = &oZlOrdercomCi.ZL_ORDER_DET; Local integer &i; For &i = &oZlOrderDetCollection.count To 1 Step - 1 &oZlOrderDetCollection.deleteItem(&i); End-For; Local Rowset &rowSet1 = &rst.GetRow(1).GetRowset(Scroll.ZL_ORDER_DET); For &i17 = 1 To &rowSet1.ActiveRowCount;
&oZlOrderDetCollection.insertItem(&oZlOrderDetCollection.count); &oZlOrderDet = &oZlOrderDetCollection.Item(&oZlOrderDetCollection.count); &oZlOrderDet.ZL_ORDER_SUBID = &rowSet1.GetRow(&i17).ZL_ORDER_DET.ZL_ORDER_SUBID.Value; &oZlOrderDet.ZL_ORDER_SUBTYPE = &rowSet1.GetRow(&i17).ZL_ORDER_DET.ZL_ORDER_SUBTYPE.Value; &oZlOrderDet.ZL_ORDER_SUBDESC_1 = &rowSet1.GetRow(&i17).ZL_ORDER_DET.ZL_ORDER_SUBDESC.Value; &oZlOrderDet.ZL_ORDERQUAN = &rowSet1.GetRow(&i17).ZL_ORDER_DET.ZL_ORDERQUAN.Value; &oZlOrderDet.ZL_ORDERPRI = &rowSet1.GetRow(&i17).ZL_ORDER_DET.ZL_ORDERPRI.Value; End-For;
If Not &oZlOrdercomCi.Save() Then; Return False; Else Return True; End-If; catch Exception &ex end-try; End-Function;
|
- 在服务操作中的处理程序 中 添加处理程序详情:
- 注意:这里不添加处理程序的话,在soapUI中会报错:执行到onRequest中断之类的错误。
使用soapUI模拟外部request请求
打开soapUI,新建工程:
得到代码如下,删除了后面两部分,似乎是关于多语言配置的:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:zl="http://xmlns.oracle.com/Enterprise/Tools/schemas/ZL_REQ_MESAG.V1"> <soapenv:Header> <wsse:Security soap:mustUnderstand="1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> <wsse:Username>PS</wsse:Username> <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">Abcd!234</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <zl:ZL_REQ_MESAG> <zl:FieldTypes> <zl:ZL_ORDER_HEL class="R"> <zl:ZL_ORDERID type="CHAR"/> <zl:ZL_ORDER_TEXT type="CHAR"/> <zl:ZL_ORDERDESC type="CHAR"/> <zl:ZL_ORDER_SUMMON type="NUMBER"/> </zl:ZL_ORDER_HEL> <zl:ZL_ORDER_DET class="R"> <zl:ZL_ORDER_SUBID type="CHAR"/> <zl:ZL_ORDERID type="CHAR"/> <zl:ZL_ORDER_SUBTYPE type="CHAR"/> <zl:ZL_ORDER_SUBDESC type="CHAR"/> <zl:ZL_ORDERQUAN type="NUMBER"/> <zl:ZL_ORDERPRI type="NUMBER"/> <zl:ZL_ORDERMON type="NUMBER"/> </zl:ZL_ORDER_DET> <zl:PSCAMA class="R"> <zl:LANGUAGE_CD type="CHAR"/> <zl:AUDIT_ACTN type="CHAR"/> <zl:BASE_LANGUAGE_CD type="CHAR"/> <zl:MSG_SEQ_FLG type="CHAR"/> <zl:PROCESS_INSTANCE type="NUMBER"/> <zl:PUBLISH_RULE_ID type="CHAR"/> <zl:MSGNODENAME type="CHAR"/> </zl:PSCAMA> </zl:FieldTypes> <zl:MsgData> <zl:Transaction> <zl:ZL_ORDER_HEL class="R"> <zl:ZL_ORDERID IsChanged="Y">1001</zl:ZL_ORDERID> <zl:ZL_ORDER_TEXT IsChanged="Y">测试</zl:ZL_ORDER_TEXT> <zl:ZL_ORDERDESC IsChanged="Y">2018年采购</zl:ZL_ORDERDESC> <zl:ZL_ORDER_SUMMON IsChanged="Y"></zl:ZL_ORDER_SUMMON> <zl:ZL_ORDER_DET class="R"> <zl:ZL_ORDER_SUBID IsChanged="Y">1</zl:ZL_ORDER_SUBID> <zl:ZL_ORDERID IsChanged="Y">1</zl:ZL_ORDERID> <zl:ZL_ORDER_SUBTYPE IsChanged="Y">p</zl:ZL_ORDER_SUBTYPE> <zl:ZL_ORDER_SUBDESC IsChanged="Y">垃圾采购</zl:ZL_ORDER_SUBDESC> <zl:ZL_ORDERQUAN IsChanged="Y">10</zl:ZL_ORDERQUAN> <zl:ZL_ORDERPRI IsChanged="Y">10.23</zl:ZL_ORDERPRI> <zl:ZL_ORDERMON IsChanged="Y"></zl:ZL_ORDERMON> </zl:ZL_ORDER_DET> </zl:ZL_ORDER_HEL> </zl:Transaction> </zl:MsgData> </zl:ZL_REQ_MESAG> </soapenv:Body> </soapenv:Envelope>
|
点击左上角运行,右边出现如下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soapenv:Body> <ZL_RESP_MESAGE xmlns="http://peoplesoft.com/ZL_RESP_MESAGEResponse"> <FieldTypes> <ZL_INT_ORD_RST class="R"> <ZL_ORDERID type="CHAR"/> <MESSAGE_TEXT type="CHAR"/> </ZL_INT_ORD_RST> <PSCAMA class="R"> <LANGUAGE_CD type="CHAR"/> <AUDIT_ACTN type="CHAR"/> <BASE_LANGUAGE_CD type="CHAR"/> <MSG_SEQ_FLG type="CHAR"/> <PROCESS_INSTANCE type="NUMBER"/> <PUBLISH_RULE_ID type="CHAR"/> <MSGNODENAME type="CHAR"/> </PSCAMA> </FieldTypes> <MsgData> <Transaction> <ZL_INT_ORD_RST class="R"> <ZL_ORDERID IsChanged="Y">1001</ZL_ORDERID> <MESSAGE_TEXT IsChanged="Y">订单接口数据同步成功。</MESSAGE_TEXT> </ZL_INT_ORD_RST> <PSCAMA class="R"> <LANGUAGE_CD>ZHS</LANGUAGE_CD> <AUDIT_ACTN/> <BASE_LANGUAGE_CD>ZHS</BASE_LANGUAGE_CD> <MSG_SEQ_FLG/> <PROCESS_INSTANCE>0</PROCESS_INSTANCE> <PUBLISH_RULE_ID/> <MSGNODENAME/> </PSCAMA> </Transaction> </MsgData> </ZL_RESP_MESAGE> </soapenv:Body> </soapenv:Envelope>
|
思考:
这里和订单录入系统函数代码虽然是一样的,最终都是执行的save操作,但区别是:订单录入系统的save是执行的updatedata操作(覆盖操作),这里的save是执行create操作(新建,orderID是唯一的),所以,一个可以成功覆盖,另一个不能成功创建插入。还有一个是update操作,ID可以相同,但是子序列必须不同。
每个系统特有的,会给。