4 Replies Latest reply on Aug 1, 2006 10:34 AM by Ronald van Kuijk

    How to invoke a deployed business process

    Brad O'Hearne Newbie

      From the JUnit test classes that comes with the samples, I can see how to invoke a stand-alone business process. But once a business process is deployed, how do I invoke a deployed business process from a Java class?

      Basically the use case I have is this: I would like to have the jbpm engine running in JBoss, and have business processes invoked either as the result of a web service invocation, or a web request (servlet invocation). So in other words, this requires invocation of a business process from a Java class.

      The JUnit test classes don't seem to interact with any central engine, or deployed business process. In the JUnit test classes, the business processes are directly loaded from their XML files, and invoked. So how do I interact with a central engine that manages already deployed business processes, and get it to invoke the business process from an external Java class?

        • 1. Re: How to invoke a deployed business process
          Brad O'Hearne Newbie

          Can anyone help me with this? What is the proper way to invoke a business process deployed in JBoss from Java code (like a servlet).

          Thanks.

          • 2. Re: How to invoke a deployed business process
            Kevin Barfield Newbie

            There is a full API for interacting with jBPM from Java code. Please take a look at the sample web app that comes with jBPM. It is Java code calling processes that have been deployed to jBPM. This code fragment example is from the HomeBean.java in jbpm-starters-kit-3.1\jbpm\src\java.webapp\org\jbpm\webapp\bean

            /**
             * prepares a task form for starting a new process instance.
             */
             public String startProcessInstance() {
             // Get the task instance id from request parameter
             long processDefinitionId = JsfHelper.getId("processDefinitionId");
             ProcessDefinition processDefinition = graphSession.loadProcessDefinition(processDefinitionId);
            
             // create a new process instance to run
             ProcessInstance processInstance = new ProcessInstance(processDefinition);
            
             // create a new taskinstance for the start task
             TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();
            
             // Save the process instance along with the task instance
             jbpmContext.save(processInstance);
            
             // Fill the task backing bean with useful information
             taskBean.initialize(taskInstance);
            
             return "task";
             }


            • 3. Re: How to invoke a deployed business process
              Tomasz Domagala Newbie

              I'm a JBoss newbie and let me assure myself. Cause I agree with Brado it is not clearly stated, I think :-)
              If I write, say, a session bean that uses objects and methods like those in the HomeBean class, wil it work? Will these methods in the deployed session bean find eg process instances deployed on the server?
              Best regards,
              Thomas

              • 4. Re: How to invoke a deployed business process
                Ronald van Kuijk Master

                why wouldn't they? The thing you have to look out for is to have a JbpmContext. In the webapp that is done automagically.