From a3d14aab9c4f6b1e66a0f0334761c392b2f68292 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Mon, 18 Oct 2010 10:20:50 -0400 Subject: [PATCH] INT-1534 @Header annotations now accept hyphenated header names --- .../util/MessagingMethodInvokerHelper.java | 9 ++++++--- ...thodInvokingMessageProcessorAnnotationTests.java | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java index f47792d0e2..053bbafa28 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/MessagingMethodInvokerHelper.java @@ -570,9 +570,12 @@ public class MessagingMethodInvokerHelper extends AbstractExpressionEvaluator } Assert.notNull(headerName, "Cannot determine header name. Possible reasons: -debug is " + "disabled or header name is not explicitly provided via @Header annotation."); - String headerExpression = "headers." + headerName + relativeExpression; - return (headerAnnotation.required()) ? headerExpression : "headers['" + headerName + "'] != null ? " - + headerExpression + " : null"; + String headerRetrievalExpression = "headers['" + headerName + "']"; + String fullHeaderExpression = headerRetrievalExpression + relativeExpression; + String fallbackExpression = (headerAnnotation.required()) + ? "T(org.springframework.util.Assert).isTrue(false, 'required header not available: " + headerName + "')" + : "null"; + return headerRetrievalExpression + " != null ? " + fullHeaderExpression + " : " + fallbackExpression; } private synchronized void setExclusiveTargetParameterType(TypeDescriptor targetParameterType) { diff --git a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorAnnotationTests.java b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorAnnotationTests.java index d44d352509..d633e50c72 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorAnnotationTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/handler/MethodInvokingMessageProcessorAnnotationTests.java @@ -296,6 +296,15 @@ public class MethodInvokingMessageProcessorAnnotationTests { assertEquals("DOE, John", result); } + @Test + public void fromMessageToHyphenatedHeaderName() throws Exception { + Method method = TestService.class.getMethod("headerNameWithHyphen", String.class); + MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method); + Message message = MessageBuilder.withPayload("payload").setHeader("foo-bar", "abc").build(); + Object result = processor.processMessage(message); + assertEquals("ABC", result); + } + @SuppressWarnings("unused") private static class MultipleMappingAnnotationTestBean { @@ -386,6 +395,10 @@ public class MethodInvokingMessageProcessorAnnotationTests { public String irrelevantAnnotation(@BogusAnnotation() String value) { return value; } + + public String headerNameWithHyphen(@Header("foo-bar") String foobar) { + return foobar.toUpperCase(); + } } private Message getMessage() {