<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
Re: abortProcessInstance causes an exception
</h3>
<span style="margin-bottom: 10px;">
created by <a href="https://community.jboss.org/people/jnorris">jnorris</a> in <i>jBPM</i> - <a href="https://community.jboss.org/message/783484#783484">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hi Maciej,</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>We have a set of cxf web services that interface to the jbpm runtime.  We are not using any of the jbpm web apps and are running in an osgi container.  When the web services is invoked a setup method gets a bean that has the jbpm api calls.  A setup method creates the session.  When the method being called returns a cleanup method disposes of the session.   I would have attached a zip with the log and some code but I don't see any way to do that so I'll add it in the reply.  This is the spring configuration in blueprint.xml:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><bean id="jtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"></p><p>          <property name="transactionManager" ref="transactionManager"/></p><p>          <property name="userTransaction" ref="userTransaction"/></p><p></bean></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><bean id="htTxMgr" class="org.drools.container.spring.beans.persistence.HumanTaskSpringTransactionManager" scope="prototype"></p><p>          <argument ref="jtaTransactionManager" /></p><p></bean></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><bean id="systemEventListener" class="org.drools.SystemEventListenerFactory" factory-method="getSystemEventListener" /></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><bean id="taskService" class="org.jbpm.task.service.TaskService" scope="prototype"></p><p>          <property name="systemEventListener" ref="systemEventListener" /></p><p></bean></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><bean id="taskSessionFactory" class="org.jbpm.task.service.persistence.TaskSessionSpringFactoryImpl"</p><p>          init-method="initialize" depends-on="taskService" scope="prototype"></p><p>          <property name="transactionManager" ref="htTxMgr" /></p><p>          <property name="useJTA" value="true" /></p><p>          <property name="taskService" ref="taskService" /></p><p>          <jpa:unit unitname="org.jbpm.persistence.jpa" property="entityManagerFactory"/></p><p></bean></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p><bean id="provider.jbpm.api.interaction" class="com.test.jbpm.JbpmApiInteraction" </p><p>          init-method="setup" scope="prototype"></p><p>      <property name="transactionManager" ref="jtaTransactionManager" /></p><p>          <property name="taskSessionFactory" ref="taskSessionFactory" /></p><p>          <jpa:unit unitname="org.jbpm.persistence.jpa" property="entityManagerFactory"/></p><p></bean></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The setup method in the bean does the following:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Environment env = KnowledgeBaseFactory.newEnvironment();</p><p>env.set( EnvironmentName.ENTITY_MANAGER_FACTORY, this.entityManagerFactory );</p><p>env.set( EnvironmentName.GLOBALS, new MapGlobalResolver() );</p><p>AbstractPlatformTransactionManager aptm = (AbstractPlatformTransactionManager) transactionManager;</p><p>TransactionManager transactionManager = new DroolsSpringTransactionManager( aptm );</p><p>env.set( EnvironmentName.TRANSACTION_MANAGER, transactionManager );</p><p>PersistenceContextManager persistenceContextManager = new DroolsSpringJpaManager( env );</p><p>env.set( EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, persistenceContextManager );</p><p>Properties properties = new Properties();</p><p>properties.put( "drools.processInstanceManagerFactory", "org.jbpm.persistence.processinstance.JPAProcessInstanceManagerFactory" );</p><p>properties.put( "drools.processSignalManagerFactory", "org.jbpm.persistence.processinstance.JPASignalManagerFactory" );</p><p>KnowledgeSessionConfiguration config = KnowledgeBaseFactory.newKnowledgeSessionConfiguration( properties );</p><p>ksession = JPAKnowledgeService.newStatefulKnowledgeSession( this.kbase, config, env );</p><p>this.ksession.getWorkItemManager().registerWorkItemHandler( "Service Task", new ServiceTaskHandler() );</p><p>this.taskSession = taskSessionFactory.createTaskServiceSession();</p><p>taskService = this.taskSession.getService();</p><p>localTaskService = new LocalTaskService( taskService );</p><p>CustomSyncWsWorkItemHandler  humanTaskHandler = new CustomSyncWsWorkItemHandler( this.localTaskService, this.ksession );</p><p>humanTaskHandler.setLocal( true );</p><p>humanTaskHandler.connect();</p><p>this.ksession.getWorkItemManager().registerWorkItemHandler( "Human Task", humanTaskHandler );</p><p>this.ksession.addEventListener( new ProcessEventListenerImpl());</p><p>TasksAdmin admin = taskService.createTaskAdmin();</p><p>this.ksession.addEventListener( new TaskCleanUpProcessEventListener( admin ));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Note: the CustomSyncWsWorkItemHandler is related to issue JBPM-3578.  We need this because we also are supporting BRMS5.3.0.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The bean is created:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>jbpmApiInteraction = (JbpmApiInteraction)blueprintContainer.getComponentInstance( "provider.jbpm.api.interaction" );</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>The method to cancel the process instance is invoked on the bean:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>jbpmApiInteraction.cancelProcessInstance( instanceId ) calls this.ksession.abortProcessInstance( instanceId )</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>After the call returns the objects are disposed in the bean:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>this.taskSession.dispose();</p><p>this.localTaskService.dispose();</p><p>this.kession.dispose();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>I'll post the stack trace in another reply.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Regards,</p><p>Jim</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/783484#783484">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in jBPM at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>