3 Replies Latest reply on Dec 8, 2006 11:22 AM by sjmenden

    Problem injecting drools WorkingMemory

    sjmenden

      I am following the documentation for injecting the WorkingMemory into an EJB. I know my problem is configuration, but there are no working examples specific to the documentation, so I'm having trouble:

      SEVERE: Error Rendering View[/purchase.xhtml]
      org.jboss.seam.RequiredException: In attribute requires value for component: purchaseHome.purchasingRulesMemory
       at org.jboss.seam.Component.getInstanceToInject(Component.java:1844)
       at org.jboss.seam.Component.injectFields(Component.java:1317)
       at org.jboss.seam.Component.inject(Component.java:1087)
       at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:48)
       ...
      



      components.xml
      <components xmlns:drools="http://jboss.com/products/drools">
      
       ...
      
       <drools:rule-base name="purchasingRules">
       <drools:rule-files>
       <value>purchasingRules.drl</value>
       </drools:rule-files>
       </drools:rule-base>
      
       <drools:managed-working-memory name="purchasingRulesMemory" auto-create="true" rule-base="#{purchasingRules}"/>
      
       ...
      
      </components>
      



      purchasingRules.drl, located in the resources dir, but I'm copying it over to WEB-INF/classes because the docs say that the rule is looked for on the classpath
      package test.purchasing
      
      rule "Step 1"
      
       when
       s : PurchaseStatus( status == "New Request")
       then
       System.out.println("Rule Triggered!!!!!!!!!");
       System.out.println(s);
       s.setStatus("Waiting for purchase Approval.");
       s.setNextStep("Step 1");
      
      end
      



      PurchaseHome.java
      ...
      
      @Name("purchaseHome")
      @LoggedIn
      public class PurchaseHome extends EntityHome<Purchase> {
      
       @In WorkingMemory purchasingRulesMemory;
      
       ...
      }
      




        • 1. Re: Problem injecting drools WorkingMemory
          sjmenden

          I made some progress but now getting massive exceptions. I changed the components.xml to look like the drools example one:

          components.xml

          ...
          <component name="ruleBase" class="org.jboss.seam.drools.RuleBase">
           <property name="ruleFiles">purchasingRules.drl</property>
           </component>
          
           <component name="purchasingRulesMemory" class="org.jboss.seam.drools.ManagedWorkingMemory">
           <property name="ruleBase">#{ruleBase}</property>
           </component>
          ...
          



          But now I'm getting a ClassCastException, and I have verified my jars exactly(crosses fingers) mirror the ones in the example. I'm running SEAM CR2 with JBoss 4.0.5

          17:16:25,918 ERROR [STDERR] StringTemplate: problem parsing group <unknown>: java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token
          17:16:25,919 ERROR [STDERR] java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token
          17:16:25,919 ERROR [STDERR] at antlr.CharScanner.makeToken(CharScanner.java:173)
          17:16:25,920 ERROR [STDERR] at org.antlr.stringtemplate.language.GroupLexer.mID(GroupLexer.java:333)
          17:16:25,920 ERROR [STDERR] at org.antlr.stringtemplate.language.GroupLexer.nextToken(GroupLexer.java:103)
          17:16:25,920 ERROR [STDERR] at antlr.TokenBuffer.fill(TokenBuffer.java:69)
          17:16:25,920 ERROR [STDERR] at antlr.TokenBuffer.LA(TokenBuffer.java:80)
          17:16:25,920 ERROR [STDERR] at antlr.LLkParser.LA(LLkParser.java:52)
          17:16:25,920 ERROR [STDERR] at antlr.Parser.match(Parser.java:210)
          17:16:25,921 ERROR [STDERR] at org.antlr.stringtemplate.language.GroupParser.group(GroupParser.java:117)
          17:16:25,921 ERROR [STDERR] at org.antlr.stringtemplate.StringTemplateGroup.parseGroup(StringTemplateGroup.java:754)
          17:16:25,921 ERROR [STDERR] at org.antlr.stringtemplate.StringTemplateGroup.<init>(StringTemplateGroup.java:264)
          17:16:25,921 ERROR [STDERR] at org.antlr.stringtemplate.StringTemplateGroup.<init>(StringTemplateGroup.java:244)
          17:16:25,921 ERROR [STDERR] at org.drools.semantics.java.RuleBuilder.<clinit>(Unknown Source)
          17:16:25,921 ERROR [STDERR] at org.drools.compiler.PackageBuilder.addRule(Unknown Source)
          17:16:25,922 ERROR [STDERR] at org.drools.compiler.PackageBuilder.addPackage(Unknown Source)
          17:16:25,922 ERROR [STDERR] at org.jboss.seam.drools.RuleBase.compileRuleBase(RuleBase.java:52)
          17:16:25,922 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          17:16:25,922 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          17:16:25,922 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          17:16:25,922 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
          17:16:25,923 ERROR [STDERR] at org.jboss.seam.util.Reflections.invoke(Reflections.java:18)
          ...
          


          • 2. Re: Problem injecting drools WorkingMemory
            gavin.king

            There is an example application in the examples/drools directory.

            • 3. Re: Problem injecting drools WorkingMemory
              sjmenden

              I am following the example as closely as I possibly can. I can not track seam to track down this problem.

              Here is the directory structure of the drools example deployed and my application deployed:

              JBoss- seam

              EAR contents:

              drwxr-xr-x 3 root root 4096 Dec 8 11:00 drools
              drwxr-xr-x 4 root root 4096 Dec 8 11:00 jboss-seam-drools-exp.war
              -rw-r--r-- 1 root root 3005 Dec 8 11:00 jboss-seam-drools.jar
              -rw-r--r-- 1 root root 627241 Dec 8 11:00 jboss-seam.jar
              drwxr-xr-x 2 root root 4096 Dec 8 11:00 lib
              drwxr-xr-x 2 root root 4096 Dec 8 11:00 META-INF
              -rw-r--r-- 1 root root 923 Dec 8 11:00 numberguess.drl
              -rw-r--r-- 1 root root 1026 Dec 8 11:00 pageflow.jpdl.xml
              


              drools/lib:
              -rw-r--r-- 1 root root 443432 Dec 8 11:00 antlr-2.7.6.jar
              -rw-r--r-- 1 root root 546498 Dec 8 11:00 antlr-3.0ea8.jar
              -rw-r--r-- 1 root root 36846 Dec 8 11:00 commons-jci-core-1.0-406301.jar
              -rw-r--r-- 1 root root 10802 Dec 8 11:00 commons-jci-janino-2.4.3.jar
              -rw-r--r-- 1 root root 207723 Dec 8 11:00 commons-lang-2.1.jar
              -rw-r--r-- 1 root root 26202 Dec 8 11:00 commons-logging-api-1.0.4.jar
              -rw-r--r-- 1 root root 635207 Dec 8 11:00 drools-compiler-3.0.5.jar
              -rw-r--r-- 1 root root 550976 Dec 8 11:00 drools-core-3.0.5.jar
              -rw-r--r-- 1 root root 383546 Dec 8 11:00 janino-2.4.3.jar
              -rw-r--r-- 1 root root 358843 Dec 8 11:00 stringtemplate-2.3b6.jar
              


              lib:
              jbpm-3.1.2.jar
              




              My Purchasing App

              EAR contents:
              drwxr-xr-x 3 root root 4096 Dec 8 11:11 drools
              drwxr-xr-x 4 root root 4096 Dec 8 11:11 purchasing.jar
              drwxr-xr-x 4 root root 4096 Dec 8 11:11 purchasing.war
              -rw-r--r-- 1 root root 619971 Dec 8 11:11 jboss-seam.jar
              -rw-r--r-- 1 root root 600277 Dec 8 11:11 jbpm-3.1.2.jar
              drwxr-xr-x 2 root root 4096 Dec 8 11:11 META-INF
              -rw-r--r-- 1 root root 359 Dec 8 11:11 purchasingRules.drl
              


              drools/lib:
              -rw-r--r-- 1 root root 443432 Dec 8 11:11 antlr-2.7.6.jar
              -rw-r--r-- 1 root root 546498 Dec 8 11:11 antlr-3.0ea8.jar
              -rw-r--r-- 1 root root 36846 Dec 8 11:11 commons-jci-core-1.0-406301.jar
              -rw-r--r-- 1 root root 10802 Dec 8 11:11 commons-jci-janino-2.4.3.jar
              -rw-r--r-- 1 root root 26202 Dec 8 11:11 commons-logging-api-1.0.4.jar
              -rw-r--r-- 1 root root 635207 Dec 8 11:11 drools-compiler-3.0.5.jar
              -rw-r--r-- 1 root root 550976 Dec 8 11:11 drools-core-3.0.5.jar
              -rw-r--r-- 1 root root 383546 Dec 8 11:11 janino-2.4.3.jar
              -rw-r--r-- 1 root root 358843 Dec 8 11:11 stringtemplate-2.3b6.jar
              


              purchasing.war/WEB-INF/lib:
              -rw-r--r-- 1 root root 24432 Dec 8 11:11 el-api.jar
              -rw-r--r-- 1 root root 97471 Dec 8 11:11 el-ri.jar
              -rw-r--r-- 1 root root 5096 Dec 8 11:11 jboss-seam-debug.jar
              -rw-r--r-- 1 root root 70709 Dec 8 11:11 jboss-seam-ui.jar
              -rw-r--r-- 1 root root 291366 Dec 8 11:11 jsf-facelets.jar
              




              There are a few difference in location, like I have some libs in WEB-INF/lib whereas drools has it in <EAR dir>/lib

              I don't think this matters though because I have the correct paths in my application.xml. My application deploys fine, but the first time I try to access a page which accesses drools I get:

              17:16:25,918 ERROR [STDERR] StringTemplate: problem parsing group <unknown>: java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.Token
              17:16:25,919 ERROR [STDERR] java.lang.ClassCastException: antlr.CommonToken cannot be cast to antlr.
              



              Do you guys have any pointers whatsoever as to the means that I can debug this problem. I will, as a last resort, take the drools example and copy all of my files to it and see if that works, but right now I am running a seam-gen project that has a little different dir structure.