Announcement Announcement Module
Collapse
No announcement yet.
SpEL for MessageHeaders Constants Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • SpEL for MessageHeaders Constants

    I'm trying to replace a message header correlation id object with its string representation (so I can send it across JMS to another SI-backed service, get it back, and then aggregate). The following works fine:

    Code:
    <si:header name="correlationId"
               expression="headers.get('correlationId').toString()"
               overwrite="true"/>
    However, I would rather not use a string for the header name and instead use the constant defined in MessageHeaders. Something like this:

    Code:
    <si:header name="#{ T(org.springframework.integration.MessageHeaders).CORRELATION_ID }"
               expression="headers.get(org.springframework.integration.MessageHeaders.CORRELATION_ID.toString())"
               overwrite="true"/>
    However, that fails with a ClassCastException.

    Suggestions on what the correct way to do this is?

    Thanks.

  • #2
    Code:
    <header-enricher input-channel="inputY" output-channel="inputX">
        <correlation-id expression="headers.get(T(org.springframework.integration.MessageHeaders).CORRELATIONID).toString()"/>
    </header-enricher>
    Last edited by Gary Russell; May 16th, 2012, 02:04 PM.

    Comment


    • #3
      Hmmm - that doesn't work ...

      Comment


      • #4
        I am not sure why you can't do it with pure SpEL, but this works...

        Code:
        <header-enricher input-channel="inputY" output-channel="inputX">
            <correlation-id expression="headers.get(@correlationIdHeader).toString()"
        	overwrite="true" />
        </header-enricher>
        
        <util:constant id="correlationIdHeader" static-field="org.springframework.integration.MessageHeaders.CORRELATION_ID"/>

        Comment


        • #5
          Actually, this is even simpler; given correlationId is a first class citizen amongst headers...

          Code:
          <header-enricher input-channel="inputY" output-channel="inputX">
              <correlation-id expression="headers.correlationId.toString()"
          	overwrite="true" />
          </header-enricher>

          Comment


          • #6
            Whoa, that is clean. Thanks for your time and help!

            Comment

            Working...
            X