5 Replies Latest reply on Nov 9, 2009 6:52 AM by Anonymous User

    Content Based Routing using Drools

    Anushree Khandalkar Newbie

      Hi everyone,
      I am trying CBR in jboss esb using drools..
      I have successfully converted xml to POJO using smooks..
      Now I want to apply rules on the object..
      This is the code snippet for drools action:

      <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="ContentBasedRouter">
       <property name="ruleSet" value="SimpleRule.drl"/>
       <property name="ruleReload" value="true"/>
       <property name="destinations">
       <route-to destination-name="express" service-category="SecondServiceESB" service-name="SecondJMS"/>
       <route-to destination-name="normal" service-category="ThirdServiceESB" service-name="ThirdJMS"/>
       </property>
       <property name="object-paths">
       <object-path esb="body.com.acme.Order"/>
       </property>
       </action>


      But the action is not routed to either of the services.
      Order is the Bean class in com.acme package.

      Any idea as to why this is not working??

      Regards,
      Anushree

        • 1. Re: Content Based Routing using Drools
          Anonymous User Newbie

          Hello Anushree,

          Two possible reasons:
          (1) Neither of your rules in SimpleRule.drl matches your POJO
          (2) Your rules match, but the destination name is neither "express" nor "normal". In this case you would get a MessageRouteException like this:

          org.jboss.soa.esb.services.routing.MessageRouterException: Destination xxx does not exist your configuration ...


          Check your rules in "SimpleRule.drl".

          Regards,

          Dennis

          • 2. Re: Content Based Routing using Drools
            Anushree Khandalkar Newbie

            Hi,
            Thanks for your reply.
            The problem does not appear to be in in drl file.

            Here is my service in jboss-esb.xml

            <services>
             <service category="Proj2Service" description="Send Message" name="Proj2JMS">
             <listeners>
             <jms-listener busidref="firstQueue" is-gateway="false" name="Sample-Gateway"/>
             </listeners>
             <actions mep="OneWay">
             <action class="org.jboss.soa.esb.actions.SystemPrintln" name="action1">
             <property name="message" value="helloWorld"/>
             <property name="printfull" value="true"/>
             </action>
             <action name="transform" class="org.jboss.soa.esb.smooks.SmooksAction">
             <property name="smooksConfig" value="/smooks-res.xml" />
             <property name="resultType" value="JAVA" />
             <property name="java-output-location" value="$default" />
             <property name="reportPath" value="/home/anushree/Desktop/result.html"/>
             </action>
            
             <action name="map_order_components" class="org.jboss.soa.esb.actions.scripting.GroovyActionProcessor">
             <property name="script" value="/map_order_components.groovy" />
             </action>
            
             <action class="org.jboss.soa.esb.actions.SystemPrintln" name="action2">
             <property name="message" value="helloWorld2"/>
             <property name="printfull" value="true"/>
             </action>
            
             <action class="org.jboss.soa.esb.actions.BusinessRulesProcessor" name="ContentBasedRouter">
             <property name="ruleSet" value="SimpleRule.drl"/>
             <property name="ruleReload" value="false"/>
             <property name="stateful" value="true"/>
             <property name="destinations">
             <route-to destination-name="express" service-category="SecondServiceESB" service-name="SecondJMS"/>
             <route-to destination-name="normal" service-category="ThirdServiceESB" service-name="ThirdJMS"/>
             </property>
             <property name="object-paths">
             <object-path esb="body.order"/>
             </property>
             </action>
            
             <action class="org.jboss.soa.esb.actions.SystemPrintln" name="action3">
             <property name="message" value="helloWorld2"/>
             <property name="printfull" value="true"/>
             </action>
            
             </actions>
             </service>


            I am sending it a xml file.

            The problem appears to be in groovy script that i am running which is used to map the order bean onto the message
            to make it available to the ObjectMapper...
            Here is the groovy script ( i have saved it in proj root)
            message.getBody().add("order", message.getBody().get().get("order"));

            When i send the xml message i get this error:
            18:25:01,916 INFO [STDOUT] helloWorld:
            18:25:01,916 INFO [STDOUT] [ message: [ JBOSS_XML ]
            header: [ To: JMSEpr [ PortReference < <wsa:Address jms://localhost/queue/first_queue/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory/>, <wsa:ReferenceProperties jbossesb:java.naming.provider.url : localhost/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.url.pkgs : org.jnp.interfaces/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : AUTO_ACKNOWLEDGE/>, <wsa:ReferenceProperties jbossesb:transacted : false/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/jms/> > ] MessageID: a84b3cbd-9cce-4d74-b666-7d42ff635f4f RelatesTo: jms:correlationID#a84b3cbd-9cce-4d74-b666-7d42ff635f4f ]
            context: {}
            body: [ objects: {org.jboss.soa.esb.message.defaultEntry=<?xml version="1.0" encoding="UTF-8"?>
            <order>
             <productId>1</productId>
             <quantity>8</quantity>
             <price>5</price>
             </order>
            } ]
            fault: [ ]
            attachments: [ Named:{}, Unnamed:[] ]
            properties: [ {org.jboss.soa.esb.message.byte.size=2038, org.jboss.soa.esb.message.time.dod=Mon Nov 09 18:25:01 IST 2009, javax.jms.message.redelivered=false} ] ]
            18:25:03,117 ERROR [GroovyActionProcessor] Error executing Groovy script.
            org.jboss.soa.esb.actions.ActionProcessingException: Error reading script '/map_order_components.groovy' stream.
             at org.jboss.soa.esb.actions.scripting.GroovyActionProcessor.getScript(GroovyActionProcessor.java:174)
             at org.jboss.soa.esb.actions.scripting.GroovyActionProcessor.process(GroovyActionProcessor.java:147)
             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)
            18:25:03,118 WARN [ActionProcessingPipeline] No fault address defined for fault message! To: JMSEpr [ PortReference < <wsa:Address jms://localhost/queue/first_queue/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory/>, <wsa:ReferenceProperties jbossesb:java.naming.provider.url : localhost/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.url.pkgs : org.jnp.interfaces/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : AUTO_ACKNOWLEDGE/>, <wsa:ReferenceProperties jbossesb:transacted : false/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/jms/> > ] MessageID: a84b3cbd-9cce-4d74-b666-7d42ff635f4f RelatesTo: jms:correlationID#a84b3cbd-9cce-4d74-b666-7d42ff635f4f
            18:25:03,329 WARN [ServiceInvoker] Courier indicated (un)marshal related error org.jboss.soa.esb.couriers.CourierMarshalUnmarshalException: Failed to serialize ESB Message. during delivery to EPR [JMSEpr [ PortReference < <wsa:Address jms://localhost:1099/queue/DeadMessageQueue/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory/>, <wsa:ReferenceProperties jbossesb:java.naming.provider.url : localhost:1099/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.url.pkgs : org.jnp.interfaces/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : AUTO_ACKNOWLEDGE/>, <wsa:ReferenceProperties jbossesb:transacted : false/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/jms/> > ]] for Service [JBossESB-Internal:DeadLetterService] and Message [header: [ To: JMSEpr [ PortReference < <wsa:Address jms://localhost:1099/queue/DeadMessageQueue/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory/>, <wsa:ReferenceProperties jbossesb:java.naming.provider.url : localhost:1099/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.url.pkgs : org.jnp.interfaces/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : AUTO_ACKNOWLEDGE/>, <wsa:ReferenceProperties jbossesb:transacted : false/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/jms/> > ] MessageID: a84b3cbd-9cce-4d74-b666-7d42ff635f4f RelatesTo: jms:correlationID#a84b3cbd-9cce-4d74-b666-7d42ff635f4f ]]. Failed to serialize ESB Message.
            18:25:03,333 WARN [ActionProcessingPipeline] Failed to send response failure to DLQ service
            


            Any idea as to what is happening???

            Regards,
            Anushree

            • 3. Re: Content Based Routing using Drools
              Anonymous User Newbie

              Hi Anushree.

              " ... Failed to serialize ESB Message ..."

              You map to POJO. The implementation, which is behind POJO needs to be serializable. Serializability of your class is turned on by the class implementing the java.io.Serializable interface.

              You need to extend your order class as follows:

              class order implements java.io.Serializable {
              ...
              }


              Br,

              Dennis

              • 4. Re: Content Based Routing using Drools
                Anushree Khandalkar Newbie

                Hi,
                Ya I made the changes and now that error no longer comes...
                Though the error in executing Groovy script is still there...

                Here is the script:
                message.getBody().add("order", message.getBody().get().get("order"));

                I have put it in the root of the project..
                Here is the stack trace:

                20:06:20,220 INFO [STDOUT] helloWorld:
                20:06:20,221 INFO [STDOUT] [ message: [ JBOSS_XML ]
                header: [ To: JMSEpr [ PortReference < <wsa:Address jms://localhost/queue/first_queue/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory/>, <wsa:ReferenceProperties jbossesb:java.naming.provider.url : localhost/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.url.pkgs : org.jnp.interfaces/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : AUTO_ACKNOWLEDGE/>, <wsa:ReferenceProperties jbossesb:transacted : false/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/jms/> > ] MessageID: 31058236-2fd1-4439-96fb-bf3ebc3afb4a RelatesTo: jms:correlationID#31058236-2fd1-4439-96fb-bf3ebc3afb4a ]
                context: {}
                body: [ objects: {org.jboss.soa.esb.message.defaultEntry=<?xml version="1.0" encoding="UTF-8"?>
                <order>
                 <productId>1</productId>
                 <quantity>8</quantity>
                 <price>5</price>
                 </order>
                } ]
                fault: [ ]
                attachments: [ Named:{}, Unnamed:[] ]
                properties: [ {org.jboss.soa.esb.message.byte.size=2038, org.jboss.soa.esb.message.time.dod=Mon Nov 09 20:06:20 IST 2009, javax.jms.message.redelivered=false} ] ]
                20:06:22,318 ERROR [GroovyActionProcessor] Error executing Groovy script.
                org.jboss.soa.esb.actions.ActionProcessingException: Error reading script '/map_order_components.groovy' stream.
                 at org.jboss.soa.esb.actions.scripting.GroovyActionProcessor.getScript(GroovyActionProcessor.java:174)
                 at org.jboss.soa.esb.actions.scripting.GroovyActionProcessor.process(GroovyActionProcessor.java:147)
                 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)
                20:06:22,364 WARN [ActionProcessingPipeline] No fault address defined for fault message! To: JMSEpr [ PortReference < <wsa:Address jms://localhost/queue/first_queue/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.initial : org.jnp.interfaces.NamingContextFactory/>, <wsa:ReferenceProperties jbossesb:java.naming.provider.url : localhost/>, <wsa:ReferenceProperties jbossesb:java.naming.factory.url.pkgs : org.jnp.interfaces/>, <wsa:ReferenceProperties jbossesb:destination-type : queue/>, <wsa:ReferenceProperties jbossesb:specification-version : 1.1/>, <wsa:ReferenceProperties jbossesb:connection-factory : ConnectionFactory/>, <wsa:ReferenceProperties jbossesb:persistent : true/>, <wsa:ReferenceProperties jbossesb:acknowledge-mode : AUTO_ACKNOWLEDGE/>, <wsa:ReferenceProperties jbossesb:transacted : false/>, <wsa:ReferenceProperties jbossesb:type : urn:jboss/esb/epr/type/jms/> > ] MessageID: 31058236-2fd1-4439-96fb-bf3ebc3afb4a RelatesTo: jms:correlationID#31058236-2fd1-4439-96fb-bf3ebc3afb4a
                


                Thanks for your help...

                Regards,
                Anushree

                • 5. Re: Content Based Routing using Drools
                  Anonymous User Newbie

                  You obviously have an error in your groovy script.

                  It shouldn`t

                  message.getBody().add("order", message.getBody().get("order"));


                  instead of

                  message.getBody().add("order", message.getBody().get().get("order"));