INT-3749: Get rid of IECA logic

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

Since `IntegrationEvaluationContextAware` isn't so "context-free" resource like `BeanFactory`
 and `ApplicationContext`, but just a specific bean in the context, we can't follow with `BeanPostProcessor` logic - bad architecture by level of responsibility.
 Therefore we should follow with standard Dependency Injection mechanism to retrieve `evaluationContext` for the particular component.

 Since we can't rely on the `@Autowired` because SI can be used from the raw XML configuration,
 we use utility method instead. The pattern to get the proper `integrationEvaluationContext` is:
 ```
 @Override
 protected void onInit() throws Exception {
 		super.onInit();
 		this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
 }
 ```
This commit is contained in:
Artem Bilan
2015-06-23 20:42:34 -04:00
committed by Gary Russell
parent fe98cbc4e0
commit 3392d4e1ab
26 changed files with 272 additions and 253 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 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.
@@ -23,11 +23,12 @@ import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.expression.IntegrationEvaluationContextAware;
import org.springframework.integration.expression.ExpressionUtils;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
@@ -35,7 +36,7 @@ import org.springframework.util.Assert;
* @author Artem Bilan
* @since 4.0
*/
public class ExpressionArgumentsStrategy implements ArgumentsStrategy, IntegrationEvaluationContextAware, BeanFactoryAware {
public class ExpressionArgumentsStrategy implements ArgumentsStrategy, BeanFactoryAware, InitializingBean {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
@@ -63,14 +64,13 @@ public class ExpressionArgumentsStrategy implements ArgumentsStrategy, Integrati
}
@Override
public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) {
Assert.notNull(evaluationContext, "'evaluationContext' must not be null");
this.evaluationContext = evaluationContext;
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
public void afterPropertiesSet() throws Exception {
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.beanFactory);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-2015 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.
@@ -26,7 +26,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.expression.IntegrationEvaluationContextAware;
import org.springframework.integration.expression.ExpressionUtils;
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
import org.springframework.integration.redis.support.RedisHeaders;
import org.springframework.messaging.Message;
@@ -39,8 +39,7 @@ import org.springframework.util.ObjectUtils;
* @author Artem Bilan
* @since 4.0
*/
public class RedisOutboundGateway extends AbstractReplyProducingMessageHandler
implements IntegrationEvaluationContextAware {
public class RedisOutboundGateway extends AbstractReplyProducingMessageHandler {
private static final SpelExpressionParser PARSER = new SpelExpressionParser();
@@ -66,12 +65,6 @@ public class RedisOutboundGateway extends AbstractReplyProducingMessageHandler
this.redisTemplate.afterPropertiesSet();
}
@Override
public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) {
Assert.notNull(evaluationContext, "'evaluationContext' must not be null");
this.evaluationContext = evaluationContext;
}
@SuppressWarnings("unchecked")
public void setArgumentsSerializer(RedisSerializer<?> serializer) {
Assert.notNull(serializer, "'serializer' must not be null");
@@ -106,6 +99,12 @@ public class RedisOutboundGateway extends AbstractReplyProducingMessageHandler
return "redis:outbound-gateway";
}
@Override
protected void doInit() {
super.doInit();
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
}
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
final String command = this.commandExpression.getValue(this.evaluationContext, requestMessage, String.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007-2014 the original author or authors
* Copyright 2007-2015 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.
@@ -24,7 +24,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.expression.IntegrationEvaluationContextAware;
import org.springframework.integration.expression.ExpressionUtils;
import org.springframework.integration.handler.AbstractMessageHandler;
import org.springframework.integration.support.converter.SimpleMessageConverter;
import org.springframework.messaging.Message;
@@ -36,7 +36,7 @@ import org.springframework.util.Assert;
* @author Artem Bilan
* @since 2.1
*/
public class RedisPublishingMessageHandler extends AbstractMessageHandler implements IntegrationEvaluationContextAware {
public class RedisPublishingMessageHandler extends AbstractMessageHandler {
private final RedisTemplate<?, ?> template;
@@ -56,11 +56,6 @@ public class RedisPublishingMessageHandler extends AbstractMessageHandler implem
this.template.afterPropertiesSet();
}
@Override
public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) {
this.evaluationContext = evaluationContext;
}
public void setSerializer(RedisSerializer<?> serializer) {
Assert.notNull(serializer, "'serializer' must not be null");
this.serializer = serializer;
@@ -101,8 +96,9 @@ public class RedisPublishingMessageHandler extends AbstractMessageHandler implem
protected void onInit() throws Exception {
Assert.notNull(topicExpression, "'topicExpression' must not be null.");
if (this.messageConverter instanceof BeanFactoryAware) {
((BeanFactoryAware) this.messageConverter).setBeanFactory(this.getBeanFactory());
((BeanFactoryAware) this.messageConverter).setBeanFactory(getBeanFactory());
}
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors
* Copyright 2013-2015 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.
@@ -24,7 +24,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.integration.expression.IntegrationEvaluationContextAware;
import org.springframework.integration.expression.ExpressionUtils;
import org.springframework.integration.handler.AbstractMessageHandler;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
@@ -35,7 +35,7 @@ import org.springframework.util.Assert;
* @author Artem Bilan
* @since 3.0
*/
public class RedisQueueOutboundChannelAdapter extends AbstractMessageHandler implements IntegrationEvaluationContextAware {
public class RedisQueueOutboundChannelAdapter extends AbstractMessageHandler {
private final RedisSerializer<String> stringSerializer = new StringRedisSerializer();
@@ -67,11 +67,6 @@ public class RedisQueueOutboundChannelAdapter extends AbstractMessageHandler imp
this.template.afterPropertiesSet();
}
@Override
public void setIntegrationEvaluationContext(EvaluationContext evaluationContext) {
this.evaluationContext = evaluationContext;
}
public void setExtractPayload(boolean extractPayload) {
this.extractPayload = extractPayload;
}
@@ -87,6 +82,12 @@ public class RedisQueueOutboundChannelAdapter extends AbstractMessageHandler imp
return "redis:queue-outbound-channel-adapter";
}
@Override
protected void onInit() throws Exception {
super.onInit();
this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
}
@Override
@SuppressWarnings("unchecked")
protected void handleMessageInternal(Message<?> message) throws Exception {