SOA循环添加数组的应用

来源:互联网 发布:pptv云播网络异常 编辑:程序博客网 时间:2024/05/21 10:39

           近日遇到一个需求,在SOA中的传入参数为数组,要求中间循环数组,逐条进行数据处理,数据处理后的结果需要添加到一个集合里,并在循环结束后,将集合输出。

看需求类似java里处理数组的情况,但是在SOA里怎么实现,刚接触SOA的偶实在是经验少,求教了同事后,得到的结果是他们虽然用了好久,但是这个功能没用过,看来只能自食其力了,有木有啊!!!

         查看一圈资料下来,发现在Assign中的bpelx:append 能实现需求。

The bpelx:append extension in an assign activity enables a BPEL process service component to append the contents of one variable, expression, or XML fragment to another variable's contents. To use this extension, you select a copy rule at the bottom of the Copy Rules tab, then select Append from the dropdown list.

The from-spec query within bpelx:append yields zero or more nodes. The node list is appended as child nodes to the target node specified by theto-spec query.

The to-spec query must yield one single L-Value element node. Otherwise, abpel:selectionFailure fault is generated. Theto-spec query cannot refer to a partner link.

<bpel:assign>    <bpelx:append>      <bpelx:from ... />       <bpelx:to ... />    </bpelx:append> </bpel:assign> 

详细资料请看:

http://www.art2dec.com/documentation/docs/fmw11g1114documentation/integration.1111/e10224/bp_manipdoc.htm#BABJDJID

https://cn.forums.oracle.com/forums/thread.jspa?threadID=2246505

找到了理论根据,但是实际应用起来并不容易啊。from 和to中的值如何确定,取什么值,颇费了一番脑筋。经过一番测试,结果终于成功。以下为demo的步骤,为节省时间,仅作5次的循环:

1、定义返回的输出数组XSD文件,record节点是0到多个的的数组

2、编写bpel流程

整个过程如下图:

3、过程解剖

      1)定义变量tempNode,元素类型选择输出参数的类型

     2)AssignInit活动给循环索引Index赋给初始值0

3)设置循环条件

4)给临时变量tempNode赋值

5)将临时变量tempNode节点赋给输出数组,特别留意AssignAppendArray节点的copyRule和对应关系,tempNode与右边的循环节点的上一级进行对应。

因为Appand的目的是要将左边的一个节点包括结构和数据整个添加到右边的某一个节点下去,因此右边节点的选择很重要,一定是要循环节点的上一级。

可能表述得有点不清,再次摘录老外的一段话,哈哈,虽然他自己都没有自信是否表达清楚了,但是起码我是清楚了,就不知道你清楚了没:

Generally, we use append to add any element from source to the target variable. And here the element which you are appending, that type of elements are repeating i mean can exixsts 0 to many on the target side. So, whatever you append will be on the last. Make sure the data is there in the element which you are appending and also, while doing an append operation you need to give the correct xpath i mean to the source and also for the target variable. May be if you can post your source, we can figure out.

And also while using append, on the source side i mean on the left hand side, select the element which you want to append and on the right hand side you need should not select the repeating element, you should select the top element which contains the repeating element. This way it works. I may not be clear but i'll try to help if you post the source code.

 

6)循环索引加1继续循环

4、发布测试

 家里weblogic不能用啊,CSDN不给力,不能上传源代码,有木有,无法贴运行结果了,以后再说呗

人品爆发,weblogic又好了,SOA服务器也好了,上图,结果如下:

本文结束,圆满了。。。。。。。。。。。。