INT-1794 no longer creating a Message when a MessageSource returns a null payload object

This commit is contained in:
Mark Fisher
2011-02-09 18:33:45 -06:00
parent a2aedfb969
commit cae35083e3
2 changed files with 18 additions and 6 deletions

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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 Mark Fisher
* @author Oleg Zhurakousky
* @since 2.0 * @since 2.0
*/ */
public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluator implements MessageSource<T> { 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() { public final Message<T> receive() {
Message<T> message = null; Message<T> message = null;
Object result = this.doReceive(); Object result = this.doReceive();
Map<String, Object> headers = this.evaluateHeaders(); Map<String, Object> headers = this.evaluateHeaders();
if (result instanceof Message<?>) { if (result instanceof Message<?>) {
try { try {
message = (Message<T>) result; message = (Message<T>) result;
@@ -63,7 +62,7 @@ public abstract class AbstractMessageSource<T> extends AbstractExpressionEvaluat
message = builder.build(); message = builder.build();
} }
} }
else { else if (result != null) {
T payload = null; T payload = null;
try { try {
payload = (T) result; payload = (T) result;

View File

@@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.junit.Test; import org.junit.Test;
import org.springframework.expression.Expression; import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression; import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.standard.SpelExpressionParser;
@@ -88,6 +88,15 @@ public class MethodInvokingMessageSourceTests {
source.receive(); 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") @SuppressWarnings("unused")
private static class TestBean { private static class TestBean {
@@ -102,6 +111,10 @@ public class MethodInvokingMessageSourceTests {
public void invalidMethodWithNoReturnValue() { public void invalidMethodWithNoReturnValue() {
} }
public Object nullReturningMethod() {
return null;
}
} }
} }