INT-3404: Remove MProducer from AIFileSMS

JIRA: https://jira.spring.io/browse/INT-3404

Previously, `AbstractInboundFileSynchronizingMessageSource` implemented both `MessageProducer` and `MessageSource`.
The `MessageProducer` is really redundant and confusing.
Also, it might produce some side-effects when using JavaConfig.

Provide some other simple but important fix for all `AbstractMessageSource` implementation to invoke `super.afterPropertiesSet()`

Polishing

Add mock bean factory to failing tests.

Revert state assertions in AbstractInboundFileSynchronizingMessageSource;
the fields are state, not arguments, at the time they are being
asserted.
This commit is contained in:
Artem Bilan
2014-07-01 17:21:22 +03:00
committed by Gary Russell
parent 1ca631e2c8
commit db8b164425
5 changed files with 31 additions and 20 deletions

View File

@@ -65,7 +65,8 @@ public class MethodInvokingMessageSource extends AbstractMessageSource<Object> i
}
@Override
public void afterPropertiesSet() {
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
synchronized (this.initializationMonitor) {
if (this.initialized) {
return;

View File

@@ -41,7 +41,8 @@ import org.springframework.util.ObjectUtils;
* @author Gary Russell
* @since 2.1
*/
public class ResourceRetrievingMessageSource extends AbstractMessageSource<Resource[]> implements ApplicationContextAware, InitializingBean {
public class ResourceRetrievingMessageSource extends AbstractMessageSource<Resource[]>
implements ApplicationContextAware, InitializingBean {
private final String pattern;
@@ -78,11 +79,10 @@ public class ResourceRetrievingMessageSource extends AbstractMessageSource<Resou
@Override
public void afterPropertiesSet() {
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
if (this.patternResolver == null) {
if (this.applicationContext instanceof ResourcePatternResolver) {
this.patternResolver = this.applicationContext;
}
this.patternResolver = this.applicationContext;
}
Assert.notNull(this.patternResolver, "no 'patternResolver' available");
}

View File

@@ -44,7 +44,7 @@ import org.springframework.messaging.MessageHandlingException;
*/
public abstract class AbstractExpressionEvaluator implements BeanFactoryAware, InitializingBean {
private final Log logger = LogFactory.getLog(this.getClass());
protected final Log logger = LogFactory.getLog(this.getClass());
private volatile StandardEvaluationContext evaluationContext;
@@ -71,6 +71,10 @@ public abstract class AbstractExpressionEvaluator implements BeanFactoryAware, I
}
}
protected BeanFactory getBeanFactory() {
return beanFactory;
}
public void setConversionService(ConversionService conversionService) {
if (conversionService != null) {
this.typeConverter.setConversionService(conversionService);
@@ -136,15 +140,16 @@ public abstract class AbstractExpressionEvaluator implements BeanFactoryAware, I
}
protected Object evaluateExpression(String expression, Object input) {
return this.evaluateExpression(expression, input, (Class<?>) null);
return this.evaluateExpression(expression, input, null);
}
protected <T> T evaluateExpression(String expression, Object input, Class<T> expectedType) {
return this.expressionParser.parseExpression(expression).getValue(this.getEvaluationContext(), input, expectedType);
return this.expressionParser.parseExpression(expression)
.getValue(this.getEvaluationContext(), input, expectedType);
}
protected Object evaluateExpression(Expression expression, Object input) {
return this.evaluateExpression(expression, input, (Class<?>) null);
return this.evaluateExpression(expression, input, null);
}
protected <T> T evaluateExpression(Expression expression, Class<T> expectedType) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 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,9 +30,9 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.endpoint.MethodInvokingMessageSource;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.integration.endpoint.MethodInvokingMessageSource;
/**
* @author Mark Fisher
@@ -43,6 +43,7 @@ public class MethodInvokingMessageSourceTests {
@Test
public void testValidMethod() {
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("validMethod");
Message<?> result = source.receive();
@@ -72,6 +73,7 @@ public class MethodInvokingMessageSourceTests {
@Test(expected=MessagingException.class)
public void testNoMatchingMethodName() {
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("noMatchingMethod");
source.receive();
@@ -80,6 +82,7 @@ public class MethodInvokingMessageSourceTests {
@Test(expected=MessagingException.class)
public void testInvalidMethodWithArg() {
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("invalidMethodWithArg");
source.receive();
@@ -88,6 +91,7 @@ public class MethodInvokingMessageSourceTests {
@Test(expected=MessagingException.class)
public void testInvalidMethodWithNoReturnValue() {
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("invalidMethodWithNoReturnValue");
source.receive();
@@ -96,6 +100,7 @@ public class MethodInvokingMessageSourceTests {
@Test
public void testNullReturningMethodReturnsNullMessage() {
MethodInvokingMessageSource source = new MethodInvokingMessageSource();
source.setBeanFactory(mock(BeanFactory.class));
source.setObject(new TestBean());
source.setMethodName("nullReturningMethod");
Message<?> message = source.receive();

View File

@@ -22,8 +22,7 @@ import java.util.Arrays;
import java.util.Comparator;
import java.util.regex.Pattern;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.endpoint.MessageProducerSupport;
import org.springframework.integration.endpoint.AbstractMessageSource;
import org.springframework.integration.file.FileReadingMessageSource;
import org.springframework.integration.file.filters.AcceptOnceFileListFilter;
import org.springframework.integration.file.filters.CompositeFileListFilter;
@@ -55,8 +54,7 @@ import org.springframework.util.Assert;
* @author Oleg Zhurakousky
* @author Gary Russell
*/
public abstract class AbstractInboundFileSynchronizingMessageSource<F> extends MessageProducerSupport
implements MessageSource<File> {
public abstract class AbstractInboundFileSynchronizingMessageSource<F> extends AbstractMessageSource<File> {
/**
* Should the endpoint attempt to create the local directory? True by default.
@@ -86,7 +84,8 @@ public abstract class AbstractInboundFileSynchronizingMessageSource<F> extends M
this(synchronizer, null);
}
public AbstractInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<F> synchronizer, Comparator<File> comparator) {
public AbstractInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer<F> synchronizer,
Comparator<File> comparator) {
Assert.notNull(synchronizer, "synchronizer must not be null");
this.synchronizer = synchronizer;
if (comparator == null){
@@ -122,7 +121,8 @@ public abstract class AbstractInboundFileSynchronizingMessageSource<F> extends M
}
@Override
protected void onInit() {
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
Assert.notNull(this.localDirectory, "localDirectory must not be null");
try {
if (!this.localDirectory.exists()) {
@@ -149,7 +149,7 @@ public abstract class AbstractInboundFileSynchronizingMessageSource<F> extends M
}
catch (Exception e) {
throw new MessagingException(
"Failure during initialization of MessageSource for: " + this.getComponentType(), e);
"Failure during initialization of MessageSource for: " + this.getClass(), e);
}
}
@@ -159,7 +159,7 @@ public abstract class AbstractInboundFileSynchronizingMessageSource<F> extends M
* Then, it polls the file source again and returns the result, whether or not it is null.
*/
@Override
public final Message<File> receive() {
public final Message<File> doReceive() {
Assert.state(this.fileSource != null, "fileSource must not be null");
Assert.state(this.synchronizer != null, "synchronizer must not be null");
Message<File> message = this.fileSource.receive();