2 Replies Latest reply on May 30, 2007 11:33 AM by wash

    Process definition instanciation (java call)

    Newbie

      Hi Guys !

      We are trying to start a new jBPM process instance from java code, is there any sample code to perform it properly? We are able to send a notification for an suspended instance, but when we try to create an instance, then we don't have a jobId which must be specified.

      As we know a JobID is normally related to a pending task and not for a creation.

      Our code looks like:




      InitialContext ic = new InitialContext();
       QueueConnectionFactory qcf = (QueueConnectionFactory) ic.lookup("XAConnectionFactory");
       qc = qcf.createQueueConnection();
       qc.start();
       session = qc.createQueueSession(true, QueueSession.AUTO_ACKNOWLEDGE);
       Queue queue = (Queue) ic.lookup("queue/JbpmCommandQueue");
       QueueSender sender = session.createSender(queue);
      
       //ObjectMessage msg = session.createObjectMessage();
       ObjectMessage om = session.createObjectMessage();
      
       HashMap<String, Object> map = new HashMap<String, Object>();
       map.put("long99", new Long(99));
       map.put("stringABC", "ABC");
       map.put("boolean", new Boolean(false));
       om.setObject(map);
      
       org.jbpm.command.NewProcessInstanceCommand newProcessInstanceCmd = new org.jbpm.command.NewProcessInstanceCommand();
      
       newProcessInstanceCmd.setActorId("ernie");
       newProcessInstanceCmd.setCreateStartTask(true);
       newProcessInstanceCmd.setProcessId(38L);
       newProcessInstanceCmd.setProcessName("ProcessName");
       newProcessInstanceCmd.setVariables(map);
      
       om.setObject(newProcessInstanceCmd);
       //om.setLongProperty("jobId", 286L);
       sender.send(om);
       sender.close();
       session.commit();




      Wash

        • 1. Re: Process definition instanciation (java call)
          Newbie

          Hi all,

          If we don't specify jobId, we have an exception because the MDB could not extract a jobId from the message send to the queue.

          It seems like we have to specify a jobId when creating a new process instance, although this is not logical.

          Can someone help us?


          Kind regards



          • 2. Re: Process definition instantiation (java call)
            Newbie

             

            "Wash" wrote:
            Hi Guys !

            We are trying to start a new jBPM process instance from java code, is there any sample code to perform it properly? We are able to send a notification for an suspended instance, but when we try to create an instance, then we don't have a jobId which must be specified.

            As we know a JobID is normally related to a pending task and not for a creation.

            Our code looks like:




            InitialContext ic = new InitialContext();
             QueueConnectionFactory qcf = (QueueConnectionFactory) ic.lookup("XAConnectionFactory");
             qc = qcf.createQueueConnection();
             qc.start();
             session = qc.createQueueSession(true, QueueSession.AUTO_ACKNOWLEDGE);
             Queue queue = (Queue) ic.lookup("queue/JbpmCommandQueue");
             QueueSender sender = session.createSender(queue);
            
             //ObjectMessage msg = session.createObjectMessage();
             ObjectMessage om = session.createObjectMessage();
            
             HashMap<String, Object> map = new HashMap<String, Object>();
             map.put("long99", new Long(99));
             map.put("stringABC", "ABC");
             map.put("boolean", new Boolean(false));
             om.setObject(map);
            
             org.jbpm.command.NewProcessInstanceCommand newProcessInstanceCmd = new org.jbpm.command.NewProcessInstanceCommand();
            
             newProcessInstanceCmd.setActorId("ernie");
             newProcessInstanceCmd.setCreateStartTask(true);
             newProcessInstanceCmd.setProcessId(38L);
             newProcessInstanceCmd.setProcessName("ProcessName");
             newProcessInstanceCmd.setVariables(map);
            
             om.setObject(newProcessInstanceCmd);
             //om.setLongProperty("jobId", 286L);
             sender.send(om);
             sender.close();
             session.commit();




            Wash