INT-1794 no longer creating a Message when a MessageSource returns a null payload object
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.
|
||||
@@ -30,6 +30,7 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*/
|
||||
public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluator implements MessageSource<T> {
|
||||
@@ -46,9 +47,7 @@ public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluat
|
||||
public final Message<T> receive() {
|
||||
Message<T> message = null;
|
||||
Object result = this.doReceive();
|
||||
|
||||
Map<String, Object> headers = this.evaluateHeaders();
|
||||
|
||||
if (result instanceof Message<?>) {
|
||||
try {
|
||||
message = (Message<T>) result;
|
||||
@@ -63,7 +62,7 @@ public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluat
|
||||
message = builder.build();
|
||||
}
|
||||
}
|
||||
else {
|
||||
else if (result != null) {
|
||||
T payload = null;
|
||||
try {
|
||||
payload = (T) result;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user