1 Reply Latest reply on Nov 4, 2008 11:02 AM by Daniel Bevenius

    Drools: How to retrieve value out of HashMap

    Chris Sun Newbie

      Via JMS an javax.jms.ObjectMessage containing a java.util.HashMap arrives at the ESB. With Drools I would like to check some keys in this HashMap and route the Message.

      JMS Sender:

      HashMap<String, Object> map = new HashMap<String, Object>(4);
       map.put("lockType", lockType);
       map.put("accountId", accountId);
       map.put("contactId", contactId);
       map.put("productId", productId);
      return session.createObjectMessage(map);


      ContentBasedRouter:
      <action class="org.jboss.soa.esb.actions.ContentBasedRouter" name="MessageFilter">
       <property name="ruleSet" value="FilterRules.drl"/>
       <property name="ruleReload" value="true"/>
       <property name="destinations">
       <route-to destination-name="DemoDestination" service-category="locking" service-name="testDestination"/>
       </property>
       <property name="object-paths">
       <object-path esb="body.'org.jboss.soa.esb.message.defaultEntry'" />
       </property>
       </action>


      Rule:
      package com.unitedinternet.esb
      
      #list any import classes here.
      import org.jboss.soa.esb.message.Message;
      import java.util.HashMap;
      
      #declare any global variables here
      global java.util.List destinations;
      
      rule "route"
       when
      
       map: HashMap (???????)
       then
      
       System.out.println("####################");
       destinations.add("DemoDestination");
      end

      How can I retrieve a Keyvalue in the condition section of the rule?
      What excactly is org.jboss.soa.esb.message.defaultEntry ?

        • 1. Re: Drools: How to retrieve value out of HashMap
          Daniel Bevenius Master

          Hi,

          I think the following should work:

          rule "PrintMap"
           no-loop
           when
           $m : Message ()
           $map : HashMap () from $m.body.get()
           then
           System.out.println("Print Map " + $map);
          end
          


          What excactly is org.jboss.soa.esb.message.defaultEntry ?

          This is the default location for an object added to the body.
          For example if you call message.getBody.add("some string"); that object can be accessed by either
          message.getBody().get();
          or
          message.getBody().get("org.jboss.soa.esb.message.defaultEntry");

          Regards,

          /Daniel