INT-1534 @Header annotations now accept hyphenated header names

This commit is contained in:
Mark Fisher
2010-10-18 10:20:50 -04:00
parent 2f9f92235c
commit a3d14aab9c
2 changed files with 19 additions and 3 deletions

View File

@@ -570,9 +570,12 @@ public class MessagingMethodInvokerHelper<T> 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) {

View File

@@ -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() {