max3d
max3d

Reputation: 1507

Remove custom header with @Transformer annotation

I would like to know if it is possible to remove a custom message header, with @Transformer annotation.

@Transformer(inputChannel = "inputChannel", outputChannel = "outputChannel")
public Message transform(Message message) {
    HeaderFilter filter = new HeaderFilter("privateKey");
    return message;
}

Upvotes: 0

Views: 432

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121347

Correct, you can do that via remove function:

@Transformer(inputChannel = "inputChannel", outputChannel = "outputChannel")
public Message transform(Message message) {
    return MessageBuilder.fromMessage(message).removeHeader("privateKey").build();
}

You don't need any other logic in this method.

On the other hand you can use HeaderFilter instead:

@Transformer(inputChannel = "inputChannel", outputChannel = "outputChannel")
@Bean
public HeaderFilter headerFilter() {
    return new HeaderFilter("privateKey");
}

Upvotes: 2

Related Questions