, , , , , , , , , , ,

I want this post to show you how we can use the For Each component of the OSB to iterate through a list of employees who will be returned from an exposed service BPEL

In addition to using the For Each component also show how we can do the same iteration using XQuery

I did a service in BPEL that returns a list of employees that are returned from my Oracle XE database.

As the idea of this post is just to show how to use the For Each component will go directly to our focus and if you have any doubts as Exposing a Service or use a Service Callout see the links below:

Needed then just expose my service created in BPEL using a Business Service and now I will call this service using the Service Callout, for it created a Proxy Service call ForEachProxyService.proxy

One more important detail that you need to be aware of is the construction of its contract (WSDL), click here and make download my WSDL for you to see as was the definition of this contract.

See below I created the Variable get data obterDadosEmpregadosRequest to assemble our Request and obterDadosEmpregadosResponse variable that will hold the call answer this SelectEmployeeBusiness our service is the service that I had to expose the OSB:

Imagem Blog UansCarvalho

As my intention is simply to return the employee list that is returned to our service SelectEmployeeBusiness service will add directly to the Response Pipeline Stage one and within this the Stage For Each component and also a Replace within our For Each

Imagem Blog UansCarvalho

See below in detail how are the property of our For Each

Then click on the box of our For Each and fill in the Properties tab as follows:

  • For Each Variable: empregado (This is just a name that give to our iteration, namely that this variable is returned iterarmos)
  • Xpath: <XPath> (Here for now you can leave it as is)
  • In Variable: obterDadosEmpregadosResponse (This is the name of our return variable of our service that added to our Service Callout, we will use this variable so we can iterate over the list to be returned)

Imagem Blog UansCarvalho

So now click on the tag <XPath>

In the box below, drag to the left side of our listaEmpregado will be below our obterDadoEmpregadosResponse

Imagem Blog UansCarvalho

Here we do not need our for:obterDadosEmpregadosResponse because we do not need this tag is also returned in our Response, so we can delete this part and leave only ./listaEmpregados

Imagem Blog UansCarvalho

So our For Each looks like this:

Imagem Blog UansCarvalho

Now click on our Replace the Properties tab and leave as follows:

  • XPath: . (Point)
  • In Variable: body (We will do Replace our body)
  • Expression: <Expression> (Here while you can leave it as is)
  • Replace node contents (Check this option)

Imagem Blog UansCarvalho

Now click on <Expression> and mount your Response payload as follows:

Imagem Blog UansCarvalho

Note: Doubts how to assemble the Response? See my post Using the Service Callout OSB

Now inside the tag <listaEmpregados> add our the For Each variable ($empregado), just put it here in braces after the variable and put a slash and an asterisk (/ *) because we want to return everything after this variable which actually returns everything in the list, as we have already started to tag <listaEmpregados> it need not be removed and therefore put the /*

Imagem Blog UansCarvalho

Click OK and test the service:

Now if you want to not use the For Each component can within our Replace the same screen put up in XQuery as follows:

Imagem Blog UansCarvalho

Note: Remember that if you prefer to use the XQuery, our Replace may not be within the For Each component because it should not exist in this case.

Calling our Service ForEachProxyService see below our return:

Imagem Blog UansCarvalho

See that we now have several <empregados> within our <listaEmpregados>


Doubts ? Leave your comment and download the Projet BPEL and Projet OSB :-)


Hugs and see you next