Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
Jsr94 and JBoss Rules using DSL Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Jsr94 and JBoss Rules using DSL

    I'm using the Spring Modules 0.8 release to integrate JBoss Rules via the JSR94 classes. Everything was surprisingly simple to get wired together and working, but now I am faced with an issue using DSL files. I was able to successfully load a drl file without any issues, but now I want to load both the drl and a dsl. Looking at some of the sample classes provided with the drools examples I need to pass both these files off to the PackageBuilder via an overloaded method, addPackageFromDrl.

    Code:
    builder.addPackageFromDrl( drl, dsl );
    How can I do this via the Spring module classes?

    Thanks for the help...

  • #2
    After stepping through the code a bit I learned that the Spring class
    LocalRuleExecutionSetProviderImpl is looking for the key dsl in the properties
    object that is passed in and that it expects the value object in the hash table
    to be either a java.io.Reader or a String object containing the contents of the
    dsl file. So I modified my configuration to pass in an instance of Reader for
    the dsl file.

    So I created a simple class, ReasourceAsReader, that is a FactoryBean that converts a Resource to a java.io.Reader. I then assigned this bean to the hashtable that is passed into the DefaultRuleSource as follows:

    Code:
      <bean id="ruleSource" class="org.springmodules.jsr94.rulesource.DefaultRuleSource">
        <property name="ruleRuntime">
          <ref local="ruleRuntime" />
        </property>
        <property name="ruleAdministrator">
          <ref local="ruleAdministrator" />
        </property>
        <property name="source">
          <value>classpath:com/sybase/it/cosmos/rules/order-release.drl</value>
        </property>
        <property name="bindUri">
          <value>autoRelease</value>
        </property>
        
        <property name="rulesetProperties">
          <map key-type="java.lang.String" value-type="java.lang.String">      
            <entry key="dsl"> 
              <bean class="com.sybase.it.cosmos.spring.ResourceReader">
                <property name="source">
    <value>classpath:/com/sybase/it/cosmos/rules/order-release.dsl</value>
                </property>
              </bean>
            </entry>
          </map>    
        </property>
      </bean
    The code for the FactoryBean is as follows:
    Code:
    import org.springframework.beans.factory.FactoryBean;
    import org.springframework.beans.factory.InitializingBean;
    import org.springframework.core.io.Resource;
    import org.springframework.core.io.support.EncodedResource;
    
    public class ResourceReader implements FactoryBean, InitializingBean {
      
      private Resource source = null;
      private java.io.Reader reader = null;
      
      public void setSource(Resource source) {
        this.source = source;
      }
      public void afterPropertiesSet() throws Exception {
        if(source == null) {
          throw new IllegalArgumentException("Resource cannot be null!");
        }
            
        EncodedResource er = new EncodedResource(source);
        reader = er.getReader();
      }
      public Object getObject() throws Exception {
        return reader;
      }
      public Class getObjectType() {
        return java.io.Reader.class;
      }
      public boolean isSingleton() {
        return true;
      }
    }
    Now the dsl file is loaded but I'm receiving the following exception:
    Code:
    Caused by: 
    org.drools.rule.InvalidRulePackage:
    org.drools.lang.ExpanderException
     <at> 993028org.drools.lang.ExpanderException
     <at> 128b33aorg.drools.lang.ExpanderException
     <at> 10ea988org.drools.lang.ExpanderException
     <at> 19c4844org.drools.lang.ExpanderException
     <at> 14c8f24org.drools.lang.ExpanderException
     <at> 1498526org.drools.lang.ExpanderException
     <at> 1c4a760org.drools.lang.ExpanderException
     <at> 1c8ce14org.drools.lang.ExpanderException
     <at> 51b326org.drools.lang.ExpanderException
     <at> 1c8997eorg.drools.lang.ExpanderException
     <at> d54d3forg.drools.lang.ExpanderException
     <at> 1c26386org.drools.lang.ExpanderException
     <at> 1140cf6org.drools.lang.ExpanderException
     <at> 15efa6aorg.drools.lang.ExpanderException
     <at> 8a750aorg.drools.lang.ExpanderException
     <at> 9e6e0org.drools.lang.ExpanderException <at> 14b389
    	at org.drools.rule.Package.checkValidity(Package.java:368)
    Any ideas as to what might be causing this?

    Thanks for the help...

    Comment


    • #3
      I came accross the same problem as you are having and after some debugging, it seems like a bug in Drools. The problem is that drools does not output the exceptions correctly when the error is an ExpanderException. It seems that this is because they forgot to implement toString() on that class.

      To work around this and see the errors, set a breakpoint on the toString() method of PackageBuilderErrors. Via debugging you should then be able to navigate through an array of DroolsError objects and call getMessage() on each one to see the error message.

      Comment


      • #4
        Nice solution

        Hi,

        We just got the same problem and your suggestion works!
        Thx cmathrusse.

        Comment


        • #5
          I don't even remember having this problem But I'm glad I could be of help

          Comment

          Working...
          X