2 Replies Latest reply on Sep 3, 2008 6:55 PM by jjarkko

    Can I pass parameters/properties to groovy scripts?

      I don't want to write a separate groovy script for every action that I define. The only thing that changes in my actions is some value, but the functionality is the same.

      How can I pass a parameter/property to a groovy script from the jboss-esb.xml file and then retrieve that value inside my script?

      I would like to do something like this:

      <action name="MyGroovyAction" class="org.jboss.soa.esb.actions.scripting.GroovyActionProcessor">
       <property name="script" value="/scripts/my_groovy_func.groovy" />
       <property name="parameter1" value="123" />
      </action>
      


      Is this possible? If so, how do I retrieve the value inside my groovy script?

        • 1. Re: Can I pass parameters/properties to groovy scripts?

          I took a look at the ESB source code for the Groovy Action and noticed that the configTree is bound to the "config" variable in groovy.

          So, the solution is:

          import org.jboss.soa.esb.message.*;
          import org.jboss.soa.esb.helpers.ConfigTree;
          
           MYPARAM_NAME = "parameter1";
           myparam1 = config.getAttribute(MYPARAM_NAME);
          
          println "the value of the parameter is " + myparam1;
          


          • 2. Re: Can I pass parameters/properties to groovy scripts?

            I've always wondered if it is possible to modify the config tree of next action in action pipeline.

            Something like this:

            action1: do some logic which resolves that decides that param1=1
            action2: is configured using configTree parameters (like most stock actions, wise, soapclient, System.out.println action)

            Now I'd like prepare/calculate the config param needed by action2 in action1.
            A simple case would be prepare the message

            <action name="prepare" class="acme.PrepareMessage">
            </action>
            <action name="println" class="org.jboss.soa.esb.actions.SystemPrintln">
             <property name="message" value="${from.previous.action}"/>
            </action>