diff --git a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java index 525b3987fb..e5582a2c16 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdvice.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,8 +77,7 @@ public class ExpressionEvaluatingRequestHandlerAdvice extends AbstractRequestHan private EvaluationContext evaluationContext; /** - * Set the expression to evaluate against the message after a successful - * handler invocation. + * Set the expression to evaluate against the message after a successful handler invocation. * Defaults to {@code payload}, if {@code successChannel} is configured. * @param onSuccessExpression the SpEL expression. * @since 4.3.7 @@ -88,8 +87,7 @@ public class ExpressionEvaluatingRequestHandlerAdvice extends AbstractRequestHan } /** - * Set the expression to evaluate against the message after a successful - * handler invocation. + * Set the expression to evaluate against the message after a successful handler invocation. * Defaults to {@code payload}, if {@code successChannel} is configured. * @param onSuccessExpression the SpEL expression. * @since 5.0 @@ -228,7 +226,7 @@ public class ExpressionEvaluatingRequestHandlerAdvice extends AbstractRequestHan } if (!this.trapException) { if (e instanceof ThrowableHolderException) { // NOSONAR - throw (ThrowableHolderException) e; + throw e; } else { throw new ThrowableHolderException(actualException); // NOSONAR lost stack trace @@ -276,7 +274,7 @@ public class ExpressionEvaluatingRequestHandlerAdvice extends AbstractRequestHan MessagingException messagingException = new MessageHandlingExpressionEvaluatingAdviceException(message, "Handler Failed", unwrapThrowableIfNecessary(exception), evalResult); - ErrorMessage errorMessage = new ErrorMessage(messagingException); + ErrorMessage errorMessage = new ErrorMessage(messagingException, message.getHeaders()); this.messagingTemplate.send(this.failureChannel, errorMessage); } return evalResult; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdviceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdviceTests.java index a450b0bfdd..babbace5a3 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdviceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/advice/ExpressionEvaluatingRequestHandlerAdviceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2022 the original author or authors. + * Copyright 2017-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ package org.springframework.integration.handler.advice; +import java.util.Map; + import org.aopalliance.aop.Advice; import org.junit.jupiter.api.Test; @@ -55,13 +57,15 @@ public class ExpressionEvaluatingRequestHandlerAdviceTests { @Test public void test() { this.in.send(new GenericMessage<>("good")); - this.in.send(new GenericMessage<>("junk")); + this.in.send(new GenericMessage<>("junk", Map.of("some_request_header_key", "some_request_header_value"))); assertThat(config.successful).isInstanceOf(AdviceMessage.class); assertThat(config.successful.getPayload()).isEqualTo("good was successful"); + assertThat(config.failed).isInstanceOf(ErrorMessage.class); Object evaluationResult = ((MessageHandlingExpressionEvaluatingAdviceException) config.failed.getPayload()) .getEvaluationResult(); assertThat((String) evaluationResult).startsWith("junk was bad, with reason:"); + assertThat(config.failed.getHeaders()).containsEntry("some_request_header_key", "some_request_header_value"); } @Configuration