Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Header Enricher & Groovy

  1. #1
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default Header Enricher & Groovy

    Hello, Mark, Oleg & Dave

    You all are authors of integration with Groovy.
    So, here's my wish to improve that solution.
    Why not implement an evalutaion of value for one header through <groovy:script>?
    You already support that through SpEL.
    But SpEL is single line script, and in my case it doesn't solve my problem.
    And further I don't see reason to write separate Java-class or to move solving of my task to Transformer.
    My sample is:
    1. Payload is XML
    2. I have a delayer
    3. I have to set a header for delayer
    4. The value for this header is Date based on content of payload
    5. So, I evalute xPath -> parse result to Date -> add delay from SpringContext -> and put final Date to header for delayer.

    I think it is a reason where we can use short Groovy scripts.
    I see no reason to write a complete transformer for setting value of only one header.

    Thanks in advance

    Artem

  2. #2
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    Hello.
    So, colleagues, because you do not respond to my post, I tried to implement this decision by ьнself.
    The fact that I came out in the attachment.
    I marked my changes as TODO
    Here is an example of usage:
    HTML Code:
     <header-enricher>
                <header name="logId" ref="logRequestResponseAction" method="log"/>
                <header name="TEST_HEADER">
                    <groovy:script>
                        <![CDATA[
                                new XmlParser().parseText(headers.requestXml).with {
                                    return new Date(Date.parse("yyyy-MM-dd'T'HH:mm:ss", headerData.messageDescription.requestDate.text()).time + 300 * 1000)
                                }
                                ]]>
                    </groovy:script>
                </header>
            </header-enricher>
    I think this functionality could be useful.

    Best wishes.
    Artem
    Attached Files Attached Files

  3. #3
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    Thanks for the code. It's probably not ideal to force spring-integration-core to have a new dependency that way, but there might be other ways to do the same thing. This already works out of the box, for instance, and it isn't a lot more verbose than your example:

    Code:
          <header-enricher>
                <header name="logId" ref="logRequestResponseAction" method="log"/>
                <header name="TEST_HEADER" ref="enricher" method="enrich"/>
            </header-enricher>
    	<lang:groovy id="enricher">
    		<lang:inline-script>
    		<![CDATA[
    			class Enricher {
    				def enrich(Map headers) {
                                new XmlParser().parseText(headers.requestXml).with {
                                    return new Date(Date.parse("yyyy-MM-dd'T'HH:mm:ss", headersData.messageDescription.requestDate.text()).time + 300 * 1000)
                                }
                                    }
    			}
    		]]>
    		</lang:inline-script>
    	</lang:groovy>
    Last edited by Dave Syer; Apr 28th, 2011 at 08:58 AM. Reason: spelling

  4. #4
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Artem, sorry for late reply. Some of us were traveling

    @Dave

    I agree we don't want to have core depend on Groovy, but it seems like in his case its just an implementation of MessageProcessor strategy and a minor change to schema.
    Let me try to see if I can rework it a bit.

    Artem, meanwhile can you open up a feature request so we can incorporate these comments in it.

  5. #5
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    Hello, guys!

    I'm glad to see (read) you.

    Depending on what you say? Sorry for my mistakes. But there are dependency only in unnecessary imports in my code in HeaderEnricher.
    In my maven project exists depency only from artifact spring-integration-core right now

    I tried to reuse code that you already have.

    And it is my comment about Dave's sample:
    In your solution in SI we can write some short groovy script in Message context. Your sample is full defined class. If I then want more scripts like my task I'll have to write a lot of code. And in the end I decide to move it all into a single class.

    Oleg, what do you mean about "open up a feature request"? Should I open issue in JIRA?

    Thank you for your work
    Artem

  6. #6
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Yes, as 'New Feature" in JIRA

  7. #7
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    IMHO it should be treated the same as:
    Code:
    <int:header name="TEST_HEADER">
                <bean class="org.Foo"/>
    </int:header>
    Basically your inner-bean support instead of the 'ref'

  8. #8
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Ok, I have it working now with the <bean> and <script> without core being dependent on groovy and/or things like this:
    Code:
    DomUtils.getChildElementsByTagName(headerElement, "script");
    Let us know when you open a JIRA

  9. #9
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    Thank you, Oleg, for your enthusiasm and eagerness to work .
    I will open issue tomorrow in our time - you'll even sleep.

    Thank you again

    Artem

  10. #10
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    I added JIRA "New Feature":
    https://jira.springsource.org/browse/INT-1881

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •