Announcement Announcement Module
No announcement yet.
How do I programmatically create a HeaderEnricher? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I programmatically create a HeaderEnricher?

    I'm new to Spring & Spring Integration. My first task is to take an existing Spring 2.5.6 & Spring Integraiton 1.0.3 app and upgrade to Spring Framework 3.0.5 & Spring Integration 2.0.5.

    Can someone point me to examples of how to make a HeaderEnricher programmatically in spring integration 2.0.5? I am not understanding how to implement the API. Previously, we were able to use a Map<String, Object> to specify the headers to add. Now we have to use Map<String, ? extends HeaderEnricher.HeaderValueMessageProcessor<?>> . Is there an example where someone has implemented this in code?

  • #2
    I don't understand why do you use HeaderEnricher.HeaderValueMessageProcessor<?> implementations as heder values? What is the reason?
    Can you give more info about your logic?

    Artem Bilan


    • #3
      I need to convert existing code to spring integration 2.0.5. In the existing code, a map of headers is created like this:

      Map<String, Object> headersToAdd = new HashMap<String, Object>();
      headersToAdd.put ("header1", "header1value");
      headersToAdd.put ("header2", "header2value");
      HeaderEnricher enricher = new HeaderEnricher(headersToAdd);

      This code no longer compiles. The new signature for the HeaderEnricher constructor is
      public HeaderEnricher(java.util.Map<java.lang.String,? extends HeaderEnricher.HeaderValueMessageProcessor<?>> headersToAdd)

      I don't understand how to modify the original code to conform to the new signature.


      • #4
        The typical creation of a HeaderEnricher instance would be through the <header-enricher> element as defined in the core Spring Integration schema. In that case, the parser will construct the object (and create the Map with HeaderValueMessageProcessor instances as values).

        So, could you explain your use-case so that we understand why you do want to create the object directly?

        We could add a 2nd constructor that accepts literal values and internally creates StaticHeaderValueMessageProcessor instances. The concern would be if people also want to support Expression in a similar way (then, we're basically back to the HeaderValueMessageProcessor approach where literal values, Expressions, and method-invoking bean+refs are all supported).


        • #5
          Well, as I said, I'm very new to spring and am taking over an existing app. The app is almost completely created programmatically, with only 2 beans defined in the context.xml file. The two beans are a web-resource (rest) and a (for lack of better term) "controller" bean. When a new request is received by the REST endpoint, the controller bean is invoked. This bean creates the spring integration "workflow" (if you will) from the information provided by the rest endpoint. I believe the programmatic approach was chosen over defining everything in the .xml file because the flows are created dynamically. I need to add the Headers to the message so that they can be used by the correlation strategy of my aggregator.