Uploaded image for project: 'jBPM'
  1. jBPM
  2. JBPM-3792

WorkItemHandler gets null from StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession() in its constructor

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor Minor
    • jBPM 5.4.0.CR1
    • jBPM 5.3
    • Console
    • None

      Assuming a custom WorkItemHandler which wants to have a reference to ksession in jbpm-gwt-console-server.

      public class MyWorkItemHandler implements WorkItemHandler {
          
          private StatefulKnowledgeSession ksession;
          
          public MyWorkItemHandler() {
              System.out.println("constructor : getting ksession");
              ksession = org.jbpm.integration.console.StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession();
              System.out.println("constructor : " + ksession);
          }
      ...
      
      • Set up based on jBPM 5.3.0 installer
      • Copy customworkitemhandler.jar to $JBOSS_HOME/standalone/deployments/jbpm-gwt-console-server.war/WEB-INF/lib
      • Copy drools.session.conf and CustomWorkItemHandlers.conf to $JBOSS_HOME/standalone/deployments/jbpm-gwt-console-server.war/WEB-INF/classes/META-INF/
      • Start JBoss AS
      • Import repository_export_log_task.xml to Guvnor
      • Go to http://localhost:8080/jbpm-console/ and login

      You will see that StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession() returns null.

      16:30:54,668 INFO  [stdout] (http-localhost-127.0.0.1-8080-5) constructor : getting ksession
      16:30:54,668 INFO  [stdout] (http-localhost-127.0.0.1-8080-5) constructor : null
      
      Daemon Thread [http-localhost-127.0.0.1-8080-3] (Suspended)	
      	StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession() line: 131	
      	MyWorkItemHandler.<init>() line: 14	
      	NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]	
      	NativeConstructorAccessorImpl.newInstance(Object[]) line: 57	
      	DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 45	
      	Constructor<T>.newInstance(Object...) line: 532	
      	NewObjectNode.getReducedValue(Object, Object, VariableResolverFactory) line: 274	
      	MVELInterpretedRuntime.parseAndExecuteInterpreted() line: 106	
      	MVELInterpretedRuntime.parse() line: 49	
      	MVEL.eval(String, Object, VariableResolverFactory) line: 150	
      	InlineCollectionNode.execGraph(Object, Class, Object, VariableResolverFactory) line: 180	
      	InlineCollectionNode.execGraph(Object, Class, Object, VariableResolverFactory) line: 138	
      	InlineCollectionNode.getReducedValue(Object, Object, VariableResolverFactory) line: 105	
      	MVELInterpretedRuntime.parseAndExecuteInterpreted() line: 106	
      	MVELInterpretedRuntime.parse() line: 49	
      	MVEL.eval(String, Map<String,Object>) line: 165	
      	SessionConfiguration.loadWorkItemHandlers(String) line: 304	
      	SessionConfiguration.initWorkItemHandlers() line: 294	
      	SessionConfiguration.getWorkItemHandlers() line: 269	
      	ReteooStatefulSession(AbstractWorkingMemory).getWorkItemManager() line: 1106	
      	StatefulKnowledgeSessionImpl.getWorkItemManager() line: 311	
      	SingleSessionCommandService$SynchronizationImpl.afterCompletion(int) line: 452	
      	JtaTransactionSynchronizationAdapter.afterCompletion(int) line: 22	
      	SynchronizationImple.afterCompletion(int) line: 117	
      	AtomicAction(TwoPhaseCoordinator).afterCompletion(int, boolean) line: 403	
      	AtomicAction(TwoPhaseCoordinator).end(boolean) line: 104	
      	AtomicAction(AtomicAction).commit(boolean) line: 159	
      	TransactionImple.commitAndDisassociate() line: 1159	
      	UserTransactionImple(BaseTransaction).commit() line: 119	
      	JtaTransactionManager.commit(boolean) line: 179	
      	SingleSessionCommandService.<init>(Integer, KnowledgeBase, KnowledgeSessionConfiguration, Environment) line: 200	
      	NativeConstructorAccessorImpl.newInstance0(Constructor, Object[]) line: not available [native method]	
      	NativeConstructorAccessorImpl.newInstance(Object[]) line: 57	
      	DelegatingConstructorAccessorImpl.newInstance(Object[]) line: 45	
      	Constructor<T>.newInstance(Object...) line: 532	
      	KnowledgeStoreServiceImpl.buildCommandService(Integer, KnowledgeBase, KnowledgeSessionConfiguration, Environment) line: 101	
      	KnowledgeStoreServiceImpl.loadStatefulKnowledgeSession(int, KnowledgeBase, KnowledgeSessionConfiguration, Environment) line: 84	
      	JPAKnowledgeService.loadStatefulKnowledgeSession(int, KnowledgeBase, KnowledgeSessionConfiguration, Environment) line: 131	
      	StatefulKnowledgeSessionUtil.createOrLoadStatefulKnowledgeSession(KnowledgeBase) line: 281	
      	StatefulKnowledgeSessionUtil.initializeStatefulKnowledgeSession() line: 154	
      	StatefulKnowledgeSessionUtil$SessionHolder.<clinit>() line: 127	
      	StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession() line: 131	
      	TaskManagement(SessionInitializer).<init>() line: 25	
      	TaskManagement.<init>() line: 51	
      	ManagementFactory.createTaskManagement() line: 26	
      	ManagementFactory.createTaskManagement() line: 19	
      	TaskListFacade.getTaskManagement() line: 72	
      	TaskListFacade.getTasksForIdRef(String) line: 101	
      ...
      

      Actually, this happened in recursive calls of StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession() and SessionHolder.statefulKnowledgeSession was null at that time.

      A workaround is calling StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession() in WorkItemHandler.executeWorkItem().

          public void executeWorkItem(WorkItem workItem, WorkItemManager manager) {
              
              if (ksession == null) {
                  System.out.println("executeWorkItem : getting ksession");
                  ksession = org.jbpm.integration.console.StatefulKnowledgeSessionUtil.getStatefulKnowledgeSession();
              }
              System.out.println("executeWorkItem : " + ksession);
      ...
          }
      

              swiderski.maciej Maciej Swiderski (Inactive)
              rhn-support-tkobayas Toshiya Kobayashi
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: