4 Replies Latest reply on Jul 16, 2010 11:44 AM by johannesk

    How to use GetProcessInstanceVariablesCommand?

    johannesk

      Hi,

       

      I'm trying to call a jBPM process from ESB with an esbToBpmVars and a bpmToEsbVars mapping. I'm using jboss-5.1.0.GA with jbossesb-4.8 installed. The actions that are called in the process change BPM vars, but the change does not reflect in the ESB vars. Can anyone give me a hint, how to solve this?

       

      My service prints the incoming message, than calls an jBPM process and afterwards print the outgoing message:

       

        <service category="Test" description="The Test Service"
         invmScope="GLOBAL" name="TestService">
         <actions mep="RequestResponse">
          <action name="printlnBefore">
           <property name="message"/>
           <property name="printfull" value="true"/>
          </action>
          <action name="jBPM">
           <property name="command" value="StartProcessInstanceCommand"/>
           <property name="process-definition-id" value="5"/>
           <property name="esbToBpmVars">
            <mapping bpm="jbpmVar1" esb="var1"/>
            <mapping bpm="jbpmVar2" esb="var2"/>
           </property>
          </action>
          <action name="jBPMvars">
           <property name="command" value="GetProcessInstanceVariablesCommand"/>
           <property name="bpmToEsbVars">
            <mapping bpm="jbpmVar1" esb="var1"/>
            <mapping bpm="jbpmVar2" esb="var2"/>
           </property>
          </action>
          <action name="printlnAfter">
           <property name="message"/>
           <property name="printfull" value="true"/>
          </action>
         </actions>
        </service>
      

       

      The jBPM process is defined as a fork with transitions to two nodes that use "test.jbpmesb.handlers.CustomNode1" and "...CustomNode2":

       

      <process-definition name="process1">
          <start-state name="start">
              <transition to="fork1"></transition>
          </start-state>
          <fork name="fork1">
              <transition to="node1" name="to node1"/>
              <transition to="node2" name="to node2"/>
          </fork>
          <node name="node1">
              <action class="test.jbpmesb.handlers.CustomNode1"/>
              <transition to="join1"/>
          </node>
          <node name="node2">
              <action class="test.jbpmesb.handlers.CustomNode2"/>
              <transition to="join1"/>
          </node>
          <join name="join1">
              <transition to="end"/>
          </join>
          <end-state name="end"/>
      </process-definition>
      

       

      The Node implementations simply read the variable jbpmVar1 (respectively jbpmVar2) and set it to a modified value:

       

       

      package test.jbpmesb.handlers;
      
      import org.jbpm.graph.def.ActionHandler;
      import org.jbpm.graph.exe.ExecutionContext;
      
      public class CustomNode1 implements ActionHandler {
          private static final long serialVersionUID = 5783771288537932931L;
          
          public void execute(ExecutionContext ctx) throws Exception {
              String jbpmVar = (String) ctx.getVariable("jbpmVar1");
              String newJbpmVar = jbpmVar + jbpmVar;
              ctx.setVariable("jbpmVar1", newJbpmVar);
              ctx.leaveNode();
          }
      }
      

       

      (CustomNode2 is almost the same, except that it uses jbpmVar2)

       

      The message before the invocation with the values var1=erste and var2=zweite:

       

      19:06:13,375 INFO  [STDOUT] Message structure: 
      19:06:13,375 INFO  [STDOUT] [ message: [ JBOSS_XML ]
      header: [ To: InVMEpr [ PortReference < <wsa:Address invm://54657374242424242424242424242424546573745365727669636533/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] ReplyTo: InVMEpr [ PortReference < <wsa:Address invm://thread-124-6/>, <wsa:ReferenceProperties jbossesb:passByValue : false/>, <wsa:ReferenceProperties jbossesb:temporaryEPR : true/> > ] MessageID: a8172743-8346-4bd7-b656-b93d356eb427 ]
      context: {}
      body: [ objects: {org.jboss.soa.esb.message.defaultEntry=Hello World, var1=erste, var2=zweite} ]
      fault: [  ]
      attachments: [ Named:{}, Unnamed:[] ]
      properties: [ {} ] ]
      

       

      And after the invocation still var1=erste and var2=zweite, but should be var1=ersteerste and var2=zweitezweite:

       

      19:06:13,438 INFO  [STDOUT] Message structure: 
      19:06:13,469 INFO  [STDOUT] [ message: [ JBOSS_XML ]
      header: [ To: InVMEpr [ PortReference < <wsa:Address invm://54657374242424242424242424242424546573745365727669636533/false?false#10000/>, <wsa:ReferenceProperties jbossesb:passByValue : false/> > ] ReplyTo: InVMEpr [ PortReference < <wsa:Address invm://thread-124-6/>, <wsa:ReferenceProperties jbossesb:passByValue : false/>, <wsa:ReferenceProperties jbossesb:temporaryEPR : true/> > ] MessageID: a8172743-8346-4bd7-b656-b93d356eb427 ]
      context: {}
      body: [ objects: {bpmToEsbVars=[Mapping[ esb=var1, bpm=jbpmVar1, isProcessScope=null, defaultValue=null ], Mapping[ esb=var2, bpm=jbpmVar2, isProcessScope=null, defaultValue=null ]], jbpmProcessDefId=5, org.jboss.soa.esb.message.defaultEntry=Hello World, jbpmProcessInstId=35, jbpmCommandCode=GetProcessInstanceVariablesCommand, jbpmVariableMappings={jbpmVar1=erste, jbpmVar2=zweite}, var1=erste, var2=zweite} ]
      fault: [  ]
      attachments: [ Named:{}, Unnamed:[] ]
      properties: [ {jboss.esb:category=MessageCounter,deployment=test-esb.esb,service-category=Test,service-name=TestService3Time=67507462} ] ]
      

       

      What am I doing wrong?

       

      Kind regards

       

      Johannes Krämer