3
votes

I'me using Spring Integration and java dsl specifications to implement my IntegrationFlow. I want to use an custom header enricher to add some file names to the header, it will be something like :

public class FileHeaderNamingEnricher {
    public Message<File> enrichHeader(Message<File> fileMessage) {
            // getting some details fom the database ...
            return messageBuilder
                    .setHeader("filename", "somestuff")
                    .build();
        }  
}

And my Integration flow will look like :

public IntegrationFlow myflow() {
        return IntegrationFlows.from("input")
                                .enrich // here I want to enrich the header using my class
    }

Can any one help me with this please ?

1

1 Answers

4
votes

You can have your FileHeaderNamingEnricher extend AbstractReplyProducingMesageHandler (put your code in handleRequestMessage()).

Or, implement GenericHandler<T> (its handle method gets the payload and headers as parameters and can return a message).

Then use the .handle method...

 ...
 .handle(myEnricher())
 ...

 @Bean
 public void MessageHandler myEnricher() {
    return new FileHeaderNamingEnricher();
 }