Combined commit from Gary and Mark for INT-2451
Added bean resolver to ContentEnricher INT-2451 Polishing - PR Review Comments Disallow bean resolution in the name expression for content enricher properties - the name expressions can only resolve to payload properties. Value expressions can resolve to beans and bean properties.
This commit is contained in:
committed by
Oleg Zhurakousky
parent
1d392e6ab2
commit
a77e5dac5a
@@ -20,7 +20,9 @@ import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.Lifecycle;
|
||||
import org.springframework.context.expression.BeanFactoryResolver;
|
||||
import org.springframework.context.expression.MapAccessor;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.SpelParserConfiguration;
|
||||
@@ -43,6 +45,7 @@ import org.springframework.util.ReflectionUtils;
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Gunnar Hillert
|
||||
* @author Gary Russell
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ContentEnricher extends AbstractReplyProducingMessageHandler implements Lifecycle {
|
||||
@@ -51,7 +54,9 @@ public class ContentEnricher extends AbstractReplyProducingMessageHandler implem
|
||||
|
||||
private final SpelExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true));
|
||||
|
||||
private final StandardEvaluationContext evaluationContext = new StandardEvaluationContext();
|
||||
private final StandardEvaluationContext sourceEvaluationContext = new StandardEvaluationContext();
|
||||
|
||||
private final StandardEvaluationContext targetEvaluationContext = new StandardEvaluationContext();
|
||||
|
||||
private volatile boolean shouldClonePayload = false;
|
||||
|
||||
@@ -192,7 +197,12 @@ public class ContentEnricher extends AbstractReplyProducingMessageHandler implem
|
||||
|
||||
this.gateway.afterPropertiesSet();
|
||||
}
|
||||
this.evaluationContext.addPropertyAccessor(new MapAccessor());
|
||||
this.sourceEvaluationContext.addPropertyAccessor(new MapAccessor());
|
||||
this.targetEvaluationContext.addPropertyAccessor(new MapAccessor());
|
||||
BeanFactory beanFactory = this.getBeanFactory();
|
||||
if (beanFactory != null) {
|
||||
this.sourceEvaluationContext.setBeanResolver(new BeanFactoryResolver(beanFactory));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -216,7 +226,7 @@ public class ContentEnricher extends AbstractReplyProducingMessageHandler implem
|
||||
actualRequestMessage = requestMessage;
|
||||
}
|
||||
else {
|
||||
final Object requestMessagePayload = this.requestPayloadExpression.getValue(this.evaluationContext, requestMessage);
|
||||
final Object requestMessagePayload = this.requestPayloadExpression.getValue(this.sourceEvaluationContext, requestMessage);
|
||||
actualRequestMessage = MessageBuilder.withPayload(requestMessagePayload)
|
||||
.copyHeaders(requestMessage.getHeaders()).build();
|
||||
}
|
||||
@@ -233,8 +243,8 @@ public class ContentEnricher extends AbstractReplyProducingMessageHandler implem
|
||||
for (Map.Entry<Expression, Expression> entry : this.propertyExpressions.entrySet()) {
|
||||
Expression propertyExpression = entry.getKey();
|
||||
Expression valueExpression = entry.getValue();
|
||||
Object value = valueExpression.getValue(this.evaluationContext, replyMessage);
|
||||
propertyExpression.setValue(this.evaluationContext, targetPayload, value);
|
||||
Object value = valueExpression.getValue(this.sourceEvaluationContext, replyMessage);
|
||||
propertyExpression.setValue(this.targetEvaluationContext, targetPayload, value);
|
||||
}
|
||||
return targetPayload;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user