Wednesday, August 8, 2012

How to avoid Selection Failure in Assign activity


One of the queries I got recently was on how to handle selection failures in assign activity if the tags are not present as part of the payload.
To show case how it works I will just do a small sample program which assigns input variable to output variable. I am using PS5(11.1.1.6) environment and BPEL2.0 as specification.
I am using BPEL 2.0 spec, but the solution works in BPEL 1.1 also.
Example:-  I use a simple assign activity to assign 2 elements of input to output.

  <assign name="Assign1" xml:id="id_11">
            <copy xml:id="id_16">
                <from xml:id="id_17">$inputVariable.payload/client:input1</from>
                <to xml:id="id_18">$outputVariable.payload/client:result1</to>
            </copy>
            <copy xml:id="id_19" ignoreMissingFromData="no">
                <from xml:id="id_20">$inputVariable.payload/client:input2</from>
                <to xml:id="id_21">$outputVariable.payload/client:result2</to>
            </copy>
        </assign>


For testing this I pass only one element in payload. The element2 tag is not present in the payload.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bpel="http://xmlns.oracle.com/BPMLearning/Project1/BPELProcess1">
   <soapenv:Header/>
   <soapenv:Body>
      <bpel:process>
         <bpel:input1>hello</bpel:input1>
        </bpel:process>
   </soapenv:Body>
</soapenv:Envelope>



In runtime it throws following selection failure error
Exception stack trace:
Exception is thrown because the from-spec at line 61 is evaluated to be empty
-<details>
-<from-spec>
<from xml:id="id_20" xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable">
$inputVariable.payload/client:input2
</from>
</from-spec>
-<variable>
<message>
inputVariable
</message>
</variable>
-<fault>
-<bpelFault>
<faultType>
0
</faultType>
<selectionFailure xmlns="http://docs.oasis-open.org/wsbpel/2.0/process/executable"/>
</bpelFault>
</fault>
</details>


Solution
 To fix this there is an attribute ignoreMissingFromData
The ignoreMissingFromData attribute suppresses any bpel:selectionFailure standard faults.
BPEL 1.1  syntax
BPEL 2.0 syntax
<copy bpelx:ignoreMissingFromData="yes|no"/>
<copy ignoreMissingFromData="yes|no"/>


 
<assign name="Assign1" xml:id="id_11">
            <copy xml:id="id_16">
                <from xml:id="id_17">$inputVariable.payload/client:input1</from>
                <to xml:id="id_18">$outputVariable.payload/client:result1</to>
            </copy>
            <copy xml:id="id_19" ignoreMissingFromData="yes">
                <from xml:id="id_20">$inputVariable.payload/client:input2</from>
                <to xml:id="id_21">$outputVariable.payload/client:result2</to>
            </copy>
        </assign>

The error gets suppressed since it ignores the element as the ignoreMissingFromData flag is set to yes.
BPEL instance execution stacktrace
Copy rule at line 64 is ignored because the evaluated from value is empty
<payload>

<details>
<from-spec>
<from  xml:id="id_23">$inputVariable.payload/client:input2</from>
</from-spec>
<variable>
<message>inputVariable</message>
</variable>
</details>


















That’s it .It’s an easy solution to selectionFailure instead of
 using the count nodes function and taking headaches in 
doing the mapping.


5 comments:

Sudheer said...

Dude... Thanks for the tip... Lemme try this... :)

Anirban Dhar said...

thanks a ton :)
worked like charm...

failing wings said...

Hi,

YOur blog was invaluable. would you happen to know if something simmilar is available in case of append or copylist

George Thomas said...

thanks, On your query of copylist /append ,the behavior will be the same beacuse ignoreMissingFromData is an attribute supported for all the extension assign operations.


Dhanraj Pimple said...

Hi George,

Thanks for the blog, btw this is Dhanraj.