cancel
Showing results for 
Search instead for 
Did you mean: 

Integrate Activiti with Drools

ridottiastozze
Champ in-the-making
Champ in-the-making
Hi,
I have to integrate Activiti with the Drools Engine for my thesis but I have some problems.
I have inserted in the Activiti Explorer the .bar file, that contains the .bpmn20.xml process and the .drl file.  Looking in one previus post   I notice that you gave some advices:

1. The drools-api, drools-compiler, drools-core and mvel2 jar files are missing from the activiti-rest application, so you have to add those manually.  (I have inserted the .jar in C:\activiti-5.8\apps\apache-tomcat-6.0.32\webapps\activiti-rest\WEB-INF\lib folder)
2. In the activiti-cfg.xml inside the activiti-cfg.jar in the activiti-rest application you have to include the following property:
<property name="customPostDeployers">
<list>
<bean class="org.activiti.engine.impl.rules.RulesDeployer" />
</list>
</property>
(it seems ok)


When I run the process in the Activiti Explorer tomcat gives me this exception:
Cause: org.activiti.engine.ActivitiException: couldn't find type for RuleInput

This is the code:
<process id="processSalary" name="processSalary">
    <startEvent id="startevent1" name="Start" activiti:initiator="employeeName>
    <extensionElements>       
     <activiti:formProperty id="salary" name="Insert the salary" type="long" required="true"/>
     <activiti:formProperty id="age" name="Insert the age" type="long" required="true"/>
     </extensionElements>
    </startEvent>
<serviceTask id="servicetask1" name="Service Task" activiti:class="org.activiti.demo.rules.CreateRuleObjectDelegate"></serviceTask>
    <sequenceFlow id="flow1" name="" sourceRef="startevent1" targetRef="servicetask1"></sequenceFlow>
    <businessRuleTask id="businessruletask1" name="Business rule task" activiti:rules="salarycheck" activiti:ruleVariablesInput="${ruleInput}" activiti:exclude="false" activiti:resultVariableName="ruleOutput"></businessRuleTask>

public class CreateRuleObjectDelegate implements JavaDelegate {

  public void execute(DelegateExecution execution) throws Exception {
     RuleInput ruleInput = new RuleInput();   
       ruleInput.setEmployee((String) execution.getVariable("employeeName"));
       Long salario, age;
       salario = (Long)execution.getVariable("salary");
       age = (Long)execution.getVariable("age");  
       ruleInput.setSalary(salario.intValue());
       ruleInput.setAge(age.intValue());
       System.out.println("Setting ruleInput " + ruleInput);
       execution.setVariable("ruleInput", ruleInput);
  }
}


rule "salarycheck"
when
    i : RuleInput( employee == "kermit" )
then
    System.out.println("testing");
    RuleOutput o = new RuleOutput();
    o.setResult("rule fired");
    insert(o);
end

I have attached the complete code.
I hope you are able to help me. Best regards,
14 REPLIES 14

trademak
Star Contributor
Star Contributor
Hi,

That's right. The Activiti Explorer has its own process engine and doesn't use the Activiti REST module.
So the JARs you added to the Activiti REST web app classpath should be in the Activiti Explorer web app classpath.

Best regards,

ridottiastozze
Champ in-the-making
Champ in-the-making
I have inserterted the activiti-cfg.jar , drools-api-5.1.1.jar, drools-compiler-5.3.0.Final.jar, drools-core-5.3.0.Final.jar and mvel2-2.1.0.drools4.jar , in C:\activiti-5.8\apps\apache-tomcat-6.0.32\webapps\activiti-explorer\WEB-INF\lib but Activiti Explorer gives me the same exception:

com.vaadin.event.ListenerMethod$MethodException
Cause: com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: couldn't find type for RuleInput [salary=1000, age=15, employee=kermit] (I get this values from the form)

I have tested the rule and it is ok. You have tested the code I have attached or it seems to be correct? I am not able to understand if it is a code problem or a configuration problem.
Thank you. matteo

trademak
Star Contributor
Star Contributor
Hi,

Did you also create a JAR containing the RuleInput class?
The RuleInput class should also be added to the Activiti Explorer classpath.

Best regards,

ridottiastozze
Champ in-the-making
Champ in-the-making
The .jar  is correct. In fact if I use only a serviceTask to recuper data form I have any problems.

RuleInput ruleInput = new RuleInput();   
     ruleInput.setEmployee((String) execution.getVariable("employeeName"));
     Long salario, age;
     salario = (Long)execution.getVariable("salary");
     age = (Long)execution.getVariable("age");  
     ruleInput.setSalary(salario.intValue());
     ruleInput.setAge(age.intValue());
    System.out.println("Setting ruleInput " + ruleInput);

The problem is the link with the rule.
If I try to change the code inserting only an Object instead of a ruleInput object:

Object ruleInput = new Object();  
execution.setVariable("ruleInput", ruleInput);

and to delete the condition of the rule:
rule "salarycheck"
when
then
    System.out.println("testing");
    RuleOutput o = new RuleOutput();
    o.setResult("rule fired");
    insert(o);
end

<serviceTask id="servicetask1" name="Service Task" activiti:class="org.activiti.demo.rules.CreateRuleObjectDelegate"></serviceTask>
    <businessRuleTask id="businessruletask1" name="Business rule task" activiti:rules="salarycheck"

I have a similar exception:

com.vaadin.event.ListenerMethod$MethodException
Cause: org.activiti.engine.ActivitiException: couldn't find type for java.lang.Object@598a5d

Probably it is a configuration problem.
Best regards,

trademak
Star Contributor
Star Contributor
Hi,

The problem is the rulesProcess.jar file. The folder structure is wrong.
Did you create this JAR with the Activiti Designer on Windows? There's a bug that prevents the JAR from being created correctly.

Best regards,

ridottiastozze
Champ in-the-making
Champ in-the-making
Hi,
I have inserted in the directories …\apache-tomcat-6.0.32\lib and …\activiti-explorer\WEB-INF\lib the .jar that I have created using the Export function of Eclipse. I don't use the .jar that eclipse creates with the createdeploymentartifact function. I attach the image of the structure of the .jar.
There is an other way to create the .jar?

best regards,

ridottiastozze
Champ in-the-making
Champ in-the-making
I have tryed to call a java dependencies (serviceTask) and to print the data form and it works. When I add to the process a businessRulTask tomcat gives me now this exception:

<businessRuleTask id="businessruletask1" name="Business rule task" activiti:rules="salarycheck" activiti:ruleVariablesInput="${ruleInput}" activiti:exclude="false" activiti:resultVariableName="ruleOutput"></businessRuleTask>

Excaption:
com.vaadin.event.ListenerMethod$MethodException
Cause: com.vaadin.event.ListenerMethod$MethodException
Cause: java.lang.NoSuchMethodError: org.drools.util.CompositeClassLoader.clone()Lorg/drools/util/CompositeClassLoader;
at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:164)
at com.vaadin.ui.AbstractComponent.fireEvent(AbstractComponent.java:1193)
at com.vaadin.ui.Button.fireClick(Button.java:539)

I'm doing many attempts, but I am not able to solve this problem. Help
Best regards,

ridottiastozze
Champ in-the-making
Champ in-the-making
Do you have any suggestion? I need to solve this problem for my thesis.  Thank you.
best regards,

trademak
Star Contributor
Star Contributor
Hi,

I've deployed the SalaryProject example that you included in your first post and it works fine with me.
So it must be the steps you performed to get it installed on the Activiti Engine.
In the Activiti in Action book I've written a whole chapter about the Drools and Activiti integration, maybe it's a good idea to work with that chapter to get it working.

Best regards,