7 Replies Latest reply on Oct 24, 2007 8:26 AM by David Roberts

    Communication between JBoss jBPM application and a web appli

    Kamlesh Kumar Newbie

      Hi,

      I have to trigger my jBPM application from a web application deployed in JBoss. In other words if i want to invoke my jBPM application from a JSP or Servlet and vice versa, what steps should i follow?

      Thanks
      Kamlesh

        • 1. Re: Communication between JBoss jBPM application and a web a
          Ronald van Kuijk Master

          the same steps you would do in just using the api, or the ones done in the webconsole or in the struts example in the wiki:

          Get a reference to a JbpmContext and perform all operations on that api.

          Look at the examples/source/testcases a little and all will become clear ;-)

          • 2. Re: Communication between JBoss jBPM application and a web a
            Kamlesh Kumar Newbie

            Hi Ronald,
            Thanks for your response..
            I am still not able to get it. I have seen the testcase class. In this class the ProcessDefinition is instantiated by parsing the corresponding xml file and then ProcessInstance is created using the ProcessDefinition.

            But the thing is, what code i will write inside my jsp to call the application. Means suppose i want to call the example/websale application from my index.jsp, what code i should write? can you elaborate it with some piece of code.

            Thanks
            Kamlesh

            • 3. Re: Communication between JBoss jBPM application and a web a
              David Roberts Apprentice

              All the code you require is in the jbpm-console web application source code. That's probably where most people will learn how to interact with the Jbpm lilbraries.

              For example, here is a method in one of my action classes, which shows how I start a process in my own web application:



              public ActionForward startProcess(ActionMapping mapping, ActionForm form,
               HttpServletRequest request,
               HttpServletResponse response)
               throws Exception {
               if (log.isDebugEnabled()) {
               log.debug("Entering 'startProcess' method");
               }
               User currentUser = getUser(request);
               String processDefinitionIdStr = request.getParameter("processDefinitionId");
               long processDefinitionId = Long.parseLong(processDefinitionIdStr);
               jbpmContext.setActorId(currentUser.getUsername());
               GraphSession graphSession = jbpmContext.getGraphSession();
               ProcessDefinition processDefinition = graphSession.getProcessDefinition(processDefinitionId);
               ProcessInstance processInstance = processDefinition.createProcessInstance();
               // Signal the root token based on the following criteria:
               // 1. If there is no start task, and
               // 2. If the root token is still at the start state, and
               // 3. If the start state has a default leaving transition, then
               // signal the token along the default transition.
               TaskMgmtInstance taskMgmtInstance = processInstance.getTaskMgmtInstance();
               //set the current user as the initiator
               processInstance.getContextInstance().setVariable("sys_initiator", currentUser.getUsername());
               TaskInstance startTaskInstance = taskMgmtInstance.createStartTaskInstance();
               if (startTaskInstance == null) {
               // There is no start task
               Node initialNode = processDefinition.getStartState();
               Token rootToken = processInstance.getRootToken();
               Node rootTokenNode = rootToken.getNode();
               if (initialNode.getId() == rootTokenNode.getId()) {
               // The root token is still at the start node
               Transition defaultLeavingTransition = initialNode.getDefaultLeavingTransition();
               if (defaultLeavingTransition != null) {
               // There's a default transition
               rootToken.signal(defaultLeavingTransition);
               System.out.println("Signalled Root Token");
               }
               }
               }
               System.out.println("Started");
               if (processInstance.hasEnded()) {
               System.out.println("Finished");
               }
               // Nothing else saves the process, so we must
               jbpmContext.save(processInstance);
              
               return mapping.findForward("myTasks");
               }


              And guess what, if I remember correctly, that was taken almost exactly as it from the jbpm-console webapp source code. So take a look there if you need help.

              Good luck!

              • 4. Re: Communication between JBoss jBPM application and a web a
                Kamlesh Kumar Newbie

                I understood a bit about how to call the process from a servlet. But in order to run this piece of code how should I integrate my jbpm application which is in eclipse workspace into my web-application ? Please tell me the steps. .

                • 5. Re: Communication between JBoss jBPM application and a web a
                  Kamlesh Kumar Newbie

                  Where is the jbpm-console source code. I have the jbpm-console.war, but after unzipping it i find no *.jsf files in it

                  • 6. Re: Communication between JBoss jBPM application and a web a
                    Kamlesh Kumar Newbie

                    Sorry by *.jsf files i mean the source code of the class file to which the *.jsf files are mapped in web.xml