INT-2342
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -73,18 +73,12 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
|
||||
public String getPayloadExpression(Method method) {
|
||||
String payloadExpression = null;
|
||||
method.getAnnotation(Payload.class);
|
||||
Payload methodPayloadAnnotation = AnnotationUtils.findAnnotation(method, Payload.class);
|
||||
if (methodPayloadAnnotation != null) {
|
||||
payloadExpression = StringUtils.hasText(methodPayloadAnnotation.value())
|
||||
? methodPayloadAnnotation.value()
|
||||
: "#" + PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME;
|
||||
}
|
||||
if (payloadExpression == null || payloadExpression.contains("#" + PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME)) {
|
||||
Assert.isTrue(!void.class.equals(method.getReturnType()),
|
||||
"When defining @Publisher on a void-returning method, an explicit payload " +
|
||||
"expression that does not rely upon a #return value is required.");
|
||||
}
|
||||
Annotation[][] annotationArray = method.getParameterAnnotations();
|
||||
for (int i = 0; i < annotationArray.length; i++) {
|
||||
Annotation[] parameterAnnotations = annotationArray[i];
|
||||
@@ -98,6 +92,11 @@ public class MethodAnnotationPublisherMetadataSource implements PublisherMetadat
|
||||
}
|
||||
}
|
||||
}
|
||||
if (payloadExpression == null || payloadExpression.contains("#" + PublisherMetadataSource.RETURN_VALUE_VARIABLE_NAME)) {
|
||||
Assert.isTrue(!void.class.equals(method.getReturnType()),
|
||||
"When defining @Publisher on a void-returning method, an explicit payload " +
|
||||
"expression that does not rely upon a #return value is required.");
|
||||
}
|
||||
return payloadExpression;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2011 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.
|
||||
@@ -30,6 +30,7 @@ import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.context.support.StaticApplicationContext;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.annotation.Payload;
|
||||
import org.springframework.integration.annotation.Publisher;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
|
||||
@@ -51,6 +52,20 @@ public class PublisherAnnotationAdvisorTests {
|
||||
|
||||
@Test
|
||||
public void annotationAtMethodLevel() {
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor();
|
||||
advisor.setBeanFactory(context);
|
||||
QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class);
|
||||
ProxyFactory pf = new ProxyFactory(new AnnotationAtMethodLevelTestBeanImpl());
|
||||
pf.addAdvisor(advisor);
|
||||
TestVoidBean proxy = (TestVoidBean) pf.getProxy();
|
||||
proxy.testVoidMethod("foo");
|
||||
Message<?> message = testChannel.receive(0);
|
||||
assertNotNull(message);
|
||||
assertEquals("foo", message.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotationAtMethodLevelOnVoidReturnWithParamAnnotation() {
|
||||
PublisherAnnotationAdvisor advisor = new PublisherAnnotationAdvisor();
|
||||
advisor.setBeanFactory(context);
|
||||
QueueChannel testChannel = context.getBean("testChannel", QueueChannel.class);
|
||||
@@ -113,13 +128,22 @@ public class PublisherAnnotationAdvisorTests {
|
||||
}
|
||||
|
||||
|
||||
static class AnnotationAtMethodLevelTestBeanImpl implements TestBean {
|
||||
static interface TestVoidBean {
|
||||
|
||||
void testVoidMethod(String s);
|
||||
|
||||
}
|
||||
|
||||
|
||||
static class AnnotationAtMethodLevelTestBeanImpl implements TestBean, TestVoidBean {
|
||||
|
||||
@Publisher(channel="testChannel")
|
||||
public String test() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
@Publisher(channel="testChannel")
|
||||
public void testVoidMethod(@Payload String s) {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user