5 Replies Latest reply on Jul 30, 2009 7:01 AM by jimdwyer

    HowTo: Use JBPM4 API (on JBoss 5)

    djcye

      Hi,
      i am a newb. In order to (for example) add some Users and Roles i do need the API right ? Well i dont know how to get a 'connection' to the ProcessEngine. In the delivered examples 'only' a local process engine is created...

      In 5.2. ProcessEngine of the UserGuide they do:
      "ProcessEngine processEngine = new Configuration()
      .buildProcessEngine();"

      Can i "configure" somhow that it should use the JBPM on the JBoss ?

        • 1. Re: HowTo: Use JBPM4 API (on JBoss 5)
          jimdwyer

          I was wondering the same thing myself. Do I use JNDI, @EJB? How does it work now?

          • 2. Re: HowTo: Use JBPM4 API (on JBoss 5)
            jimdwyer

            From the usersguide, section 2.6

            In JBoss, the ProcessEngine can be obtained from JNDI with

            new InitialContext().lookup("java:/ProcessEngine")

            • 3. Re: HowTo: Use JBPM4 API (on JBoss 5)
              jbarrez

              Exactly. If you use the demo setup provided by the distribution, you can use the ProcessEngine which is bound to JNDI. You can adapt the database configuration in the jbpm folder (under deploy) for your database.

              Another solution is just to use jBPM as a standalone Jar, and creating a process engine using new Configuration().buildProcessEngine(). You can store this object in a static field for example (it's thread-safe).

              • 4. Re: HowTo: Use JBPM4 API (on JBoss 5)
                djcye

                But the

                "new InitialContext().lookup("java:/ProcessEngine")"

                Have to take place inside the JBoss right ? Has somone an example for this ?

                • 5. Re: HowTo: Use JBPM4 API (on JBoss 5)
                  jimdwyer

                  You need to built a little java class with a method like this:

                  public void startWorkflow(){
                  try{
                  InitialContext ctx = new InitialContext();
                  ProcessEngine processEngine = (ProcessEngine)ctx.lookup("java:/ProcessEngine");

                  // ProcessEngine and Services are to be used as singletons. (ie they are threadsafe)
                  RepositoryService repositoryService = processEngine.getRepositoryService();
                  ExecutionService executionService = processEngine.getExecutionService();
                  TaskService taskService = processEngine.getTaskService();
                  HistoryService historyService = processEngine.getHistoryService();
                  ManagementService managementService = processEngine.getManagementService();


                  ProcessInstance processInstance = executionService.startProcessInstanceByKey("AsyncActivity");
                  System.out.println("ProcessId: " + processInstance.getId());

                  }catch (NamingException ne){
                  System.out.println(ne);
                  }



                  Then call that from a jsp or something.

                  <%jsp useBean id="bean" class="org.someco.Test" scope="session" />
                  <% bean.startWorkflow(); %>

                  Package the class and jsp into a war, deploy the war on the jboss.

                  That should do it.