INT-3248 Suppress HeaderChannelRegistry Warning
Remove warning from BFCR if there is no HeaderChannelRegistry in the bean factory. Change the log to DEBUG and remove the stack trace. Instead, update the Exception message when a channel name can't be resolved to a channel to indicate that there is no registry. JIRA: https://jira.springsource.org/browse/INT-3248
This commit is contained in:
committed by
Artem Bilan
parent
5ed110c2a0
commit
b0c70ab519
@@ -32,7 +32,11 @@ import org.springframework.util.Assert;
|
||||
* <p>Will lookup Spring managed beans identified by bean name,
|
||||
* expecting them to be of type {@link MessageChannel}.
|
||||
*
|
||||
* Consults a {@link HeaderChannelRegistry}, if available, if the bean is not found.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @see org.springframework.beans.factory.BeanFactory
|
||||
*/
|
||||
public class BeanFactoryChannelResolver implements ChannelResolver, BeanFactoryAware {
|
||||
@@ -82,7 +86,7 @@ public class BeanFactoryChannelResolver implements ChannelResolver, BeanFactoryA
|
||||
HeaderChannelRegistry.class);
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.warn("No HeaderChannelRegistry found", e);
|
||||
logger.debug("No HeaderChannelRegistry found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +104,8 @@ public class BeanFactoryChannelResolver implements ChannelResolver, BeanFactoryA
|
||||
}
|
||||
}
|
||||
throw new ChannelResolutionException(
|
||||
"failed to look up MessageChannel bean with name '" + name + "'", e);
|
||||
"failed to look up MessageChannel with name '" + name + "' in the BeanFactory"
|
||||
+ (this.replyChannelRegistry == null ? " (and there is no HeaderChannelRegistry present)." : "."), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,11 +22,18 @@ import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
@@ -34,11 +41,15 @@ import org.springframework.integration.channel.DefaultHeaderChannelRegistry;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.support.channel.ChannelResolutionException;
|
||||
import org.springframework.integration.support.channel.HeaderChannelRegistry;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -143,6 +154,53 @@ public class HeaderChannelRegistryTests {
|
||||
registry.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBFCRWithRegistry() {
|
||||
BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver();
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
when(beanFactory.getBean(IntegrationContextUtils.INTEGRATION_HEADER_CHANNEL_REGISTRY_BEAN_NAME,
|
||||
HeaderChannelRegistry.class))
|
||||
.thenReturn(mock(HeaderChannelRegistry.class));
|
||||
doAnswer(new Answer<Object>(){
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
throw new NoSuchBeanDefinitionException("bar");
|
||||
}
|
||||
}).when(beanFactory).getBean("foo", MessageChannel.class);
|
||||
resolver.setBeanFactory(beanFactory);
|
||||
try {
|
||||
resolver.resolveChannelName("foo");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (ChannelResolutionException e){
|
||||
assertThat(e.getMessage(),
|
||||
Matchers.equalTo("failed to look up MessageChannel with name 'foo' in the BeanFactory."));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBFCRNoRegistry() {
|
||||
BeanFactoryChannelResolver resolver = new BeanFactoryChannelResolver();
|
||||
BeanFactory beanFactory = mock(BeanFactory.class);
|
||||
doAnswer(new Answer<Object>(){
|
||||
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
throw new NoSuchBeanDefinitionException("bar");
|
||||
}
|
||||
}).when(beanFactory).getBean("foo", MessageChannel.class);
|
||||
resolver.setBeanFactory(beanFactory);
|
||||
try {
|
||||
resolver.resolveChannelName("foo");
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (ChannelResolutionException e){
|
||||
assertThat(e.getMessage(),
|
||||
Matchers.equalTo("failed to look up MessageChannel with name 'foo' in the BeanFactory (and there is no HeaderChannelRegistry present)."));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Foo extends AbstractReplyProducingMessageHandler {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user