7 Replies Latest reply on Nov 26, 2010 9:29 AM by Tim Marks

    CBR/Drools configuration problem

    Tim Marks Newbie

      I am trying to set up my first ContextBaseRouting action using Drools.

      I have tried many things, but keep getting exceptions as if pattern was not matched.

      Feedback appreciated.

       

      Here is the exception.

       

      2010-11-24 02:27:00,255 DEBUG [org.jboss.soa.esb.listeners.message.ActionProcessingPipeline] Unexpected exception caught while processing the action pipeline
      org.jboss.soa.esb.actions.ActionProcessingException: org.jboss.soa.esb.services.routing.MessageRouterException: Generation raised the following errors: [7,0]: [ERR 103] Line 7:0 rule 'rule_key' failed predicate: {(validateIdentifierKey(DroolsSoftKeywords.RULE))}? in rule[7,9]: [ERR 101] Line 7:9 no viable alternative at input 'XPathLanguage' in rule expander[10,0]: [ERR 101] Line 10:0 no viable alternative at input 'global' in rule expander in rule dsl[14,2]: [ERR 101] Line 14:2 no viable alternative at input 'xpathEquals' in rule expander in rule dsl in rule "hl7-inbound allergy rule using XPATH"
              at org.jboss.soa.esb.actions.ContentBasedWiretap.process(ContentBasedWiretap.java:160)
              at org.jboss.soa.esb.actions.ContentBasedRouter.process(ContentBasedRouter.java:58)
              at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:634)
              at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:588)
              at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:419)        at org.jboss.soa.esb.listeners.message.MessageAwareListener$TransactionalRunner.run(MessageAwareListener.java:540)
              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: Generation raised the following errors: [7,0]: [ERR 103] Line 7:0 rule 'rule_key' failed predicate: {(validateIdentifierKey(DroolsSoftKeywords.RULE))}? in rule[7,9]: [ERR 101] Line 7:9 no viable alternative at input 'XPathLanguage' in rule expander[10,0]: [ERR 101] Line 10:0 no viable alternative at input 'global' in rule expander in rule dsl[14,2]: [ERR 101] Line 14:2 no viable alternative at input 'xpathEquals' in rule expander in rule dsl in rule "hl7-inbound allergy rule using XPATH"
              at org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter.route(JBossRulesRouter.java:141)
              at org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter.route(JBossRulesRouter.java:120)
              at org.jboss.soa.esb.actions.ContentBasedWiretap.executeRules(ContentBasedWiretap.java:172)
              at org.jboss.soa.esb.actions.ContentBasedWiretap.process(ContentBasedWiretap.java:144)
              ... 8 more
      Caused by: org.jboss.internal.soa.esb.services.rules.RuleServiceException: Generation raised the following errors: [7,0]: [ERR 103] Line 7:0 rule 'rule_key' failed predicate: {(validateIdentifierKey(DroolsSoftKeywords.RULE))}? in rule[7,9]: [ERR 101] Line 7:9 no viable alternative at input 'XPathLanguage' in rule expander[10,0]: [ERR 101] Line 10:0 no viable alternative at input 'global' in rule expander in rule dsl[14,2]: [ERR 101] Line 14:2 no viable alternative at input 'xpathEquals' in rule expander in rule dsl in rule "hl7-inbound allergy rule using XPATH"
              at org.jboss.internal.soa.esb.services.rules.DroolsRuleBaseHelper.getNewRuleBaseWithPackage(DroolsRuleBaseHelper.java:255)
              at org.jboss.internal.soa.esb.services.rules.DroolsRuleBaseHelper.createRuleBaseFromRuleFiles(DroolsRuleBaseHelper.java:135)
              at org.jboss.internal.soa.esb.services.rules.DroolsRuleService.getRuleBaseStateForFileBasedRules(DroolsRuleService.java:544)
              at org.jboss.internal.soa.esb.services.rules.DroolsRuleService.executeStatelessRules(DroolsRuleService.java:139)
              at org.jboss.internal.soa.esb.services.rules.RuleServiceCallHelper.executeStateless(RuleServiceCallHelper.java:168)
              at org.jboss.internal.soa.esb.services.rules.RuleServiceCallHelper.executeRulesService(RuleServiceCallHelper.java:160)
              at org.jboss.internal.soa.esb.services.routing.cbr.JBossRulesRouter.route(JBossRulesRouter.java:135)
              ... 11 more

       

       

       

      Here is my action from jboss-esb.xml

      <action name="ContentBasedRouter"  class="org.jboss.soa.esb.actions.ContentBasedRouter">

                     <property name="cbrAlias" value="Drools"/>

                     <property name="ruleSet" value="rules-xpath.drl"/>

                     <property name="ruleLanguage" value="XPathLanguage.dsl"/>"/>

                     <property name="ruleReload" value="true"/>

                     <property name="destinations">

                        <route-to destination-name="allergy" service-category="mycategory" service-name="mycategoryservice" />

                     </property>

                  </action>

       

       

      Here is my rules-xpath.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 "hl7-inbound allergy rule using XPATH"

              when

                      xpathEquals "ADT_A60/MSH/MSH.9/MSG.3", "ADT A60"

              then

                      Log : "Allergy";

                              Destination : "allergy";

      end

       

       

      The message body contains XML that looks like this...

      <ADT_A60>
          <MSH>
              <MSH.1>|</MSH.1>
              <MSH.2>^~\&amp;</MSH.2>
              <MSH.3>
                  <HD.1>TestSendingSystem</HD.1>
              </MSH.3>
              <MSH.7>
                  <TS.1>200701011539</TS.1>
              </MSH.7>
              <MSH.9>
                  <MSG.1>ADT</MSG.1>
                  <MSG.2>A60</MSG.2>
                  <MSG.3>ADT A60</MSG.3>
              </MSH.9>
              <MSH.12>2.5.1</MSH.12>
              <MSH.13>123</MSH.13>
          </MSH>
          <PID>
              <PID.3>
                  <CX.1>123456</CX.1>
              </PID.3>
              <PID.5>
                  <XPN.1>
                      <FN.1>Doe</FN.1>
                  </XPN.1>
                  <XPN.2>John</XPN.2>
              </PID.5>
          </PID>
      </ADT_A60>

        • 1. Re: CBR/Drools configuration problem
          Tim Marks Newbie

          (Forgot to mention server runs jboss-eap-4.3 and esb 4.8)

          I tried a different approach - using namespaces. Now I am seeing a different exception. Please help!

           

          The new Exception is ...

          2010-11-24 16:00:40,829 DEBUG [org.jboss.soa.esb.listeners.message.ActionProcessingPipeline] Unexpected exception caught while processing the action pipeline
          org.jboss.soa.esb.actions.ActionProcessingException: No rule destination(s) [allergy] were matched, . Please fix your configuration and/or routing rules.
                  at org.jboss.soa.esb.actions.ContentBasedWiretap.process(ContentBasedWiretap.java:152)
                  at org.jboss.soa.esb.actions.ContentBasedRouter.process(ContentBasedRouter.java:58)
                  at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:634)
                  at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.processPipeline(ActionProcessingPipeline.java:588)
                  at org.jboss.soa.esb.listeners.message.ActionProcessingPipeline.process(ActionProcessingPipeline.java:419)
                  at org.jboss.soa.esb.listeners.message.MessageAwareListener$TransactionalRunner.run(MessageAwareListener.java:540)
                  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)

           

          The new action is

          <action name="ContentBasedRouter"  class="org.jboss.soa.esb.actions.ContentBasedRouter">
                         <property name="cbrAlias" value="Drools"/>
                         <property name="ruleSet" value="rules-xpath.drl"/>
                         <property name="ruleLanguage" value="XPathLanguage.dsl"/>"/>
                         <property name="ruleReload" value="true"/>
                         <property name="destinations">
                            <route-to destination-name="allergy" service-category="mycategory" service-name="mycategoryservice" />
                         </property>
                      </action>

           

          The new rules file is

          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 "hl7-inbound allergy rule using XPATH"
                  when
                          xpathEquals expr "urn:ADT_A60/MSH/MSH.9/MSG.3", "ADT A60" use namespaces "urn=urn:hl7-org:v2xml"
                  then
                          Log : "Allergy";
                                  Destination : "allergy";
          end

           

           

          The data contained in the message body

          <ADT_A60 xmlns="urn:hl7-org:v2xml">
              <MSH>
                  <MSH.1>|</MSH.1>
                  <MSH.2>^~\&amp;</MSH.2>
                  <MSH.3>
                      <HD.1>TestSendingSystem</HD.1>
                  </MSH.3>
                  <MSH.7>
                      <TS.1>200701011539</TS.1>
                  </MSH.7>
                  <MSH.9>
                      <MSG.1>ADT</MSG.1>
                      <MSG.2>A60</MSG.2>
                      <MSG.3>ADT A60</MSG.3>
                  </MSH.9>
                  <MSH.12>2.5.1</MSH.12>
                  <MSH.13>123</MSH.13>
              </MSH>
              <PID>
                  <PID.3>
                      <CX.1>123456</CX.1>
                  </PID.3>
                  <PID.5>
                      <XPN.1>
                          <FN.1>Doe</FN.1>
                      </XPN.1>
                      <XPN.2>John</XPN.2>
                  </PID.5>
              </PID>
          </ADT_A60>

          • 2. Re: CBR/Drools configuration problem
            Tom Fennelly Master

            Try using pure XPath or SXC rule sets.  They're easier to use and should be a lot faster (especially SXC).  See the programmers guide.

            • 3. Re: CBR/Drools configuration problem
              Tim Marks Newbie

              Tom - I searched the ESB 4.8 Programmers Guide and did not find a reference to SXC rules.

              We you referring to a different document?

               

              FYI - I tested my XPath using a validator tool (http://www.xmlme.com/XpathTool.aspx?mid=82) and it appears to be correct.

              I was hoping my problem was caused by a simple drools syntax error.

              • 4. Re: CBR/Drools configuration problem
                Tim Marks Newbie

                As suggested, I changed from using CBR-Drools to CBR-XPath.

                If the XML data contains a namespace, it does not work.

                Once namespace removed from XML data, CBR-XPath works.

                 

                Found posts with people having similar namespace issues (i.e. http://community.jboss.org/message/505555#505555)

                Have yet to find a solution to this problem.

                • 5. Re: CBR/Drools configuration problem
                  Anonymous User Newbie

                  Hi Tim,

                   

                  using namespaces in my rules looks like this and it works.

                   

                   

                  Example
                  rule "IATAAviationXML DocType Airport A"       
                      salience 100
                      activation-group "TESTTEST"
                      when
                           xpathMatch expr  "//a:Invoice//a:InvoiceHeader//a:SellerOrganization[count(//a:Invoice)=1][count(//a:Invoice//a:LineItemDetail//a:RouteDetails//a:CountryCode_ICAO)=0][count(//a:Invoice//a:LineItemDetail//a:RouteDetails//a:CountryCode)=0]"  use namespaces "a=http://www.IATA.com/IATAAviationInvoiceStandard"
                      then
                          Destination : "DummyService";   
                  end

                   

                   

                  In your example you write "... namespaces "urn=urn:hl7-org:v2xml". Shouldn'ti t be "urn=hl7-org:v2xml" ?

                   

                  Br,

                   

                  Dennis

                  1 of 1 people found this helpful
                  • 6. Re: CBR/Drools configuration problem
                    Tom Fennelly Master

                    Tim Marks wrote:

                     

                    As suggested, I changed from using CBR-Drools to CBR-XPath.

                    If the XML data contains a namespace, it does not work.

                    Once namespace removed from XML data, CBR-XPath works.

                     

                    Found posts with people having similar namespace issues (i.e. http://community.jboss.org/message/505555#505555)

                    Have yet to find a solution to this problem.

                     

                    Did you define the namespaces for the XPath rules?  See the fun_cbr quickstart (note the <namespace> config):

                     

                    <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="ContentBasedRouter">
                        <property name="cbrAlias" value="XPath"/>
                        <property name="destinations">
                            <namespace prefix="ord" uri="http://org.jboss.soa.esb/Order" />
                    
                            <route-to service-category="BlueTeam"  service-name="GoBlue"  expression="/ord:Order[@statusCode='0']" />
                            <route-to service-category="RedTeam"   service-name="GoRed"   expression="/ord:Order[@statusCode='1']" />
                            <route-to service-category="GreenTeam" service-name="GoGreen" expression="/ord:Order[@statusCode='2']" />
                        </property>
                    </action>
                    
                    1 of 1 people found this helpful
                    • 7. Re: CBR/Drools configuration problem
                      Tim Marks Newbie

                      Dennis & Tom -

                      It took me a while to figure out I had not included the namespace prefix in my XPath expression.

                      Thanks for your input.