BPEL's example: Working with complex types and array type
This tutorial shows you how to use the complex types and array type in BPEL. We will examine this issue with a simple example: we input a list of members of a company and the BPEL process will return the number of inputed members and information of the last one. Each member is presented by a complex type with two fields: name and age.
Tools: Eclipse 3.6, BPEL Designer 0.5.0 Plugin, Tomcat 7.0.53, ODE 1.3.5
Project creation
Create a new BPEL project named “BPEL_ComplexArray” by selecting File→New→Others→BPEL 2.0→BPEL Project. Select Next. Type the project name as BPEL_ComplexArray and select the Target Runtime as Apache ODE 1.x Runtime. Click Finish.
Create a new BPEL process file named ComplextArraySample by right clicking on the BPEL_ComplexArray/bpelContent folder, select New→Others→BPEL 2.0→New BPEL Process File. Click Next. Fill in BPEL Process Name the string ComplextArraySample, and in the Namespace the string http://complexarray.bpel.tps. Click Next.
Select the Template as Synchronous BPEL Processand modify the Service Address as http://localhost:8080/ode/processes/ComplextArraySample (suppose that your Tomcat environment is running on port 8080). Click Finish
Types declaration
Open ComplextArraySampleArtifacts.wsdl file. Right click on ComplexArraySamplePort. Select show properties and make sure that the Address is http://localhost:8080/ode/processes/ComplexArraySample.
Click on the arrow after the variable
ComplexArraySampleRequest to open the Inline Schema of this variable.
At the
Outline View, right click on
Types, select
Add Complex Type. In the
Properties View of this variable, change its name to
People. Right click on the variable People, select
Add Element. Set its name as
name and type as
string.
Add another variable named age and type int.
In the
Outline view, select
Elements→ComplexArraySampleRequest→local type→sequence→input. Then, in its
Properties view, at
Type, select
Browse.. and browse it to
People. Click
OK.
Similarity, change the type of
Elements→ComplexArraySampleResponse→local type→sequence→result from
string to
People.
But the input has to be the array of People and the result has to have another variable to hold the total number of members. So, we have to do a bit more. Click on the
Elements→ComplexArraySampleRequest→local type→sequence, in its
Properties view, select
Minimum Occurrence is
1 (at least 1 member in the list) and the
Maximum Occurrence is
unbounded.
Right click on
Elements→ComplexArraySampleResponse→local type→sequence, select Add Element. Name it as
total and select the type is
int.
That's all for the declaration step. Save the file and move to the BPEL Design.
BPEL design
Open the file
ComplextArraySample.bpel, drag an
Assign action between the existing
receiveInput and
replyOutput.
Click on the
Assign, in its
Properties view, select
Details→New. Assign the expression
count($input.payload/tns:input) to the
output→payload→total. A pop-up dialog appears asking you about the variable initiation. Select
Yes.
Select New again, add the expression $input.payload/tns:input[last()] to the output→payload→result.
That's all for the design. Save the BPEL file.
Project deployment
Right click on the BPEL_ComplexArray/bpelContent, select New→Others→BPEL 2.0→Apache ODE Deployment Descriptor. Click Next. Verify the BPEL Project field as /BPEL_ComplexArray/bpelContent. Click Finish.
Open the deploy.xml file. And select the Associated port with the Partner Link client is ComplexArraySamplePort.
Save file and open the Server view, right click on the Ode v1.x Server at localhost, select Add and Remove Projects. Select the BPEL_ComplexArray in the Available projects box and click Add. Then, click Finish.
Start the ODE server and use the Eclipse's
Web Services Explorer to test our application. If you deploy the process successfully, you will see the result like the following:
Done.
Exercices
Deploy a “hotel agent” service which stores database about hotels in your region. Then, create a BPEL process to invoke this service: input is the place (or price) and output is list of hotels and their information which relate to the input.
Back to top