05-03-2017 07:21 AM
i'm tryin to implement my own java logic using SPRING + JSF with activiti , this my BPMN file :
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"targetNamespace="http://www.bpmnwithactiviti.org"
xmlns:activiti="http://activiti.org/bpmn">
<process id="my-process" name="my-process">
<startEvent id="startEvent" name="Start" activiti:formKey="taskForm_newOrder.jsf" />
<sequenceFlow id="toValidateTask" sourceRef="startEvent" targetRef="validateTask"/><serviceTask id="validateTask" activiti:expression="#{operationController.sayHello()}" >
<extensionElements>
<activiti:field name="input" expression="${adminModele.operationLabel}" />
</extensionElements>
</serviceTask><sequenceFlow id="toCompletedOrderTask" sourceRef="validateTask" targetRef="completeOrderTask"/>
<userTask id="completeOrderTask" name="Complete order" activiti:assignee="${adminModele.operationLabel}" activiti:formKey="taskForm_completeOrder.jsf">
<documentation>Completing order for book with isbn : ${adminModele.operationLabel} </documentation>
</userTask>
<sequenceFlow id="toApproveTask" sourceRef="completeOrderTask" targetRef="approveTask"/>
<serviceTask id="approveTask" activiti:expression="#{bookOrder.validates()}" />
<sequenceFlow id="toEndEvent" sourceRef="approveTask" targetRef="endEvent"/>
<endEvent id="endEvent" name="End"/>
</process>
</definitions>
the sayHello() :
public void sayHello(){
System.out.println("SayHello ................."+bookOrder.getIsbn());
}
when i do a simple call to sayHello () it displays what i want but when the ServiceTask calls sayHello i get JavaNullPointerException , means my bookOrder object is null .
Any ideas how to deal with this problem
05-03-2017 04:07 PM
05-04-2017 10:05 AM
yes in my activiti.cfg.xml :
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
">
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/activiti_test" />
<property name="jdbcDriver" value="com.mysql.jdbc.Driver" />
<property name="jdbcUsername" value="root" />
<property name="jdbcPassword" value=" " />
<property name="databaseSchemaUpdate" value="DB_SCHEMA_UPDATE_TRUE" />
</bean>
<!-- beans i'm calling from the workflow -->
<bean id="bookOrder" class="ma.net.s2m.selectsystem.web.controller.admin.BookOrder" />
<bean id="operationController" class="ma.net.s2m.selectsystem.web.controller.admin.OperationController"/>
<bean id="adminModele" class="ma.net.s2m.selectsystem.web.modele.AdminModele"/>
</beans>
05-04-2017 10:49 AM
05-04-2017 11:20 AM
public void getProcessDiagram() {
ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();
RuntimeService runtimeService = processEngine.getRuntimeService();
RepositoryService repositoryService = processEngine.getRepositoryService();
TaskService taskService = processEngine.getTaskService();
FormService formService = processEngine.getFormService();
IdentityService service = processEngine.getIdentityService();
// Deploy the process definition
Deployment deployment = repositoryService.createDeployment()
.addClasspathResource("processesT.bpmn20.xml")
.deploy();
// Start a process instance
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("my-process");
// here i test the sayHello() ===> it displays the bookOrder.getIsbn() value
sayHello() ;
List<org.activiti.engine.task.Task> taskes = taskService.createTaskQuery().processInstanceId(processInstance.getId()).list();
System.out.println("List size: " + taskes.size());
for (org.activiti.engine.task.Task task : taskes) {
System.out.println("Task available: " + task.getName());
System.out.println("Task assignee :"+task.getAssignee());
}
org.activiti.engine.task.Task task = taskes.get(0);
Map<String , Object> taskVariables = new java.util.HashMap<String,Object>() ;
taskVariables.put("vacationApproved", "false");
taskVariables.put("managerMotivation", "We have a tight deadline!");
List<String>list = runtimeService.getActiveActivityIds(exec.getId());
for(String task1 : list){
System.out.println("****************************** Current Task : "+task1);
System.out.println("****************************** Description : "+taskes.get(0).getDescription());
System.out.println("Number of process instances: " + runtimeService.createProcessInstanceQuery().count());
}
taskService.complete(task.getId(), taskVariables);
----------------------------------------------------------------------------------------------- Error----------------------------------------
Caused by: org.activiti.engine.impl.javax.el.ELException: java.lang.NullPointerException
at org.activiti.engine.impl.javax.el.BeanELResolver.invoke(BeanELResolver.java:487)
at org.activiti.engine.impl.javax.el.CompositeELResolver.invoke(CompositeELResolver.java:397)
at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:102)
at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:86)
at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26)
at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114)
at org.activiti.engine.impl.delegate.ExpressionGetInvocation.invoke(ExpressionGetInvocation.java:33)
at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:48)
... 143 more
Caused by: java.lang.NullPointerException
at ma.net.s2m.selectsystem.web.controller.admin.OperationController.sayHello(OperationController.java:898)
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:597)
at org.activiti.engine.impl.javax.el.BeanELResolver.invoke(BeanELResolver.java:483)
... 153 more
05-04-2017 11:34 AM
Im having a really hard time understanding what you are actually doing.
The following excerpt from the stack:
Caused by: java.lang.NullPointerException
at ma.net.s2m.selectsystem.web.controller.admin.OperationController.sayHello(OperationController.java:898)
Suggests you have a REST Controller called OperationController and that the exception is being thrown not when your process calls a JavaDelegate (your service task).
If this is happening during a REST call, be aware that the servlet and process dont share the same context and it is possible any bean defined in the process engine is not available to the servlet (I have seen this a number of times).
The solution is to add a helper to retrieve the process engine context. The following link will give you the details:
java - Using some beans in Filter bean class? - Stack Overflow
Cheers,
Greg
05-04-2017 11:49 AM
I'm not using a RestController , but what i understand is that when Activiti process starts , Activiti creats it's own new context so my objects which were full in my context becomes null in activiti context since i can call sayHello () and i don't get an error but when sayHello() is called via activiti:expression="#{operationController.sayHello()}" it tells me that my object is null !!
05-04-2017 11:57 AM
Honestly, I dont understand what you are trying to do. In order to make any progress a unit test is in order.
Sorry,
Greg
05-04-2017 12:56 PM
what i'm tryin to do is binding my objects to workflow , for example activiti:expression="#{operationController.sayHello()" e this method returns NullPointerException , but my object is not Null because i already did bookOrder.setIsbn("123") before , i tried with a simple String test ="test" when i pass it to the sayHello() it doesn't return NPE the problem is everytime i pass value with Setter or try to get value with getter sayHello return NPE for that object.
hope i'm someHow clear .
regards
05-05-2017 03:49 AM
Hi Greg ,
is there a better way of declaring my beans so they can be detetcted from my BPMNfile ?
Explore our Alfresco products with the links below. Use labels to filter content by product module.