From ffe132986bffbfb361b15b5bad6113142a5efa55 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 27 Dec 2011 16:26:42 -0500 Subject: [PATCH] INT-2342 --- ...thodAnnotationPublisherMetadataSource.java | 13 ++++----- .../aop/PublisherAnnotationAdvisorTests.java | 28 +++++++++++++++++-- 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationPublisherMetadataSource.java b/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationPublisherMetadataSource.java index 756128d6eb..ef6ed8c4dc 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationPublisherMetadataSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aop/MethodAnnotationPublisherMetadataSource.java @@ -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; } diff --git a/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherAnnotationAdvisorTests.java b/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherAnnotationAdvisorTests.java index e51ee175dd..97c9f9596f 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherAnnotationAdvisorTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/aop/PublisherAnnotationAdvisorTests.java @@ -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) {} }