From cebfe8a58d2aa1147aa0c7232d5cf912f2a5515e Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 11 Jun 2019 09:06:07 -0400 Subject: [PATCH] GH-2958: Also Add to Common Header in AMHEMS Resolves https://github.com/spring-projects/spring-integration/issues/2958 The previous commit added the raw source message to a common header `IntegrationMessageHeaderAccessor.SOURCE_DATA` so that the spring-cloud-stream can construct an error message containing the data when using functions. However, we also need to add it to the common header when the `ErrorMessage` is created by Spring Integration for the normal message channel binder. This allows the DLQ processing to be agnostic as to who created the error message. (cherry picked from commit 78a0ec74e724b23e28326a8a0de3bfd08b179a86) --- .../support/AmqpMessageHeaderErrorMessageStrategy.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/AmqpMessageHeaderErrorMessageStrategy.java b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/AmqpMessageHeaderErrorMessageStrategy.java index 91870ab71d..58d7e63526 100644 --- a/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/AmqpMessageHeaderErrorMessageStrategy.java +++ b/spring-integration-amqp/src/main/java/org/springframework/integration/amqp/support/AmqpMessageHeaderErrorMessageStrategy.java @@ -16,12 +16,12 @@ package org.springframework.integration.amqp.support; -import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.springframework.amqp.support.AmqpHeaders; import org.springframework.core.AttributeAccessor; +import org.springframework.integration.IntegrationMessageHeaderAccessor; import org.springframework.integration.support.ErrorMessageStrategy; import org.springframework.integration.support.ErrorMessageUtils; import org.springframework.lang.Nullable; @@ -49,8 +49,11 @@ public class AmqpMessageHeaderErrorMessageStrategy implements ErrorMessageStrate public ErrorMessage buildErrorMessage(Throwable throwable, @Nullable AttributeAccessor context) { Object inputMessage = context == null ? null : context.getAttribute(ErrorMessageUtils.INPUT_MESSAGE_CONTEXT_KEY); - Map headers = context == null ? new HashMap() : - Collections.singletonMap(AMQP_RAW_MESSAGE, context.getAttribute(AMQP_RAW_MESSAGE)); + Map headers = new HashMap(); + if (context != null) { + headers.put(AMQP_RAW_MESSAGE, context.getAttribute(AMQP_RAW_MESSAGE)); + headers.put(IntegrationMessageHeaderAccessor.SOURCE_DATA, context.getAttribute(AMQP_RAW_MESSAGE)); + } if (inputMessage instanceof Message) { return new ErrorMessage(throwable, headers, (Message) inputMessage); }