Friday, February 26, 2010

Switch activity in BPEL

Switch activity in BPEL is again like simple switch statment of any programming language.In bpel switch activity comes with two option one is user defined condition and other is default.However you can add extra conditions as per your requirement.We will have a look in the activity use case.Create an application then within that a simple asynchronous BPEL process .Assign it some logical name.





Now drag and drop a switch activity in between the receive input and callback client



Now expand the switch activity and put two assign activity in there.



Now double click on first assign activity and assign some value to the output variable.I am assigning Arpit .



Similarly create a copy operation for the second assign activity and assign it some value,i assigned it Ankit.

Now we will provide the condition for the switch activity.

just click on the expression buttion on the top of the switch activity.



Once you will click on that a new winodw like this will come up




Just click on the xpath expression builder and a new window will come up .there in select the input variable from the BPEL variable list and double click on it so that it will now appear on the top window.Provide a condition like

the input varialbe should be less than 420

so in my case the condition is something like this

bpws:getVariableData('inputVariable','payload','/client:SwitchDemoProcessRequest/client:input')<420



Save all the changes and dploy the project.

Now invoke the process in bpel console with follwing input



Now if you will check the output in the callback client you will find the folllowing output

<outputVariable>
- <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
- <SwitchDemoProcessResponse xmlns="http://xmlns.oracle.com/SwitchDemo">

<result>

Arpit

</result>

</SwitchDemoProcessResponse>

</part>
</outputVariable>

Now invoke the same process again with value 421 and you will get value

<outputVariable>
- <part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="payload">
- <SwitchDemoProcessResponse xmlns="http://xmlns.oracle.com/SwitchDemo">

<result>

Ankit

</result>

</SwitchDemoProcessResponse>

</part>
</outputVariable>

This is because our condition is if the input <420 then assign "Arpit" to the output variable otherwise for all other input the value should be "Ankit"

So this illustrate its use case.You can add more conditional braches as per your wish by clicking on this button



you can further provide your own condition for this new switch block you can again add some more otherwise block by click on the buttion next to the previous button.

No comments: