Header Enricher
- If you only need to add headers to a Message, and they are not dynamically determined by Message content,
- then referencing a custom implementation may be overkill. For that reason, Spring Integration provides the
- 'header-enricher' element.
-
-
- ]]>
+ If you only need to add headers to a Message, and they are not dynamically determined by the Message content,
+ then referencing a custom implementation of the Transformer may be an overkill. For that reason,
+ Spring Integration provides the Header Enricher which is exposed via <header-enricher> element.
+
+
+
+
+]]>
+
+
+ Header Enricher also provides helpful sub-elements to set well known header names.
+
+
+
+
+
+
+]]>
+
+ In the above configuration you can clearly see that for well known headers such as errorChannel,
+ correlationId, priority, replyChanneletc., instead of using generic <header>
+ sub-element where you would have to provide both header 'name' and 'value', you can use convenient sub-elements
+ allowing you to set those values directly.
+
+
+ SpEL Support
+
+
+ In Spring Integration 2.0 we are introducing convenience of
+ Spring Expression Language (SpEL)
+ to help configure many different components. Header Enricher is one of them.
+ A lot of times, header value cannot be defined statically and has to be computed dynamically. That is why
+ Header Enricher allows you to also specify bean 'ref' and 'method' that will calculate the
+ header value. Let's look at the following configuration:
+
+
+
+
+
+]]>
+
+
+
+ As you can see that the computation logic to determine the header value is actually pretty simple and the
+ natural question would be is there a simpler way to accomplish this? And that is where SpEL shows its true power.
+
+
+
+]]>
+
+ As you can see, with SpEL for simple cases like above we no longer have to provide a separate class and configure
+ it in the application context. All we need is to use expression attribute and provide a valid
+ SpEL expression. You can also see that 'payload' and 'headers' are bound as variables to the SpEL Evaluation Context
+ giving you full access to the incoming Message.
+
+
+ Adapter specific Header Enrichers
+
+
+ As you go through the manual you will see that as an added convenience
+ Spring Integration provides adapter specific Header Enrichers (e.g., WS, XMPP, etc.)
+