4 Replies Latest reply on Jan 15, 2007 8:18 AM by someguyguy

    Task Handler (example is throwing an exception)

    dbmac45

      I am trying to run the following test, which was extracted from the jBPM examples source in the 3.0.1 starter's kit. The action example works great but the task assignment, as seen below, throws an exception. I've played with this for several days in attempt to get it working but have been unsuccesful thus far. I also haven't found any real-world examples or documentation, other than the jBPM tutorial, that has guided me to a solution.


      public void testTaskAssignment() {
       ProcessDefinition processDefinition = ProcessDefinition.parseXmlString(
       "<process-definition name='baby process'>" +
       " <start-state>" +
       " <transition name='baby cries' to='t' />" +
       " </start-state>" +
       " <task-node name='t'>" +
       " <task name='change nappy'>" +
       " <assignment class='com.jbay.taskmgmt.NappyAssignmentHandler' />" +
       " </task>" +
       " <transition to='end' />" +
       " </task-node>" +
       " <end-state name='end' />" +
       "</process-definition>"
       );
      
       // Create an execution of the process definition.
       ProcessInstance processInstance = new ProcessInstance(processDefinition);
       Token token = processInstance.getRootToken();
      
       // Start the process execution, leaving the start-state
       // over its default transition.
       token.signal();
       assertSame(processDefinition.getNode("t"), token.getNode());
      
       TaskInstance taskInstance = (TaskInstance)
       processInstance
       .getTaskMgmtInstance()
       .getTaskInstances()
       .iterator().next();
      
       // Now, we check if the taskInstance was actually assigned to 'papa'.
       //assertEquals("papa", taskInstance.getActorId() );
      
       // Now suppose that 'papa' has done his duties and marks the task
       // as done.
       taskInstance.end();
       // Since this was the last (only) task to do, the completion of this
       // task triggered the continuation of the process instance execution.
      
       assertSame(processDefinition.getNode("end"), token.getNode());
      }


      The assignment class is as follows:

      package com.jbay.taskmgmt;
      
      import org.jbpm.graph.exe.ExecutionContext;
      import org.jbpm.taskmgmt.def.AssignmentHandler;
      import org.jbpm.taskmgmt.exe.Assignable;
      
      public class NappyAssignmentHandler implements AssignmentHandler {
      
       private static final long serialVersionUID = 1L;
      
       public void assign(Assignable assignable, ExecutionContext executionContext) throws Exception {
       assignable.setActorId("papa");
       }
      }



      The information for the exception that is thrown is as follows:

      18:25:22,243 DEBUG GraphElement : event 'process-start' on 'ProcessDefinition(baby process)' for 'Token(/)'
      18:25:22,253 DEBUG GraphElement : event 'before-signal' on 'StartState(120a47e)' for 'Token(/)'
      18:25:22,253 DEBUG GraphElement : event 'node-leave' on 'StartState(120a47e)' for 'Token(/)'
      18:25:22,253 DEBUG GraphElement : event 'transition' on 'Transition(baby cries)' for 'Token(/)'
      18:25:22,253 DEBUG GraphElement : event 'node-enter' on 'TaskNode(t)' for 'Token(/)'
      18:25:22,263 DEBUG JbpmConfiguration : jbpm.hibernate.properties=hibernate.properties
      java.lang.NullPointerException
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:261)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
       at org.jbpm.instantiation.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:16)
       at org.jbpm.taskmgmt.exe.TaskMgmtInstance.getTaskInstanceClass(TaskMgmtInstance.java:41)
       at org.jbpm.taskmgmt.exe.TaskMgmtInstance.instantiateNewTaskInstance(TaskMgmtInstance.java:174)
       at org.jbpm.taskmgmt.exe.TaskMgmtInstance.createTaskInstance(TaskMgmtInstance.java:74)
       at org.jbpm.graph.node.TaskNode.execute(TaskNode.java:136)
       at org.jbpm.graph.def.Node.enter(Node.java:284)
       at org.jbpm.graph.def.Transition.take(Transition.java:92)
       at org.jbpm.graph.def.Node.leave(Node.java:349)
       at org.jbpm.graph.node.StartState.leave(StartState.java:73)
       at org.jbpm.graph.exe.Token.signal(Token.java:127)
       at org.jbpm.graph.exe.Token.signal(Token.java:92)
       at com.jbay.HelloTest.testTaskAssignment(HelloTest.java:87)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at junit.framework.TestCase.runTest(TestCase.java:154)
       at junit.framework.TestCase.runBare(TestCase.java:127)
       at junit.framework.TestResult$1.protect(TestResult.java:106)
       at junit.framework.TestResult.runProtected(TestResult.java:124)
       at junit.framework.TestResult.run(TestResult.java:109)
       at junit.framework.TestCase.run(TestCase.java:118)
       at junit.framework.TestSuite.runTest(TestSuite.java:208)
       at junit.framework.TestSuite.run(TestSuite.java:203)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
       at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



      I've stepped through the debugger and execution never reaches my assignment task method, so it doesn't appear to be a problem with my assignment class. The exeception is thrown on the "token.signal()" method call.

      Any help would be appreciated.

      Dave M.