8 Replies Latest reply on Aug 26, 2009 8:54 PM by Leo van den berg

    JBPM + REST problem

    Leo van den berg Master

      I am trying to get JBPM working in combination with a Rest-Service. The idea is simple. We send a message to a mobile phone, which replies to a Rest service. I get the Business process working using an asynchronous observer method:

      /** This method is called whenever the related event occurs */
       public String acceptMessage(String actor) {
              log.info("Traffic inspector " + actor + " has accepted the task.");
              inspector = actor;
              return "ok";

      If I leave out the @Asynchronous annotation I get an error that the Hibernate session is closed (I assume that is the JBPM session to store the BPM-state).

      But I am a bit stuck now, I want to use a second REST-call to get Tasks started/ended. My first problem is that I need to use a taskId to include in the url as a query-string, but how to get there : I tried using JBpmContext, but than I get the following error:

      JbpmContext may only be used inside a transaction

      I've seen the Seam In Action example, which uses the JBPM context but I get the before mentioned error.

      Has anyone done this?

      Thanks in advance,


        • 1. Re: JBPM + REST problem
          Ronald van Kuijk Apprentice


          jBPM indeed has it's own hibernate session (there is an open jira for this), so the 'session closed' can come from there.

          I do not fully understand what you mean by

          but how to get there : I tried using JBpmContext,

          How did you use the (Seam) JBpmContext? just like the normal JbpmContext?

          My experience is that the integration needs some overhauling, and using a plain JbpmContext (the jBPM one, not the Seam one) works better. I've even developed an annotation that does the whole 'try/catch/finally' normally needed by jBPM and kind of 'injecting' the context into methods where needed to circumvent some jBPM/Seam problems

          • 2. Re: JBPM + REST problem
            Leo van den berg Master

            Hi Ronald,

            Some background about our new module:

            We are including a new (road) traffic management task in our system. The idea is that we send a SMS message (already works) to a RoadInspector. He/she has a mobile phone and accept or refuse the message. When accepted the Process should start. The simplest way to implement this seemed the RestEasy interface. So the phone sends an userToken (we get the actor-id, by looking up the User in  the DB) and taskId to a URL for every task and retrieves the next taskId as a reply. There are a number of steps defined and after the last task, the Traffic Isnpector is freed-up for a new Message.

            The JBPMContext injection doesn't work directly in the REST-bean. There we get the message that it can only be used in a Transaction, so we moved the code to a EJB and that works (although we neede to add

            <transaction:ejb-transaction  />

            to components.xml (simple bu very nasty hidden configuration setting I must say...)

            Now the next step is to get the chain of request-replies working (nothing special, it's basically a simple reply-message). For the first step we need to get the taskId to the SMS-message. If we use the @CreateProcess annotation, the BPM context is not visible to us. So there is where the search begins.

            - We need to start the process,
            - We have to find the present-task for the selected Traffic Inspector.

            I hoped to be able to use the jBPM-Seam annotations (I am a VERY lazy programmar) , and fill the taskId from the startTask through the requestparameter. But I am still fighting with the first step. How to get the taskId from the just started proces...


            • 3. Re: JBPM + REST problem
              Ronald van Kuijk Apprentice

              Did you also @StartTask something? Otherwise no taskid is associated with the conversation.

              And maybe something like BusinessProcess.instance().... yields some results. Might be that you need to 'wrap' the method annotated with the @CreateProcess in another method and use it in this wrapper method. There might even be a business process id stored in the conversation, I do not remember that fully anymore.

              • 4. Re: JBPM + REST problem
                Leo van den berg Master

                I made some new test-routines to see what happens internally.

                What strikes me is that the SLSB has full access to jBPM-context when called from the REST-service  (with some help of
                @TransactionAttribute(TransactionAttributeType.REQUIRED)  on the method) , while I can't do the same on the REST-call.

                At the moment I am accessing directly the jBPM-api and it's not so complex as expected, but I prefer doing it with annotations. I think the basics will be ready by tomorrow and I hope you can help me a bit to see if things can be optimized.



                • 5. Re: JBPM + REST problem
                  Ronald van Kuijk Apprentice

                  Basic things in the core jbpm 3 'api' is not that different from the wrapper Seam uses.

                  Sure, you may even send me a small project via mail at ronald @ mpbj (reverse) .org

                  You are welcome/Graag gedaan,

                  (btw, spain?)

                  • 6. Re: JBPM + REST problem
                    Ronald van Kuijk Apprentice

                    And regarding the access to the jBPM context or lack thereof in the REST service, do other injections work?

                    • 7. Re: JBPM + REST problem
                      Ronald van Kuijk Apprentice

                      Oh, and what is 'funny', check out http://fisheye.jboss.org/changelog/JbpmSvn/projects/demos/trainticket-demo, nice demo with 'sms', jbpm etc. Just checked in.

                      • 8. Re: JBPM + REST problem
                        Leo van den berg Master

                        Hi Ronald,

                        the first part works. I had some additional problems with Ajax, but that was solved when I use Async-calls with Observer.

                        One of the specific things of the REST-bean there is that is needs to have a Session-scope (otherwise the container calls remove on the used SFSB to early). The Session-Scope for REST prevents this and additionally it stays open until the session is no longer needed.

                        The first call is to acknowledge the received SMS. The phone calls the REST-service, which in turn calls the SFSB. I inject the jbpmContext, use the normal jBPM API's to create a new Process and return the taskId.to the REST-service which send that back as response to the phone.

                        The following calls are basically the same. I look up the task - handle all the functionality and end the task.

                        Nice combination of Seam and jBPM.

                        If done some workflow-stuff in the past, bit this save a lot of time !


                        P.S. The code needs some cleaning up, but I will definitely send it to the forum for some code walk-through..