diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java index d00048dc22..d2b332fd2c 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/MessageBuilder.java @@ -183,11 +183,9 @@ public final class MessageBuilder extends AbstractIntegrationMessageBuilder copyHeadersIfAbsent(Map headersToCopy) { if (headersToCopy != null) { for (Map.Entry entry : headersToCopy.entrySet()) { - if (!this.headerAccessor.isReadOnly(entry.getKey())) { - this.headerAccessor.setHeaderIfAbsent(entry.getKey(), entry.getValue()); - } - else if (logger.isInfoEnabled()) { - logger.info("The header [" + entry + "] is ignored for population because it is is readOnly."); + String headerName = entry.getKey(); + if (!this.headerAccessor.isReadOnly(headerName)) { + this.headerAccessor.setHeaderIfAbsent(headerName, entry.getValue()); } } } diff --git a/src/reference/asciidoc/message.adoc b/src/reference/asciidoc/message.adoc index ce819929d2..798bb555f9 100644 --- a/src/reference/asciidoc/message.adoc +++ b/src/reference/asciidoc/message.adoc @@ -373,8 +373,13 @@ In addition to the default strategy, two additional `IdGenerators` are provided; [[read-only-headers]] ===== Read-only Headers -The `MessageHeaders.ID` and `MessageHeaders.TIMESTAMP` are read-only headers and the cannot be overridden. -With the `spring.integration.readOnly.headers` global property (see <>) you can specify any header names which become read-only. +The `MessageHeaders.ID` and `MessageHeaders.TIMESTAMP` are read-only headers and they cannot be overridden. + +Since _version 4.3.2_, the `MessageBuilder` provides the `readOnlyHeaders(String... readOnlyHeaders)` API to customize a list of headers which should not be copied from an upstream `Message`. +Just the `MessageHeaders.ID` and `MessageHeaders.TIMESTAMP` are read only by default. +The global `spring.integration.readOnly.headers` property (see <>) is provided to customize `DefaultMessageBuilderFactory` for Framework components. +This can be useful when you would like do not populate some out-of-the-box headers, like `contentType` by the `ObjectToJsonTransformer` (see <>). + When you try to build a new message using `MessageBuilder`, this kind of headers are ignored and particular `INFO` message is emitted to logs. [[message-implementations]]