Search code examples
java-8spring-integrationspring-integration-dsl

Enriching Header with the value from the Transformer


I have a spring integration flow. It reads the file. The file can belong to the consumer.Once I find the consumer I want to add that CONSUMER to the header so later on I can use e.g. In error handling I can check that did I even get the consumer looking at the header.

IntegrationsFlows.from(directorySource)
.transform(new ConsumerFinderTransformer()
.enrichHeaders(h -> h.header("CONSUMER" ,payload)

How do I get the payload in the enrichHeaders that's returned by the ConsumerFinderTransformer here.

I cannot find a way. Any help will be appreacited


Solution

  • This one is there for you:

        /**
     * Add a single header specification where the value is a String representation of a
     * SpEL {@link Expression}. If the header exists, it will <b>not</b> be overwritten
     * unless {@link #defaultOverwrite(boolean)} is true.
     * @param name the header name.
     * @param expression the expression.
     * @return the header enricher spec.
     */
    public HeaderEnricherSpec headerExpression(String name, String expression) {
    

    So, your code should be like:

    .enrichHeaders(h -> h.headerExpression(“CONSUMER" , “payload”)