0 Replies Latest reply on Feb 27, 2014 12:56 PM by Jose Miguel Loor

    Cannot create a StatefulKnowledgeSession in a web application

    Jose Miguel Loor Apprentice

      Hi

       

      I am trying to create an application that uses a stateless knowledge session for executing rules. The environment in like this:

      - a jboss eap 6.2 server

      - a jboss-bpms-6.0.0.GA-redhat-2-deployable-eap6.x.zip distribution that is deployed in the eap server

       

      Now, i have created a project in the bpms server, using the Project Authoring tool. I have a data model, some rules and i have defined the kmodule.xml like this:

       

      <kmodule xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

               xmlns="http://jboss.org/kie/6.0.0/kmodule">

        <kbase name="apertura" default="true" eventProcessingMode="stream" equalsBehavior="equality" declarativeAgenda="disabled" scope="javax.enterprise.context.ApplicationScoped">

          <ksession name="aperturaStatefulKnowledgeSession" type="stateful" default="true" clockType="realtime" beliefSystem="simple" scope="javax.enterprise.context.ApplicationScoped"/>

          <ksession name="aperturaStatelessKnowledgeSession" type="stateless" default="true" clockType="realtime" beliefSystem="simple" scope="javax.enterprise.context.ApplicationScoped"/>

        </kbase>

      </kmodule>

       

      The build of the kjar works fine (in the bpms console), and i can see the deployment in the Deployment Units list. After that, i am trying to use that kjar in my application. The application includes the jar in the WEB-INF/lib folder. The application is being deployed in the same jboss eap 6.2 server that is running the bpms deployable

       

      Then i am trying to apply the rules this way:

       

      KieServices kServices = KieServices.Factory.get();

      KieContainer kContainer = kServices.getKieClasspathContainer()

      KieSession kSession = kContainer.newKieSession();

       

      But then i am getting this error:

       

      java.lang.RuntimeException: Cannot find a default StatelessKieSession

       

      If i run the same snippet in a JUnit test, everything works fine.

       

      if i try to do this

      kContainer.getKieBase()

      then i get the exception

      java.lang.RuntimeException: Cannot find a default KieBase

       

      My guess is that the kieContainer is not picking the classpath right, because i am creating a default kbase as you can see in the kmodule.xml. Even if i try to get the kieBase by name, is does not work.

       

      But why is it working in a junit test ?? How can i accomplish this ?

       

      thanks