Thursday, May 7, 2015

BPEL : Populating a Complex Element List

Apache ODE has insert-as.. XPath extension functions to add elements to a list inside a business process.

You can select the function based on where the new elements should be added. For an instance, insert-as-last-into() insert elements at the end of the list and insert-as-first-into() add elements to the front of the list.

Following code snippets demonstrates the usage of the functions.

Let's assume that the variable input has multiple parameter elements. We need to add each element to a list called elementList. Here the ode:insert-as-last-into() function is used.

Insert function should be used inside a copy operation. The first argument is the variable that represents the list. Second one is the element that is going to be added. Finally the bpel:to part of the copy operation should be again the list that we are inserting elements.

This looks like a straight forward task. But when I use this for the first time, I ran into bunch of problems. So here are the tricks that you need to aware when using these functions.

1. You need to use following xpath 2.0 related queryLanguage and expressionLanguage,             

2. You can only insert directly into a list. Not a list inside another parent element.
For an instance, you can't directly insert into a list that is inside a message part. It will result in       selection failures. You need to define a local list variable, populate that local list and copy the             whole list later.

Hope this is all you need.

I have tested this with the WSO2 BPS Server. Leave a comment if you have any queries.


1 comment: