BPEL structured activities: If-Else
Different from the Pick activity, BPEL If-Else executes the processes based on the a conditions instead of an event. We will see how it works with this simple tutorial. The process returns the string “Hello John” if the input is John, otherwise, it returns “You are not John”.
Tools: Eclipse 3.6, BPEL Designer 0.5.0 Plugin, Tomcat 7.0.53, ODE 1.3.5
BPEL's If-Else activity
Create a new BPEL project named “BPEL_IfElse” by selecting File→New→Others→BPEL 2.0→BPEL Project. Select Next. Type the project name as BPEL_IfElse and select the Target Runtime as Apache ODE 1.x Runtime. Click Finish.
Create a new BPEL process file named IfElseSample by right clicking on the BPEL_IfElse/bpelContent folder, select New→Others→BPEL 2.0→New BPEL Process File. Click Next. Fill in BPEL Process Name the string IfElseSample, and in the Namespace the string http://ifelse.bpel.tps. Click Next.
Select the Template as Synchronous BPEL Process and modify the Service Address as http://localhost:8080/ode/processes/IfElseSample (suppose that your Tomcat environment is running on port 8080). Click Finish.
Open IfElseSampleArtifacts.wsdl. right click on IfElseSamplePort. Select show properties and make sure that the Address is http://localhost:8080/ode/processes/IfElseSample.
Open IfElseSample.bpel file. Click and drag the If control from the Palette to the process, between the receiveInput and replyOutput actions.
Drag an
Assign action into the
If and drag the
replyOutput below the
Assign. A
sequence is automatically created.
Right click on the
If activity, select
Add Else. Drag one
Assign and one
Reply action to the
Else branch.
Select the
If activity, in the
Properties view, select
Details and edit the condition as
$input.payload/tns:input=“John”.
Click on the
Assign action, in its
Properties view, select
Details→New. Assign the fix value
“Hello John” to the variable
output→payload→result. A pop-up dialog appears asking you about the variable initiation. Select
Yes. In case the pop-up dialog does not appear, you can do the following steps to initialize the result variable: change the operation to “assign from a Variable to Variable”; then, assign the input variable to output→payload→result; the pop-up dialog should appear; then you change the operation back to “assign from a Fix value to a Variable”.
By the same way, at the Assign1 action, assign “You are not John” to the output-payload-result. Remember to initialize the variable result before assigning this string.
Click on the
Reply action, in the
Detail tab, at the Quick Pick, select
IfElseSample→process→IfElseSampleResponseMessage-Payload→result to assign the
result to the
output variable.
Save the process design. Right click on the BPEL_IfElse/bpelContent, select New→Others→BPEL 2.0→Apache ODE Deployment Descriptor. Click Next. Verify the BPEL Project name as /BPEL_IfElse/bpelContent. Click Finish.
Open the deploy.xml file. And select the Associated port with the Partner Link client is IfElseSamplePort.
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_IfElse 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
Create a BPEL process using If activity to find the maximum of two integers.
Create a BPEL process using If activity to sort three integer in ascending order.
Back to top