Sei sulla pagina 1di 17

bpel-104-Arrays

bpel-104-Arrays
This sample illustrates how you can handle array structures present in your XML payload
using the <while> activity in the BPEL process. The Arrays Sample BPEL Process
receives Purchase Order information as a XML payload consisting of multiple line items.
Each line item XML node consists of uid, price, quantity and the line-total. The objective
of this sample is to illustrate how we can handle these multiple line-items and arrive at
the total invoice price which is the sum of all the line-total. The Arrays Sample process
uses two variables namely iterator and count along with <while> activity to loop through
all the line-item nodes and come up with the invoice total.
bpel-104-Arrays................................................................1
1.Installing the sample......................................................2
2.Description and Architecture..........................................3
3.Running the sample.......................................................6
4.Building the sample.....................................................12
Create a New SOA Composite Application................12
Create the ArraySample.wsdl File...........................13
Add a BPEL Process to the Composite.....................13
Add the BPEL Nodes and Actions............................14

bpel-104-Arrays

1. Installing the sample


For instructions on installing this sample, open the following file in browser:
SOASamples/bpel/bpel-104-Arrays/README.html

bpel-104-Arrays

2. Description and Architecture


This sample shows how to process an array of line items in an XML invoice document to
calculate the total amount of an invoice. The architecture for this sample is vary straight
forward. The following diagram shows the composite application structure.

The client in the Exposed Services swim-lane is based on the ArraySample.wsdl file,
which defines a SOAP web service interface to the ArraySample.bpel BPEL process. The
BPEL process takes the XML invoice, analyzes each line item in the invoice to calculate
the total value of the invoice. The BPEL process overview is shown next.

-3

bpel-104-Arrays

The first setAttribute node at the top of the process simply initialized the iterator and
count variables that will be used as the process loops through the line items of the
invoice. The while node contains a single setAttribute node that does the bulk of the
work. This second setAttribute node contains three copy actions as shown in the
following table.
Copy From
Copy To
concat('/tns:invoice/tns:lineitem[',bpws:getVariableData('iterator'),']/tns:line-total')

xpath//

bpws:getVariableData('input','payload',bpws:getVariableData('x /tns:;invoice/tns:total
path')) +
bpws:getVariableData('input','payload','/tns:invoice/tns:total')
bpws:getVariableData('iterator') + 1
iterator//
The first copy action is used to create an XPath expression that points to the correct line
item within the invoice for the current iteration. The second copy action then used that
-

bpel-104-Arrays

XPath expression to retrieve the line-item total, add it to the invoice total, and then
update the invoice total with the new amount. The third and final copy action increments
the iterator. The encompassing while node with then test the value of the iterator again
the count variable to determine if another iteration is needed.
The last Assign node is the copyOutput which simply copies the updated invoice to the
output variable so that it will be returned to the caller via the callback.

-5

bpel-104-Arrays

3. Running the sample


To run the sample, startup your SOA Suite admin server and the soa_server1 server. Once
both servers are up and running completely, use JDeveloper to deploy the application to
the application server. Once you have successfully deployed the application, open a
browser and point it to http://localhost:7001/em to bring up the Oracle Enterprise
Manager.
Once the Enterprise Manager page loads, navigate to the ArraySample application as
shown in the following figure and press the Test button.

Depending on your configuration, there may be a problem parsing the WSDL based on
your machine name, as shown in the following figure. If this occurs, simply replace the
machine name in the URL with localhost. The full URL is as follow:
http://localhost:8001/soa-infra/services/default/ArraySample/client?WSDL
Press the Parse button. The Enterprise Manager page will configure itself to provide you
with a web page that you can use for testing the web service. There will be a Request and
a Response tab. Ensure that the Request tab is selelcted and scroll to the bottom part of
the web page to fill in the fields in the Input Arguments section. Fill in each of the fields.
The data in the fields for the UID, Buyer, Seller and the various address fields are not
validated other than to check they they contain some data. You are free to put random
data into these fields.
In the line-item field you need to enter the number of line items for the order. Enter a
value like 2 or 3 to keep things simple at first. Then press the ArraySize icon to the
immediate right of the line-item field, as shown in the next figure.

Now you can fill in the line items with your values. The following is a sample XML
document that contains all of the fields needed to run the test:
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body xmlns:ns1="http://samples.otn.com/arraysample">
<ns1:invoice>
<ns1:purchaser uid="4988">
<ns1:name>Buyer</ns1:name>

bpel-104-Arrays

<ns1:address>
<ns1:street1>100 Main Street</ns1:street1>
<ns1:street2>Apt 2</ns1:street2>
<ns1:city>San Jose</ns1:city>
<ns1:postal-code>95129</ns1:postal-code>
<ns1:country>USA</ns1:country>
<ns1:state>CA</ns1:state>
</ns1:address>
</ns1:purchaser>
<ns1:seller uid="5968">
<ns1:name>Seller</ns1:name>
<ns1:address>
<ns1:street1>200 Elm Street</ns1:street1>
<ns1:street2>Apt D</ns1:street2>
<ns1:city>San Francisco</ns1:city>
<ns1:postal-code>95065</ns1:postal-code>
<ns1:country>USA</ns1:country>
<ns1:state>CA</ns1:state>
</ns1:address>
</ns1:seller>
<ns1:line-item uid="9328347">
<ns1:description>Test1</ns1:description>
<ns1:price>100.0</ns1:price>
<ns1:quantity>10</ns1:quantity>
<ns1:line-total>1000.0</ns1:line-total>
</ns1:line-item>
<ns1:line-item uid="94384857">

-7

bpel-104-Arrays

<ns1:description>Test2</ns1:description>
<ns1:price>200.0</ns1:price>
<ns1:quantity>10</ns1:quantity>
<ns1:line-total>2000.0</ns1:line-total>
</ns1:line-item>
<ns1:line-item uid="349485857">
<ns1:description>Test3</ns1:description>
<ns1:price>300.0</ns1:price>
<ns1:quantity>10</ns1:quantity>
<ns1:line-total>3000.0</ns1:line-total>
</ns1:line-item>
<ns1:total>5000.0</ns1:total>
</ns1:invoice>
</soap:Body>
</soap:Envelope>

When you are satisfied with the request, press the Test Web Service button. The request
message will be sent to the web service. After the request is made, the Response tab will
become active and, because this is an asynchronous request-reply web service, the
Response tab will be largely empty. However, you can still take a loot at the processing
that was performed by clicking on the Launch Message Flow Trace link in the Response
tab (be sure you have popups enabled in your browser). The following figure shows an
audit trail of the web service request.

bpel-104-Arrays

You can see from the audit trail that the while node in the BPEL process iterated 3 times
over the invoice, once for each line item. If you have set the audit level to Development,
you can see the XML document that is returned, as shown in the next figure.

-9

bpel-104-Arrays

bpel-104-Arrays

You can enable development mode audit level by right-clicking on the soa-infra
(soa_server1) entry in the left side of the Enterprise Manager navigation bar and
selecting SOA Administration Common Properties from the popup menu. There you
can set the audit level. Be sure to press the Apply button to save your changes to the audit
level.

-11

bpel-104-Arrays

4. Building the sample


In this section we will describe how to create this sample from scratch. We will not
describe each an every mouse click, but you should be able to easily follow these
instructions and work out the minor details on your own. Here are the high level steps in
the construction process:
1. Create a new SOA composite application
2. Create the ArraySample.wsdl file
3. Add a BPEL process to the composite
4. Add the BPEL nodes and actions

Create a New SOA Composite Application


1. From the main menu, select File New to bring up the New Gallery wizard.
Select Applications as the category and then select SOA Application as the specific
type of application to create. Press the OK button.

2. In the next step of the wizard, enter a name for your application. Press the Next
button
3. Enter a name for your project and press the Next button.
4. In the final step, select Empty Composite as the composite template and press
the Finish button

bpel-104-Arrays

Create the ArraySample.wsdl File


Now that the application and project are created, follow these steps:
5. Open the project you created in the Application window (top left part of the
JDeveloper IDE
6. Right-click on the SOA Content folder and select File New
7. In the New Gallery dialog, select the General category and then select the File
item. Press the OK button.
8. Name the file ArraySample.wsdl and press the OK button.
9. Instead of listing the file contents here, simply copy the contents of the
ArraySample.wsdl file from this sample project and paste the content into your new
ArraySample.wsdl file.

Add a BPEL Process to the Composite


10.
From the Component Palette, under the Service Components heading,
click and drag a BPEL Process component onto the Components section of the
composite.xml file. This will bring up the Create BPEL Process wizard.
11.
In the BPEL Process Wizard, name the process ArraySampleProcess and
set the Template field to Based on a WSDL.

-13

12.

Select the ArraySample.wsdl file that you created earlier in this project.

13.

Set the Port Type field to ArraySample

14.

Set the Callback Port Type field to ArraySampleCallback

bpel-104-Arrays

15.
Your dialog should closely match the one shown in the next figure. Press
the OK button.

Add the BPEL Nodes and Actions


At this point, your composite.xml file should look like the following:

16.
Double-click on the ArraySampleProcess BPEL node to open up the
BPEL process for editing.
17.
Create the iterator, count and xpath variables by clicking on the variables
button in the BPEL process to bring up the Variables dialog and then press the green
X icon to create each variable. The count and iterator variables need to be of type
xsd:integer while the xpath variable is of type xsd:string.

bpel-104-Arrays

18.
Rename the existing inputVariable and outputVariable variables to input
and output respectively.
19.

Press the OK button after you have created all 3 variables.

20.
Drag and drop and Assign activity from the Component Palette between
the receiveInput and callbackClient nodes in the BPEL process flow.
21.

Name the new Assign action to InitializeVariables.

22.

Double-click the InitializeVariables activity to edit it.

23.

Create 2 Copy actions as depicted in the following table

Copy From

Copy To

iterator//

ora:countNodes('input', 'payload','/tns:invoice/tns:line-item')

count//

24.
Now drag and drop a while activity from the Component Palette directly
below the InitializeVariables node.

-15

bpel-104-Arrays

25.

Label the while activity iterator <= count

26.

Open the while activity by clicking on it + button

27.

Drag and drop an Assign activity into the while activity.

28.

Name the Assign activity to CalcTotal

29.
Open the CalcTotal activity and create three Copy actions as shown in the
following table.

Copy From

Copy To

concat('/tns:invoice/tns:lineitem[',bpws:getVariableData('iterator'),']/tns:line-total')

xpath//

bpws:getVariableData('input','payload',bpws:getVariableData('x /tns:;invoice/tns:total
path')) +
bpws:getVariableData('input','payload','/tns:invoice/tns:total')
bpws:getVariableData('iterator') + 1
30.
contains.

iterator//

In the BPEL Process Designer, close the while activity to hide the action it

31.
Drag and drop a new Assign activity directly below (and outside of) the
while activity. Name this activity copyOutput
32.
Open the copyOutput activity and add a single copy action. Your copy
action should look like the following:

bpel-104-Arrays

Save your work and deploy it and test it!

-17

Potrebbero piacerti anche