INT-4284: INFO about overriding readOnly headers
JIRA: https://jira.spring.io/browse/INT-4284 Add `INFO` into the `MessageBuilder#copyHeadersIfAbsent()` when end-user tries to populate headers which are `readOnly` We can't throw exception on the matter since can modify `readOnlyHeaders` and that would force end-user to add `header-filter` logic to the application. * Document `readOnly` headers in the `message.adoc` **Cherry-pick 4.3.x**
This commit is contained in:
committed by
Gary Russell
parent
2c7bf9271c
commit
33e9ce912f
@@ -155,7 +155,7 @@ public class IntegrationMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isReadOnly(String headerName) {
|
||||
public boolean isReadOnly(String headerName) {
|
||||
return super.isReadOnly(headerName) || this.readOnlyHeaders.contains(headerName);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,9 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
@@ -43,6 +46,8 @@ import org.springframework.util.ObjectUtils;
|
||||
*/
|
||||
public final class MessageBuilder<T> extends AbstractIntegrationMessageBuilder<T> {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(MessageBuilder.class);
|
||||
|
||||
private final T payload;
|
||||
|
||||
private final IntegrationMessageHeaderAccessor headerAccessor;
|
||||
@@ -176,7 +181,16 @@ public final class MessageBuilder<T> extends AbstractIntegrationMessageBuilder<T
|
||||
*/
|
||||
@Override
|
||||
public MessageBuilder<T> copyHeadersIfAbsent(Map<String, ?> headersToCopy) {
|
||||
this.headerAccessor.copyHeadersIfAbsent(headersToCopy);
|
||||
if (headersToCopy != null) {
|
||||
for (Map.Entry<String, ?> 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user