INT-1534 @Header annotations now accept hyphenated header names
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user