Search code examples
eclipseapachebpel

How to properly initialize variable in Eclipse BPEL designer Apache ODE engine?


I have a simple BPEL variable of int datatype. The process gets deployed, but on execution, the ODE engine complains that the “variable counter isn’t properly initialized”. What is wrong with the below initialization code?

<bpel:variable name="counter" type="ns1:int">

<bpel:assign validate="no" name="setVariables">

<bpel:copy> <bpel:from><bpel:literal xml:space="preserve">1</bpel:literal>
            </bpel:from>
            <bpel:to variable="counter"></bpel:to>
        </bpel:copy> </bpel:assign>

Solution

  • I'll take the working solution from the comments to the question and provide it as answer, so that the question can be recorded as answered.

    The problem can be solved by initializing the variable on its definition and not via a later assign during process execution. That way, the variable is guaranteed to be initialized on its first access. Default initialization for the variable at hand looks like this:

    <bpel:variable name="counter" type="ns1:int"><bpel:from>1</bpel:from></variable>