Spring Integration
  1. Spring Integration
  2. INT-1727

Extend groovy:script tag to support a ScriptVariableGenerator strategy

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Complete
    • Affects Version/s: 2.0.1
    • Fix Version/s: 2.0.2
    • Component/s: Groovy Support
    • Labels:
      None

      Description

      See the forum topic for discussion and patch

        Issue Links

          Activity

          Hide
          Mark Fisher added a comment -

          The original description was: "Extend groovy:script tag to recieve custom MessageContextBindingCustomizer"

          However, this particular issue ended up focusing on the the addition of the ScriptVariableGenerator for returning a Map of variables. That strategy is intended to be generic so that implementations should be able to work with other scripting languages that we support in the future. It is focused on simply returning a Map of key/value pairs, and the Message instance is provided to the strategy method.

          In the case of Groovy, we happen to be using a GroovyObjectCustomizer to invoke the ScriptVariableGenerator. However, that is an implementation detail, and it will very likely change in the future if there is a better alternative for passing the Map of variables at runtime for script execution.

          The linked issue (INT-1784) might be of interest for those who really want to provide a GroovyObjectCustomizer rather than simply provide script variables. For example, if you are implementing a Groovy-based DSL and need to modify the groovy.lang.MetaClass, the "customizer" support would be appropriate.

          Show
          Mark Fisher added a comment - The original description was: "Extend groovy:script tag to recieve custom MessageContextBindingCustomizer" However, this particular issue ended up focusing on the the addition of the ScriptVariableGenerator for returning a Map of variables. That strategy is intended to be generic so that implementations should be able to work with other scripting languages that we support in the future. It is focused on simply returning a Map of key/value pairs, and the Message instance is provided to the strategy method. In the case of Groovy, we happen to be using a GroovyObjectCustomizer to invoke the ScriptVariableGenerator. However, that is an implementation detail, and it will very likely change in the future if there is a better alternative for passing the Map of variables at runtime for script execution. The linked issue ( INT-1784 ) might be of interest for those who really want to provide a GroovyObjectCustomizer rather than simply provide script variables. For example, if you are implementing a Groovy-based DSL and need to modify the groovy.lang.MetaClass, the "customizer" support would be appropriate.
          Hide
          Artem Bilan added a comment -

          Hello? Oleg & Mark.
          I've examined this solution and I've got a question:

          What's the problem with variables and inline groovy script?

          Thank you

          Show
          Artem Bilan added a comment - Hello? Oleg & Mark. I've examined this solution and I've got a question: What's the problem with variables and inline groovy script? Thank you
          Hide
          Artem Bilan added a comment -

          When I use the customizer reference to bean like this:

              <bean id="fooCustomizer"
                    class="org.springframework.integration.groovy.VariableBindingGroovyObjectCustomizerDecorator">
                  <property name="variables">
                      <util:map>
                          <entry key="foo" value="bar"/>
                      </util:map>
                  </property>
              </bean>
          

          My inline script work very well.

          Why can not I use the variable tag in this case?

          Show
          Artem Bilan added a comment - When I use the customizer reference to bean like this: <bean id= "fooCustomizer" class= "org.springframework.integration.groovy.VariableBindingGroovyObjectCustomizerDecorator" > <property name= "variables" > <util:map> <entry key= "foo" value= "bar" /> </util:map> </property> </bean> My inline script work very well. Why can not I use the variable tag in this case?
          Hide
          Oleg Zhurakousky added a comment -

          The motivation for not exposing customizations for inline scripts is because inline scripts are generally static one-liners that are very similar top SpEL. In fact it truly is for use cases where you would use SpEL, but targeting the developers who prefer Groovy.
          However, If you need to use the full power of Groovy dynamics (e.g. refreshing Groovy script based on time intervals, customizing it at runtime etc.), then you can further configure it with customizer, decorator, refresh-delay etc...

          Hope that helps.

          Show
          Oleg Zhurakousky added a comment - The motivation for not exposing customizations for inline scripts is because inline scripts are generally static one-liners that are very similar top SpEL. In fact it truly is for use cases where you would use SpEL, but targeting the developers who prefer Groovy. However, If you need to use the full power of Groovy dynamics (e.g. refreshing Groovy script based on time intervals, customizing it at runtime etc.), then you can further configure it with customizer, decorator, refresh-delay etc... Hope that helps.
          Hide
          Oleg Zhurakousky added a comment -

          Let me clarify one thing as well.
          We currently expose both; GroovyCustomizer and ScriptVariableGenerator

          GroovyCustomizer - is exposed regardless wether you are using inline script or not and obviously is confusing since you can do practically everything there. But the real intention was to use GroovyCustomizer to customize Groovy execution environment (e.g., properties, meta-data to address dsl concerns etc.)

          ScriptVariableGenerator - only to address the dynamics of the script itself with custom variable bindings. And it is ONLY exposed if you provide a location for the script (not inline)

          Show
          Oleg Zhurakousky added a comment - Let me clarify one thing as well. We currently expose both; GroovyCustomizer and ScriptVariableGenerator GroovyCustomizer - is exposed regardless wether you are using inline script or not and obviously is confusing since you can do practically everything there. But the real intention was to use GroovyCustomizer to customize Groovy execution environment (e.g., properties, meta-data to address dsl concerns etc.) ScriptVariableGenerator - only to address the dynamics of the script itself with custom variable bindings. And it is ONLY exposed if you provide a location for the script (not inline)

            People

            • Assignee:
              Oleg Zhurakousky
              Reporter:
              Baruch Sadogursky
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: