INT-3314: Fix BeanFactory Population for SAH
JIRA: https://jira.springsource.org/browse/INT-3314 Add to `ServiceActivatingHandler` `beanFactory` population code for the `MessageProcessor` delegate INT-3314: Populate `BF` to `HValueMProcessor`s Make `XPathExpressionEvaluatingHeaderValueMessageProcessor` as `public` INT-3314: Populate `BF` to `HE.messageProcessor` INT-3314: Add `BF` `NPE` protection INT-3314 XPath Header Enricher Test Add a test that verifies the `BeanFactoryTypeConverter` is used (convert to a TimeZone object).
This commit is contained in:
committed by
Gary Russell
parent
267fc5b3db
commit
7adc9537b6
@@ -23,7 +23,6 @@ import org.w3c.dom.NodeList;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedMap;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.IntegrationConfigUtils;
|
||||
import org.springframework.integration.config.xml.AbstractTransformerParser;
|
||||
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.xml.transformer.XPathHeaderEnricher;
|
||||
@@ -61,8 +60,8 @@ public class XPathHeaderEnricherParser extends AbstractTransformerParser {
|
||||
Element headerElement = (Element) node;
|
||||
String elementName = node.getLocalName();
|
||||
if ("header".equals(elementName)) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(IntegrationConfigUtils.BASE_PACKAGE
|
||||
+ ".xml.transformer.XPathHeaderEnricher$XPathExpressionEvaluatingHeaderValueMessageProcessor");
|
||||
BeanDefinitionBuilder builder =
|
||||
BeanDefinitionBuilder.genericBeanDefinition(XPathHeaderEnricher.XPathExpressionEvaluatingHeaderValueMessageProcessor.class);
|
||||
String expressionString = headerElement.getAttribute("xpath-expression");
|
||||
String expressionRef = headerElement.getAttribute("xpath-expression-ref");
|
||||
boolean isExpressionString = StringUtils.hasText(expressionString);
|
||||
|
||||
@@ -25,11 +25,10 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.expression.TypeConverter;
|
||||
import org.springframework.expression.spel.support.StandardTypeConverter;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.transformer.HeaderEnricher;
|
||||
import org.springframework.integration.transformer.support.HeaderValueMessageProcessor;
|
||||
import org.springframework.integration.util.BeanFactoryTypeConverter;
|
||||
import org.springframework.integration.xml.DefaultXmlPayloadConverter;
|
||||
import org.springframework.integration.xml.XmlPayloadConverter;
|
||||
import org.springframework.integration.xml.xpath.XPathEvaluationType;
|
||||
@@ -61,15 +60,15 @@ public class XPathHeaderEnricher extends HeaderEnricher {
|
||||
}
|
||||
|
||||
|
||||
static class XPathExpressionEvaluatingHeaderValueMessageProcessor implements HeaderValueMessageProcessor<Object>,
|
||||
public static class XPathExpressionEvaluatingHeaderValueMessageProcessor implements HeaderValueMessageProcessor<Object>,
|
||||
BeanFactoryAware {
|
||||
|
||||
private TypeConverter typeConverter = new StandardTypeConverter();
|
||||
private static final XmlPayloadConverter converter = new DefaultXmlPayloadConverter();
|
||||
|
||||
private final BeanFactoryTypeConverter typeConverter = new BeanFactoryTypeConverter();
|
||||
|
||||
private final XPathExpression expression;
|
||||
|
||||
private volatile XmlPayloadConverter converter = new DefaultXmlPayloadConverter();
|
||||
|
||||
private volatile XPathEvaluationType evaluationType = XPathEvaluationType.STRING_RESULT;
|
||||
|
||||
private volatile TypeDescriptor headerTypeDescriptor;
|
||||
@@ -109,7 +108,7 @@ public class XPathHeaderEnricher extends HeaderEnricher {
|
||||
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
|
||||
ConversionService conversionService = IntegrationContextUtils.getConversionService(beanFactory);
|
||||
if (conversionService != null) {
|
||||
this.typeConverter = new StandardTypeConverter(conversionService);
|
||||
this.typeConverter.setConversionService(conversionService);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
@@ -22,19 +22,20 @@ import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.xml.transformer.XPathHeaderEnricher;
|
||||
import org.springframework.integration.xml.transformer.XPathHeaderEnricher.XPathExpressionEvaluatingHeaderValueMessageProcessor;
|
||||
import org.springframework.integration.xml.xpath.XPathEvaluationType;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
* @author David Turanski
|
||||
* @author Gary Russell
|
||||
* @since 2.0
|
||||
*/
|
||||
public class XPathHeaderEnricherTests {
|
||||
@@ -53,6 +54,21 @@ public class XPathHeaderEnricherTests {
|
||||
assertEquals("Wrong value for element two expression", "2", headers.get("two"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertedEvaluation() {
|
||||
Map<String, XPathExpressionEvaluatingHeaderValueMessageProcessor> expressionMap =
|
||||
new HashMap<String, XPathExpressionEvaluatingHeaderValueMessageProcessor>();
|
||||
XPathExpressionEvaluatingHeaderValueMessageProcessor processor = new XPathExpressionEvaluatingHeaderValueMessageProcessor(
|
||||
"/root/elementOne");
|
||||
processor.setHeaderType(TimeZone.class);
|
||||
expressionMap.put("one", processor);
|
||||
String docAsString = "<root><elementOne>America/New_York</elementOne></root>";
|
||||
XPathHeaderEnricher enricher = new XPathHeaderEnricher(expressionMap);
|
||||
Message<?> result = enricher.transform(MessageBuilder.withPayload(docAsString).build());
|
||||
MessageHeaders headers = result.getHeaders();
|
||||
assertEquals("Wrong value for element one expression", TimeZone.getTimeZone("America/New_York"), headers.get("one"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullValuesSkippedByDefault() {
|
||||
Map<String, XPathExpressionEvaluatingHeaderValueMessageProcessor> expressionMap
|
||||
|
||||
Reference in New Issue
Block a user