diff --git a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.java b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.java index 1e0d7a0189..34490dfafd 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/endpoint/AbstractMessageSource.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.springframework.util.CollectionUtils; /** * @author Mark Fisher + * @author Oleg Zhurakousky * @since 2.0 */ public abstract class AbstractMessageSource extends AbstractExpressionEvaluator implements MessageSource { @@ -46,9 +47,7 @@ public abstract class AbstractMessageSource extends AbstractExpressionEvaluat public final Message receive() { Message message = null; Object result = this.doReceive(); - Map headers = this.evaluateHeaders(); - if (result instanceof Message) { try { message = (Message) result; @@ -63,7 +62,7 @@ public abstract class AbstractMessageSource extends AbstractExpressionEvaluat message = builder.build(); } } - else { + else if (result != null) { T payload = null; try { payload = (T) result; diff --git a/spring-integration-core/src/test/java/org/springframework/integration/message/MethodInvokingMessageSourceTests.java b/spring-integration-core/src/test/java/org/springframework/integration/message/MethodInvokingMessageSourceTests.java index 11f65d4be0..bfee7ee3ed 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/message/MethodInvokingMessageSourceTests.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/message/MethodInvokingMessageSourceTests.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. @@ -18,12 +18,12 @@ package org.springframework.integration.message; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import java.util.HashMap; import java.util.Map; import org.junit.Test; - import org.springframework.expression.Expression; import org.springframework.expression.common.LiteralExpression; import org.springframework.expression.spel.standard.SpelExpressionParser; @@ -88,6 +88,15 @@ public class MethodInvokingMessageSourceTests { source.receive(); } + @Test + public void testNullReturningMethodReturnsNullMessage() { + MethodInvokingMessageSource source = new MethodInvokingMessageSource(); + source.setObject(new TestBean()); + source.setMethodName("nullReturningMethod"); + Message message = source.receive(); + assertNull(message); + } + @SuppressWarnings("unused") private static class TestBean { @@ -102,6 +111,10 @@ public class MethodInvokingMessageSourceTests { public void invalidMethodWithNoReturnValue() { } + + public Object nullReturningMethod() { + return null; + } } }