Skip to content

GH-3083: Support @Header with dotted literals #3084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1280,9 +1280,13 @@ private String determineHeaderExpression(Annotation headerAnnotation, MethodPara
AnnotationAttributes annotationAttributes =
(AnnotationAttributes) AnnotationUtils.getAnnotationAttributes(headerAnnotation);
String valueAttribute = annotationAttributes.getString(AnnotationUtils.VALUE);
int len = valueAttribute == null ? 0 : valueAttribute.length();
if (!StringUtils.hasText(valueAttribute)) {
headerName = methodParameter.getParameterName();
}
else if (len > 2 && valueAttribute.charAt(0) == '\'' && valueAttribute.charAt(len - 1) == '\'') {
headerName = valueAttribute.substring(1, len - 1);
}
else if (valueAttribute.indexOf('.') != -1) {
String[] tokens = valueAttribute.split("\\.", 2);
headerName = tokens[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ public Person(String fname, String lname) {
this.name = fname + " " + lname;
}

@Override
public String toString() {
return "Person: " + this.name;
}
Expand Down Expand Up @@ -544,7 +545,8 @@ private void optionalAndRequiredWithAnnotatedMethodGuts(MethodInvokingMessagePro
@Test
public void optionalAndRequiredDottedWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("optionalAndRequiredDottedHeader", String.class, Integer.class);
Method method = service.getClass().getMethod("optionalAndRequiredDottedHeader", String.class, Integer.class,
String.class);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
processor.setUseSpelInvoker(true);
optionalAndRequiredDottedWithAnnotatedMethodGuts(processor, false);
Expand All @@ -553,7 +555,8 @@ public void optionalAndRequiredDottedWithAnnotatedMethod() throws Exception {
@Test
public void compiledOptionalAndRequiredDottedWithAnnotatedMethod() throws Exception {
AnnotatedTestService service = new AnnotatedTestService();
Method method = service.getClass().getMethod("optionalAndRequiredDottedHeader", String.class, Integer.class);
Method method = service.getClass().getMethod("optionalAndRequiredDottedHeader", String.class, Integer.class,
String.class);
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
processor.setUseSpelInvoker(true);
DirectFieldAccessor compilerConfigAccessor = compileImmediate(processor);
Expand All @@ -569,17 +572,20 @@ private void optionalAndRequiredDottedWithAnnotatedMethodGuts(MethodInvokingMess
processor.setBeanFactory(mock(BeanFactory.class));
Message<String> message = MessageBuilder.withPayload("hello")
.setHeader("dot2", new DotBean())
.setHeader("dotted.literal", "dotted")
.build();
Object result = processor.processMessage(message);
assertThat(result).isEqualTo("null42");
assertThat(result).isEqualTo("null42dotted");
message = MessageBuilder.withPayload("hello")
.setHeader("dot1", new DotBean())
.setHeader("dot2", new DotBean())
.setHeader("dotted.literal", "dotted")
.build();
result = processor.processMessage(message);
assertThat(result).isEqualTo("bar42");
assertThat(result).isEqualTo("bar42dotted");
message = MessageBuilder.withPayload("hello")
.setHeader("dot1", new DotBean())
.setHeader("dotted.literal", "dotted")
.build();
try {
result = processor.processMessage(message);
Expand Down Expand Up @@ -1345,8 +1351,8 @@ public String optionalAndRequiredHeader(@Header(required = false) String prop,
}

public String optionalAndRequiredDottedHeader(@Header(name = "dot1.foo", required = false) String prop,
@Header(name = "dot2.baz") Integer num) {
return prop + num;
@Header(name = "dot2.baz") Integer num, @Header("'dotted.literal'") String dotted) {
return prop + num + dotted;
}

public Properties propertiesMethod(Properties properties) {
Expand Down