2 Replies Latest reply on May 1, 2009 5:58 AM by cedricrathgeb

    [CBR Error] Duplicate declaration for variable 'msg' when us

      Hi all,

      I've got an error when writing a Rule using XPath for the ContentBasedRouter.

      The problem arise only with the "and" operator (there is no problem with the "or" operator).

      Here is the content of the DRL file :

      package com.jboss.soa.esb.routing.cbr
      
      #list any import classes here.
      import org.jboss.soa.esb.message.Message;
      import org.jboss.soa.esb.message.format.MessageType;
      
      expander XPathLanguage.dsl
      
      #declare any global variables here
      global java.util.List destinations;
      
      rule "CARE"
       when
       (xpathEquals "/Paiement/Membre/CodeApplication", "90") and (xpathEquals "/Paiement/Entete/TypeTransaction", "002")
       then
       Log : "Going CARE";
       Destination : "CARE";
      end
      
      rule "SAPFSCDCIRVIE"
       when
       xpathEquals "/Paiement/Membre/CodeApplication", "32"
       then
       Log : "Going SAPFSCDCIRVIE";
       Destination : "SAPFSCDCIRVIE";
      end


      And the ContentBasedRouter action in JBossESB :
      <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="content-based-router">
       <property name="ruleSet" value="drools-routing-rules-using-xpath-and.drl"/>
       <property name="ruleLanguage" value="XPathLanguage.dsl"/>
       <property name="ruleReload" value="true"/>
       <property name="destinations">
       <route-to destination-name="SAPFSCDCIRVIE" service-category="ESB_PF" service-name="Service_PF_SAPFSCDCIRVIE"/>
       <route-to destination-name="CARE" service-category="ESB_PF" service-name="Service_PF_CARE"/>
       </property>
       </action>


      Does anyone have an idea on how to create more complex Rules using XPath ?

      Should I switch to Rules working on Java Objects ?

      I tried the "LISP" syntax with the prefixed operator and I have the same behavior...

      Here is the stack trace :
      org.jboss.soa.esb.actions.ActionProcessingException: org.jboss.soa.esb.services.routing.MessageRouterException: Duplicate declaration for variable 'msg' in the rule 'CARE' : [Rule name='CARE']

      at org.jboss.soa.esb.actions.ContentBasedWiretap.process(ContentBasedWiretap.java:156)
      at org.jboss.soa.esb.actions.ContentBasedRouter.process(ContentBasedRouter.java:58)
      at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:633)
      at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:585)
      at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:419)
      at org.jboss.soa.esb.listeners.message.MessageAwareListener$TransactionalRunner.run(MessageAwareListener.java:548)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
      at java.lang.Thread.run(Thread.java:619)
      Caused by: org.jboss.soa.esb.services.routing.MessageRouterException: Duplicate declaration for variable 'msg' in the rule 'CARE' : [Rule name='CARE']

      at org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter.route(JBossRulesRouter.java:128)
      at org.jboss.soa.esb.actions.ContentBasedWiretap.executeRules(ContentBasedWiretap.java:168)
      at org.jboss.soa.esb.actions.ContentBasedWiretap.process(ContentBasedWiretap.java:140)
      ... 8 more
      Caused by: org.jboss.internal.soa.esb.services.rules.RuleServiceException: Duplicate declaration for variable 'msg' in the rule 'CARE' : [Rule name='CARE']

      at org.jboss.internal.soa.esb.services.rules.DroolsRuleBaseHelper.getNewRuleBaseWithPackage(DroolsRuleBaseHelper.java:272)
      at org.jboss.internal.soa.esb.services.rules.DroolsRuleBaseHelper.createRuleBaseFromRuleFiles(DroolsRuleBaseHelper.java:134)
      at org.jboss.internal.soa.esb.services.rules.DroolsRuleService.getRuleBaseForFileBasedRules(DroolsRuleService.java:387)
      at org.jboss.internal.soa.esb.services.rules.DroolsRuleService.executeStatelessRules(DroolsRuleService.java:116)
      at org.jboss.internal.soa.esb.services.rules.RuleServiceCallHelper.executeRulesService(RuleServiceCallHelper.java:137)
      at org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter.route(JBossRulesRouter.java:123)
      ... 10 more
      Caused by: org.drools.rule.InvalidRulePackage: Duplicate declaration for variable 'msg' in the rule 'CARE' : [Rule name='CARE']

      at org.drools.rule.Package.checkValidity(Package.java:483)
      at org.drools.common.AbstractRuleBase.addPackage(AbstractRuleBase.java:418)
      at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:385)
      at org.jboss.internal.soa.esb.services.rules.DroolsRuleBaseHelper.getNewRuleBaseWithPackage(DroolsRuleBaseHelper.java:267)
      ... 15 more


        • 1. Re: [CBR Error] Duplicate declaration for variable 'msg' whe
          beve

          Hi,

          Does anyone have an idea on how to create more complex Rules using XPath ?

          For this to work I think you'll need to create you own dsl and specify it using:
          <property name="ruleLanguage" value="YourXPathLanguage.dsl"/>

          Here is the default XPathLanguage.dsl (just to save you having to search for it):
          #JBossESB Content Based Routing using XPath DSL
          [when]xpathMatch "{xpath}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentMatches(msg, "{xpath}") )
          [when]xpathEquals "{xpath}", "{value}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentEquals(msg, "{xpath}", "{value}") )
          [when]xpathGreaterThan "{xpath}", "{value}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentGreaterThan(msg, "{xpath}", "{value}") )
          [when]xpathLessThan "{xpath}", "{value}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentLessThan(msg, "{xpath}", "{value}") )
          [then]Log : "{message}"=System.out.println("{message}");
          [then]Destination : "{message}"=destinations.add("{message}");
          
          # Namespace(NS) aware methods
          [when]xpathMatch expr "{xpath}" use namespaces "{namespaces}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentMatches(msg, "{xpath}",org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.parseNamespaces("{namespaces}")) )
          [when]xpathEquals expr "{xpath}", "{value}" use namespaces "{namespaces}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentEquals(msg, "{xpath}", "{value}",org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.parseNamespaces("{namespaces}")))
          [when]xpathGreaterThan expr "{xpath}", "{value}" use namespaces "{namespaces}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentGreaterThan(msg, "{xpath}", "{value}",org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.parseNamespaces("{namespaces}") ) )
          [when]xpathLessThan expr "{xpath}", "{value}" use namespaces "{namespaces}"=msg : org.jboss.soa.esb.message.Message( type == org.jboss.soa.esb.message.format.MessageType.JBOSS_XML ) and eval( org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.xmlContentLessThan(msg, "{xpath}", "{value}", org.jboss.internal.soa.esb.services.routing.cbr.DslHelper.parseNamespaces("{namespaces}") ))

          I think the problem you are seeing is that having two statements on the same line(when using 'and) causes the msg variable to be declared twice.
          I'm not sure exactly of how to achive this but I'm sure that the Drools guys can help you out if you get stuck.
          Would be great if you'd like to share your solution here or if you'd like to contribute it back to the project even better :)

          Regards,

          /Daniel

          • 2. Re: [CBR Error] Duplicate declaration for variable 'msg' whe

            May be easier to say than to do ;)

            At this time I don't have a lot time to look after that issue. But I think you're are right when you say I should write my own DSL for building more complex Rules with XPath.