5 Replies Latest reply on Apr 23, 2014 8:41 AM by Espen Jervidalo

    Error Boundary events and signals

    Espen Jervidalo Newbie

      Hi

       

      I have been trying to introduce Error handling by attaching an Error Boundary event to a custom activity which throws exception in case of error. As i want to go into a "retry-loop" in case of error, I decided to do it a bit differently than explained in the documentation. Please see my note in the bottom for another reason.

      So the important part of the process looks like this:

      Screen Shot 2014-04-17 at 11.13.08.png

       

      The custom activity is decorated by the org.jbpm.bpmn2.handler.SignallingTaskHandlerDecorator and the event-type I'm signalling is called "some-error". I configured the boundary event's error code to "some-error" and started debugging.

      So the exception is thrown, the process gets correctly signalled with "some-error".

      BUT the problem I see is that the boundary event is expecting a event-type called "Error-Task_<random_number>-some-error".

      This event-type is put together inside: org.jbpm.bpmn2.xml.BoundaryEventHandler#handleErrorNode on line 177:

       

      eventFilter.setType("Error-" + attachedTo + "-" + type);

       

      where attachedTo is the attached Node, but not even the name of the node given in process, but that generated by the editor. So you have no possibility to know the name of the event-type without actually debugging.

       

      Now, either I'm misunderstanding something here and if so, please explain, or this must be some sort of bug?

       

      BTW if I change the event-type while debugging to fit the expected event-type from the signal, everything works like a charm.

       

      Some hints would be very much appreciated.

       

      Cheers,

      Espen

       

      Note: The other reason is that the documented approach does not work with the BPMN2 modeller from Eclipse. It does not allow creating sub processes started by events: You have to manually add the triggeredByEvent to your processes XML structure, which then gets removed every time the document is saved..

        • 1. Re: Error Boundary events and signals
          Espen Jervidalo Newbie

          Ok, so after digging through code trying to find some way to get the node name from the passed WorkItem in the SignallingTaskHandlerDecorator for then to put together the event-type I realised that e.g. in the org.jbpm.bpmn2.xml.BoundaryEventHandler#handleSignalNode method, this event-type manipulation is not done:

                              eventFilter.setType(type);

           

          I changed the Boundary event to simply send a "Signal" instead of an "Error" and now it works.

          Still I would prefer to have the Error Signal there, as it makes it more clear what it actually does. I leave the question unanswered for now.

           

          Cheers,

          Espen

          • 2. Re: Error Boundary events and signals
            Maciej Swiderski Master

            Espen,

             

            instead of using the signal decorator (which is more suitable when you try to signal another type of catching events than errors) you can reply on the handleException logic that is provided by AbstractLogOrThrowWorkItemHandler, just make sure you custom handler extends it and invokes handleException in case of an error. With that it should directly invoke your error boundary event. There you have to ways of specifying the matching criteria, by exception class name or simply catch all. See this process definition and this test case for some sample usage.

             

            P.S.

            when it comes to eclipse modeler, please file a bug report in eclipse bugzilla for the modeler so it gets added. Maybe it is only a matter of configuration what elements are supported somewhere in the configuration of the tool.

             

            HTH

            • 3. Re: Error Boundary events and signals
              Espen Jervidalo Newbie

              Hi Maciej,

               

              Thanks for your reply!

              I tried to follow your advise and throw the org.jbpm.bpmn2.handler.WorkItemHandlerRuntimeException instead of signalling directly. That works to a certain degree, but again I'm having difficulties catching the correct errorCode in the Boundary Event, or how you put it: the "matching criteria".

              I loaded the process definition you provided and just changed the implementation class of the "Service Task" handler to a very simple one, which basically just throws an exception using the handleException method. I guess the only relevant part is this:

                      wihRe.setInformation(WorkItemHandlerRuntimeException.WORKITEMHANDLERTYPE, this.getClass().getSimpleName());

               

              Here's how it fails:

              org.jbpm.workflow.instance.node.WorkItemNodeInstance#internalTrigger line 131

                      String exceptionName = e.getClass().getName();

              which is the name of the exception. From here on it tries to resolve an exception handler using this name as parameter and "ExceptionScope" as contextId.

               

              Eventually I end up in org.jbpm.process.core.context.exception.ExceptionScope#getExceptionHandler.

              Screen Shot 2014-04-22 at 15.41.46.png

              The mapping key is WsError, the ErrorCode specified in the process, and the key it's looking up, is again the exceptions name.

               

              So the only way I got this example to work, was to set the errorCode in the process to the expected exceptions name, which is not the case in the test-process you provided. Is this how it should be?

               

              Thanks and cheers,

              Espen

              • 4. Re: Error Boundary events and signals
                Maciej Swiderski Master

                Espen, what version are you using? There where improvements in error handling area post 6.0.1 release so if you're not on 6.1.0 then you might be missing these improvements.

                 

                In general, you should be able to specify structureRef attribute on the error element of bpmn2 that actually refers to the exception type you expecting for that error, if it is not set all exception should be caught by the attached error event. The first one is used in the example I linked.

                 

                HTH

                • 5. Re: Error Boundary events and signals
                  Espen Jervidalo Newbie

                  Hi Maciej,

                  Again, thanks for the reply. That's what I was expecting concerning the structureRef attribute. But didn't seem to work, will try later on with 6.1.

                   

                  Thanks for your help!

                   

                  Cheers,

                  Espen