Something very used in programming languages is without doubt a FOR to iterate through a list of elements any, in this Post I intend to help you use the For Each component of the BPEL performing a simple loop, iterating and concatenating names that put as a parameter to our Loop .
For our tests, we will create a project called ForEachBpel
Click File >> New
Will open a screen like below:
Then select Generic Project
Project Name ForEachBpel place and select the SOA Technologies Project name and click the small arrow> to the name go right and be as below:
Note: See the Directory that it will automatically fill in the name will be created where the project name you entered in the Project Name
In my case: /home/uans/jdeveloper/mywork/UansBlogApplication/ForEachBpel
Click Next and then Finish, leaving the Composite Template in Empty Composite
Now we create an empty project will create a BPEL
Now right click Componets > Insert > BPEL Process
Click BPEL 2.0 Specification
In place name ForEachBpel
In Template select Synchronous BPEL Process and click OK
Let selected option Expose as a service SOAP, as this will be responsible for creating a WSDL and XSD default which will change for our tests.
Ready, it should look like this:
Now open the ForEachBPELProcess.xsd file that was created automatically.
In complexType element name=”process” will be as follows:
<element name=”process”>
<complexType>
<sequence>
<element name=”input” type=”string”/>
</sequence>
</complexType>
</element>
Then change to: (only the highlighted in red)
<element name=”process”>
<complexType>
<sequence>
<element name=”nome” type=”string” maxOccurs=”unbounded” minOccurs=”1″/>
</sequence>
</complexType>
</element>
So should look like this:
Let us understand what has changed:
- In element name = “nome” changed our input variable to nome
- In maxOccurs = “unbounded” I am saying that we have mentioned many times the parameter name
- In minOccurs = “1” I am saying that this parameter is required
Now open your BPEL composite and within ForEachBPELProcess.bpel drag and drop the For Each component as follows:
Double-click on your ForEach1 and on the General tab set as follows:
- Name: ForEachNome
- Counter Name: ForEachContador
Now in Counter Values tab, Start Value place 1 in the Expression field and Final Value click on the icon that looks like a small calculator as follows:
In the box that opens in Advanced Functions select the BPEL XPath Extension Functions option
Double-click on it ora:countNodes()
Inside the parenthesis: ora:countNodes() put two single quotes and within single quotes press Control key on your keyboard while the space bar, see the options that appear below:
- inputVariable
- outputVariable
- ForEachCont…
Select the inputVariable option, place a comma after the name, and place again two single quotes and inside the quotation marks select the payload option that will appear again put a comma and add two more single quotes within quotes and select the option: client:name that will appear, then you’ll be as follows:
ora:countNodes(‘inputVariable’,’payload’,’client:nome’)
Click OK, and looks like this:
Click OK again and drag a component Assign up our ForEach and rename the Assign1 name by double-clicking on the name and place the word Olá pressing Enter then, as follows:
Within our Olá it is our variable box, expand the option outputVariable >> payload >> client:processResponse >> client:result and into her drag the icon above that looks like a small calculator
Inside the box that opens add the name Olá: followed by a space in single quotes as shown below and click OK
Now into our ForEachNome drag another Assign and rename it to the name Concatenates
Open our Concatenates box again drag the icon that looks like a small calculator or simply click the right button on the name client:result (outputVariable >> payload >> client:processResponse >> client:result) e clique em Expression
Advanced Functions String Functions select the option
Double-click on the name concat and within the parentheses of concat() a double click client:result his outputVariable (outputVariable >> payload >> client:processResponse >> client:result)
Add a comma after the result and a single quote, a space and add again another single quotes followed by a comma and now double-click client:nome now your inputVariable (inputVariable >> payload >> client:process >> client:nome)
The name aside add [] and inside the brackets add the name of our For Each ($ ForEachContador, pay attention here which was added the dollar sign ($) identifying which is a variable), double-clicking on it and next to the brackets which was closed add a comma, a single quotation marks, again a comma and again a single quotation marks as follows:
concat($outputVariable.payload/client:result,’ ‘,$inputVariable.payload/client:nome[$ForEachContador],’,’)
Click OK
Click OK again on the screen above
Now drag another Assign below its ForEachNome and rename it TudoBem
Inside your box TudoBem in client:result add expression below:
concat($outputVariable.payload/client:result,’ tudo bem ?’)
Click OK
Click OK again on the screen above
Perform deploy locally of our project and we will test it
In your browser go to the address http://localhost:10000/em
Note: The port 10000 is the number that I chose to create my Domain.
Login:
Click your project: ForEachBpel[1.0]
Click Test
Below input in place 3 where 0 appears, it will be the size of our array, then click the icon next to
Made it will open the screen below for inserting three names, then fill them and click Test Web Service
The Response tab, check the result
Doubts? Leave your comment and download this Projet
Hugs and to the Next
/:-D