BPEL: Credit Card Request demo & For Each
This tutorial is an appendix of the previous "BPMN: Credit Card Request demo".
Now that you exposed a BPM project as a web service you can consume it...and generate 10, 100, 1000 or even more credit card requests just like that. Of course, with dummy data but still, the number could be big!
NOTE: Even if "sky is the limit" please note you will end up sending an email notification using your own email account. If the number of emails sent in the same time is too big then the email account provider might see this as a DDoS attack or at least will think there is something odd. So make sure you don't go with too many requests that will be rejected from the start based on the below rule:
(monthly expenses div (estimated income div 12) * 100 > 70% AND "Unemployed"
If you use the below web site you can even "bake" a big CSV file as the input:
- DATABAKE to Generate realistic test data

Note: There is also the possibility to place this future pattern inside of the previous composite; however, even the "The NeverEnding Story" has its own "The end".

In addition to the above "bake" tool there is also the below Oracle Live SQL option:
The Oracle Live SQL is full of features ... but you will have to find them.
Back to the SOA story since now is no more about BPM but about SOA...because we don't need the BPMN Component.
This tutorial goes around 3 main ideas:
- how to generate an XML Schema (XSD file) based on an Excel-CSV file.
- the File Adapter technology.
- BPEL component with the "ForEach" activity.
Below you can find attached the demo CSV file. Since the file itself was really big I removed most of the rows; you can add more rows with your own values. Download the CSV file since you will soon use it:
And now the pictures....
A picture is worth a thousand words:
Always start "Empty":
Not much to see for now since... is "Empty":
The File Adapter + CSV to XML Schema
Since we will read this file.... we will place the File Adapter in the Exposed Services; this is how we will trigger this composite.

And now we need to end up with the XML Schema (XSD) for the future messages.... based on the CSV:
Always check the columns and make sure it reflects what you want. Worst case play with the settings so at the end you have the data you need:
In my case all data is about "String" and in case some values should be reflected as numbers I will handle this in the BPEL or the BPMN component; at the end its up to you how you want to implement all this:
Save the XSD file so in the future you can reuse it without going with all the previous steps:
Now back to the File adapter:
All done here.
The Credit Card Request BPM web service
The previous BPM credit card request process is like any other web service...SOAP web service that is. So we need the WSDL from the EM Console
- localhost:7011/em
Copy the entire link of this WSDL and use it inside a SOAP External Reference:
All done.
It looks so so complicated.... 😋
The BPEL
We will use now the BPEL Component that will read the file and For Each row will invoke the BPM external web service... One by one each row from the CSV will be used as a message for a new credit card request.
Do keep in mind we just created a File Adapter Exposed Service so we will use it as a WSDL since even this File Adapter acts as a web service and has a WSDL.
Such WSDL files are to be found in the "WSDL" folder:
Make sure you don't select the checkbox to expose this BPEL as a web service- no need for this:
Now "wire" those 3 elements:
Open the BPEL component:
We will use the For Each activity:

....for each row inside the CSV file.... do something.
For example, for each row inside the CSV file...invoke the external Reference:

Create a variable to keep the message/data that will be sent to the external web service:
Since the external BPM service returns nothing, no need for an Output.
Now, for each row inside the CSV file... assign the (input) message to the message (format) requested by the external service. You will actually map the input from CSV to the variable used to invoke this external service:

However, before we implement the mapping.... we still need to go back to the For Each itself since we need some more settings.
This For Each is like any "for-loop" statement so we will need an extra parameter: a counter - to know when we need to finish-stop whatever we need to do.
Note: Keep in mind this "counter" name since we will use it again in some min.
How about the idea: do whatever you want ... till you have no more time or till you have no more objects to play with etc .
For this story the idea is: start with the first (1) row and read all of them one by one till the end of all the rows; till the end of ...how many rows we have. We can count the rows to know how many we have and when we will stop:
Is about the "CardRequest" element since this one has all the fields we need like SSN, name, etc:
Back to the Assign-Invoke activities that will be performed for all rows from the CSV file:
Open the Assign activity:
Since the input from the CSV and the BPM external service have the same schema...we can just map 1-1 element having the same name:
And this should be all that we need..... but there are "n" rows inside the CSV and we need to add this info on the mapping - assign diagram.
The "n" in this case is the "counter" we defined on the For Each activity itself (starting from 1 till the "count of all the elements" number).
The rule is simple: we use the counter variable as an element for the root of the message; or the parent of the message.... the kids are the individual elements-fields like SSN, name etc:

And we go with this pattern for all the kids- elements:
Note: In case you ask if there is an alternative to all the above steps; yes there is....But this will be covered in a different tutorial.
For now we used the For Each activity inside the BPEL Component and the above steps are the rule.
All done.
The Deployment
We can now deploy this composite and test it by placing a CUSTOMERLIST.csv file inside the specific INPUT folder. After some time (aka the amount of time you specified) the magic will happen.

Check the BPM Workist Console for the new tasks generated or even the Database table if some credit card requests were rejected by default. And also check the emails.
The BPM Woklist Console:
- http://localhost:7011/bpm/workspace/