INT-3902: XML: SmartLifecycle, Order Attributes

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

Polishing

Polishing - PR Comments

Introduce `RouterFactoryBean.setSendTimeout` and deprecate `setTimeout`
This commit is contained in:
Gary Russell
2016-01-06 13:22:48 -05:00
committed by Artem Bilan
parent 74cbc58698
commit d684dc4d0e
31 changed files with 487 additions and 143 deletions

View File

@@ -44,7 +44,7 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
private volatile String defaultOutputChannelName;
private volatile Long timeout;
private volatile Long sendTimeout;
private volatile Boolean resolutionRequired;
@@ -60,8 +60,17 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
this.defaultOutputChannelName = defaultOutputChannelName;
}
/**
* @param timeout the timeout.
* @deprecated in favor of {@link #setSendTimeout(Long)}.
*/
@Deprecated
public void setTimeout(Long timeout) {
this.timeout = timeout;
this.sendTimeout = timeout;
}
public void setSendTimeout(Long timeout) {
this.sendTimeout = timeout;
}
public void setResolutionRequired(Boolean resolutionRequired) {
@@ -121,8 +130,8 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
if (this.defaultOutputChannelName != null) {
router.setDefaultOutputChannelName(this.defaultOutputChannelName);
}
if (this.timeout != null) {
router.setTimeout(this.timeout);
if (this.sendTimeout != null) {
router.setSendTimeout(this.sendTimeout);
}
if (this.applySequence != null) {
router.setApplySequence(this.applySequence);
@@ -152,7 +161,7 @@ public class RouterFactoryBean extends AbstractStandardMessageHandlerFactoryBean
private boolean noRouterAttributesProvided() {
return this.channelMappings == null && this.defaultOutputChannel == null
&& this.timeout == null && this.resolutionRequired == null && this.applySequence == null
&& this.sendTimeout == null && this.resolutionRequired == null && this.applySequence == null
&& this.ignoreSendFailures == null;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -150,7 +150,7 @@ public abstract class AbstractMethodAnnotationPostProcessor<T extends Annotation
((AbstractMessageProducingHandler) handler).setSendTimeout(value);
}
else {
((AbstractMessageRouter) handler).setTimeout(value);
((AbstractMessageRouter) handler).setSendTimeout(value);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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,12 +26,14 @@ import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.RouterFactoryBean;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
/**
* Base parser for routers.
*
* @author Mark Fisher
* @author Gary Russell
*/
public abstract class AbstractRouterParser extends AbstractConsumerEndpointParser {
@@ -39,7 +41,12 @@ public abstract class AbstractRouterParser extends AbstractConsumerEndpointParse
protected final BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(RouterFactoryBean.class);
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "timeout");
if (StringUtils.hasText(element.getAttribute("timeout"))
&& StringUtils.hasText(element.getAttribute("send-timeout"))) {
parserContext.getReaderContext().error("Only one of 'timeout' and 'send-timeout' is allowed", element);
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "timeout", "sendTimeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-send-failures");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@@ -18,7 +18,6 @@ package org.springframework.integration.router;
import java.util.Collection;
import org.springframework.beans.BeansException;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.integration.channel.NullChannel;
@@ -30,7 +29,6 @@ import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.core.DestinationResolutionException;
import org.springframework.util.Assert;
/**
@@ -80,11 +78,23 @@ public abstract class AbstractMessageRouter extends AbstractMessageHandler {
* Set the timeout for sending a message to the resolved channel. By default, there is no timeout, meaning the send
* will block indefinitely.
* @param timeout The timeout.
* @deprecated in favor of {@link #setSendTimeout(long)}.
*/
@Deprecated
public void setTimeout(long timeout) {
this.messagingTemplate.setSendTimeout(timeout);
}
/**
* Set the timeout for sending a message to the resolved channel.
* By default, there is no timeout, meaning the send will block indefinitely.
* @param timeout The timeout.
* @since 4.3
*/
public void setSendTimeout(long timeout) {
this.messagingTemplate.setSendTimeout(timeout);
}
/**
* Specify whether send failures for one or more of the recipients should be ignored. By default this is
* <code>false</code> meaning that an Exception will be thrown whenever a send fails. To override this and suppress

View File

@@ -3394,8 +3394,21 @@
<xsd:annotation>
<xsd:documentation>
Specify the maximum amount of time in milliseconds to wait
when sending Messages to the target MessageChannels. By
default the send will block indefinitely.
when sending Messages to the target MessageChannels if blocking
is possible (e.g. a bounded queue channel that is currently full).
By default the send will block indefinitely.
DEPRECATED in favor of 'send-timeout' for consistency with other elements.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="send-timeout" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Specify the maximum amount of time in milliseconds to wait
when sending Messages to the target MessageChannels if blocking
is possible (e.g. a bounded queue channel that is currently full).
By default the send will block indefinitely.
Synonym for 'timeout' - only one can be supplied.
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@@ -115,7 +115,7 @@ public class RecipientListRouterTests {
channelB.setBeanName("channelB");
channelC.setBeanName("channelC");
RecipientListRouter router = new RecipientListRouter();
router.setTimeout(0);
router.setSendTimeout(0);
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);
@@ -145,7 +145,7 @@ public class RecipientListRouterTests {
channelB.setBeanName("channelB");
channelC.setBeanName("channelC");
RecipientListRouter router = new RecipientListRouter();
router.setTimeout(0);
router.setSendTimeout(0);
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);
@@ -177,7 +177,7 @@ public class RecipientListRouterTests {
channelB.setBeanName("channelB");
channelC.setBeanName("channelC");
RecipientListRouter router = new RecipientListRouter();
router.setTimeout(0);
router.setSendTimeout(0);
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);
@@ -212,7 +212,7 @@ public class RecipientListRouterTests {
channelC.setBeanName("channelC");
RecipientListRouter router = new RecipientListRouter();
router.setIgnoreSendFailures(true);
router.setTimeout(0);
router.setSendTimeout(0);
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);
@@ -242,7 +242,7 @@ public class RecipientListRouterTests {
channelC.setBeanName("channelC");
RecipientListRouter router = new RecipientListRouter();
router.setIgnoreSendFailures(true);
router.setTimeout(0);
router.setSendTimeout(0);
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);
@@ -272,7 +272,7 @@ public class RecipientListRouterTests {
channelC.setBeanName("channelC");
RecipientListRouter router = new RecipientListRouter();
router.setIgnoreSendFailures(true);
router.setTimeout(0);
router.setSendTimeout(0);
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2016 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.
@@ -17,6 +17,7 @@
package org.springframework.integration.xml.config;
import org.w3c.dom.Element;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.xml.AbstractTransformerParser;
@@ -38,8 +39,8 @@ public class MarshallingTransformerParser extends AbstractTransformerParser {
@Override
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String resultTransformer = element.getAttribute("result-transformer");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-type", "resultType");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-factory", "resultFactoryName");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-type", "resultType");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-factory", "resultFactoryName");
String marshaller = element.getAttribute("marshaller");
Assert.hasText(marshaller, "the 'marshaller' attribute is required");
builder.addConstructorArgReference(marshaller);

View File

@@ -33,13 +33,13 @@ import org.springframework.util.StringUtils;
/**
* Parser for the &lt;xpath-filter&gt; element.
*
*
* @author Mark Fisher
* @since 2.1
*/
public class XPathFilterParser extends AbstractConsumerEndpointParser {
private XPathExpressionParser xpathParser = new XPathExpressionParser();
private final XPathExpressionParser xpathParser = new XPathExpressionParser();
@Override
@@ -65,6 +65,7 @@ public class XPathFilterParser extends AbstractConsumerEndpointParser {
builder.addPropertyValue("targetObject", selectorBuilder.getBeanDefinition());
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "discard-channel");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "throw-exception-on-rejection");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
return builder;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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,6 +30,7 @@ import org.springframework.util.StringUtils;
/**
* @author Jonas Partner
* @author Artem Bilan
* @author Gary Russell
*/
public class XPathMessageSplitterParser extends AbstractConsumerEndpointParser {
@@ -55,6 +56,7 @@ public class XPathMessageSplitterParser extends AbstractConsumerEndpointParser {
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "iterator");
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "output-properties");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
return builder;
}

View File

@@ -16,7 +16,6 @@
package org.springframework.integration.xml.config;
import org.springframework.integration.xml.selector.XmlValidatingMessageSelector;
import org.w3c.dom.Element;
import org.springframework.beans.factory.BeanDefinitionStoreException;
@@ -25,6 +24,7 @@ import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.integration.config.FilterFactoryBean;
import org.springframework.integration.config.xml.AbstractConsumerEndpointParser;
import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
import org.springframework.integration.xml.selector.XmlValidatingMessageSelector;
import org.springframework.util.StringUtils;
/**
@@ -60,6 +60,7 @@ public class XmlPayloadValidatingFilterParser extends AbstractConsumerEndpointPa
}
IntegrationNamespaceUtils.setValueIfAttributeDefined(selectorBuilder, element, "throw-exception-on-rejection");
filterBuilder.addPropertyValue("targetObject", selectorBuilder.getBeanDefinition());
IntegrationNamespaceUtils.setValueIfAttributeDefined(filterBuilder, element, "send-timeout");
return filterBuilder;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
@@ -38,6 +38,7 @@ import org.springframework.util.xml.DomUtils;
* @author Oleg Zhurakousky
* @author Mike Bazos
* @author liujiong
* @author Gary Russell
*/
public class XsltPayloadTransformerParser extends AbstractTransformerParser {
@@ -51,7 +52,7 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser {
String xslResource = element.getAttribute("xsl-resource");
String xslTemplates = element.getAttribute("xsl-templates");
String resultTransformer = element.getAttribute("result-transformer");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-type");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-type");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "result-factory", "resultFactoryName");
String transformerFactoryClass = element.getAttribute("transformer-factory-class");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "xslt-param-headers");

View File

@@ -822,27 +822,6 @@
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="input-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.messaging.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="output-channel" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
Message Channel where you want accepted messages to be sent.
</xsd:documentation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.messaging.MessageChannel" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="discard-channel" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
@@ -856,6 +835,7 @@
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="throw-exception-on-rejection" type="xsd:boolean" default="false"/>
<xsd:attributeGroup ref="integration:inputOutputChannelGroup"/>
</xsd:complexType>
<xsd:complexType name="inputOutputEndpoint">
@@ -863,24 +843,7 @@
<xsd:element ref="integration:poller" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string"/>
<xsd:attribute name="input-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.messaging.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="output-channel" type="xsd:string">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.messaging.MessageChannel"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attributeGroup ref="integration:inputOutputChannelGroup"/>
</xsd:complexType>
<xsd:complexType name="paramType">

View File

@@ -14,6 +14,17 @@
<si:queue capacity="1"/>
</si:channel>
<si-xml:marshalling-transformer
id="parseOnly"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123"
input-channel="marshallingTransformerNoResultFactory"
output-channel="output"
marshaller="marshaller" />
<si:channel id="marshallingTransformerNoResultFactory"/>
<si-xml:marshalling-transformer
input-channel="marshallingTransformerNoResultFactory"
@@ -33,13 +44,13 @@
output-channel="output"
marshaller="marshaller"
result-type="DOMResult" />
<si:channel id="marshallingTransformerCustomResultFactory"/>
<si-xml:marshalling-transformer
input-channel="marshallingTransformerCustomResultFactory"
output-channel="output"
marshaller="marshaller"
result-factory="stubResultFactory" />
result-factory="stubResultFactory" />
<si:channel id="marshallingTransformerWithResultTransformer"/>
<si-xml:marshalling-transformer

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,10 +16,14 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
import javax.xml.transform.dom.DOMResult;
import org.hamcrest.Matchers;
@@ -28,17 +32,23 @@ import org.junit.Test;
import org.w3c.dom.Document;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.config.StubResultFactory.StubStringResult;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.util.MultiValueMap;
import org.springframework.xml.transform.StringResult;
/**
* @author Jonas Partner
* @author Mark Fisher
* @author Gary Russell
*/
public class MarshallingTransformerParserTests {
@@ -54,6 +64,20 @@ public class MarshallingTransformerParserTests {
}
@Test
public void testParse() throws Exception {
EventDrivenConsumer consumer = (EventDrivenConsumer) appContext.getBean("parseOnly");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
SmartLifecycleRoleController roleController = appContext.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
}
@Test
public void testDefault() throws Exception {
MessageChannel input = (MessageChannel) appContext.getBean("marshallingTransformerNoResultFactory");

View File

@@ -11,26 +11,36 @@
http://www.springframework.org/schema/integration/spring-integration.xsd">
<si:channel id="input" />
<si:channel id="pollableInput" >
<si:queue capacity="1"/>
</si:channel>
<si:channel id="output">
<si:queue capacity="1"/>
</si:channel>
<si-xml:unmarshalling-transformer id="parseOnly"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123"
input-channel="input"
output-channel="output"
unmarshaller="unmarshaller"/>
<si-xml:unmarshalling-transformer id="defaultUnmarshaller"
input-channel="input"
output-channel="output"
unmarshaller="unmarshaller"/>
<si-xml:unmarshalling-transformer id="unmrshallerWithPoller"
input-channel="pollableInput"
output-channel="output"
unmarshaller="unmarshaller">
<si:poller fixed-delay="500"/>
</si-xml:unmarshalling-transformer>
</si-xml:unmarshalling-transformer>
<bean id="unmarshaller" class="org.springframework.integration.xml.config.StubUnmarshaller"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,27 +16,38 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
import javax.xml.transform.dom.DOMSource;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.util.MultiValueMap;
import org.springframework.xml.transform.StringSource;
/**
* @author Jonas Partner
* @author Mark Fisher
* @author Gary Russell
*/
public class UnmarshallingTransformerParserTests {
@@ -53,6 +64,20 @@ public class UnmarshallingTransformerParserTests {
}
@Test
public void testParse() throws Exception {
EventDrivenConsumer consumer = (EventDrivenConsumer) appContext.getBean("parseOnly");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
SmartLifecycleRoleController roleController = appContext.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
}
@Test
public void testDefaultUnmarshall() throws Exception {
MessageChannel input = (MessageChannel) appContext.getBean("input");
@@ -88,7 +113,7 @@ public class UnmarshallingTransformerParserTests {
assertEquals("Wrong payload after unmarshalling", "unmarshalled", result.getPayload());
assertTrue("Wrong source passed to unmarshaller", unmarshaller.sourcesPassed.poll() instanceof DOMSource);
}
@Test
public void testPollingUnmarshall() throws Exception {
MessageChannel input = (MessageChannel) appContext.getBean("pollableInput");
@@ -100,9 +125,9 @@ public class UnmarshallingTransformerParserTests {
assertEquals("Wrong payload after unmarshalling", "unmarshalled", result.getPayload());
assertTrue("Wrong source passed to unmarshaller", unmarshaller.sourcesPassed.poll() instanceof StringSource);
}
@Test(expected = MessagingException.class)
public void testUnmarshallUnsupported() throws Exception {

View File

@@ -10,6 +10,16 @@
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<si-xml:xpath-filter id="parseOnly"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123"
input-channel="booleanFilterInput" discard-channel="booleanFilterRejections">
<si-xml:xpath-expression expression="/name"/>
</si-xml:xpath-filter>
<si-xml:xpath-filter id="booleanFilter" input-channel="booleanFilterInput" discard-channel="booleanFilterRejections">
<si-xml:xpath-expression expression="/name"/>
</si-xml:xpath-filter>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,40 +16,67 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.w3c.dom.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.w3c.dom.Document;
import org.springframework.util.MultiValueMap;
/**
* @author Mark Fisher
* @author Gary Russell
* @since 2.1
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class XPathFilterParserTests {
@Autowired
private ApplicationContext context;
@Test
public void testParse() throws Exception {
EventDrivenConsumer consumer = (EventDrivenConsumer) context.getBean("parseOnly");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
SmartLifecycleRoleController roleController = context.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
}
@Test
public void simpleStringExpressionBoolean() throws Exception {
MessageChannel inputChannel = context.getBean("booleanFilterInput", MessageChannel.class);
MessageChannel inputChannel = context.getBean("booleanFilterInput", MessageChannel.class);
QueueChannel replyChannel = new QueueChannel();
PollableChannel discardChannel = context.getBean("booleanFilterRejections", PollableChannel.class);
PollableChannel discardChannel = context.getBean("booleanFilterRejections", PollableChannel.class);
Message<?> shouldBeAccepted = MessageBuilder.withPayload("<name>outputOne</name>").setReplyChannel(replyChannel).build();
Message<?> shouldBeRejected = MessageBuilder.withPayload("<other>outputOne</other>").setReplyChannel(replyChannel).build();
inputChannel.send(shouldBeAccepted);
@@ -59,12 +86,12 @@ public class XPathFilterParserTests {
assertNull(replyChannel.receive(0));
assertNull(discardChannel.receive(0));
}
@Test
public void stringExpressionWithNamespaceBoolean() throws Exception {
MessageChannel inputChannel = context.getBean("booleanFilterWithNamespaceInput", MessageChannel.class);
MessageChannel inputChannel = context.getBean("booleanFilterWithNamespaceInput", MessageChannel.class);
QueueChannel replyChannel = new QueueChannel();
PollableChannel discardChannel = context.getBean("booleanFilterWithNamespaceRejections", PollableChannel.class);
PollableChannel discardChannel = context.getBean("booleanFilterWithNamespaceRejections", PollableChannel.class);
Document docToAccept = XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>");
Document docToReject = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
Message<?> shouldBeAccepted = MessageBuilder.withPayload(docToAccept).setReplyChannel(replyChannel).build();
@@ -79,9 +106,9 @@ public class XPathFilterParserTests {
@Test
public void stringExpressionWithNestedMapBoolean() throws Exception {
MessageChannel inputChannel = context.getBean("nestedNamespaceMapFilterInput", MessageChannel.class);
MessageChannel inputChannel = context.getBean("nestedNamespaceMapFilterInput", MessageChannel.class);
QueueChannel replyChannel = new QueueChannel();
PollableChannel discardChannel = context.getBean("nestedNamespaceMapFilterRejections", PollableChannel.class);
PollableChannel discardChannel = context.getBean("nestedNamespaceMapFilterRejections", PollableChannel.class);
Document docToAccept = XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>");
Document docToReject = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
Message<?> shouldBeAccepted = MessageBuilder.withPayload(docToAccept).setReplyChannel(replyChannel).build();
@@ -96,9 +123,9 @@ public class XPathFilterParserTests {
@Test
public void stringExpressionWithNamespaceString() throws Exception {
MessageChannel inputChannel = context.getBean("stringFilterWithNamespaceInput", MessageChannel.class);
MessageChannel inputChannel = context.getBean("stringFilterWithNamespaceInput", MessageChannel.class);
QueueChannel replyChannel = new QueueChannel();
PollableChannel discardChannel = context.getBean("stringFilterWithNamespaceRejections", PollableChannel.class);
PollableChannel discardChannel = context.getBean("stringFilterWithNamespaceRejections", PollableChannel.class);
Document docToAccept = XmlTestUtil.getDocumentForString("<ns1:name xmlns:ns1='www.example.org'>outputOne</ns1:name>");
Document docToReject = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
Message<?> shouldBeAccepted = MessageBuilder.withPayload(docToAccept).setReplyChannel(replyChannel).build();
@@ -113,9 +140,9 @@ public class XPathFilterParserTests {
@Test
public void stringExpressionIgnoresCase() throws Exception {
MessageChannel inputChannel = context.getBean("stringFilterIgnoresCaseInput", MessageChannel.class);
MessageChannel inputChannel = context.getBean("stringFilterIgnoresCaseInput", MessageChannel.class);
QueueChannel replyChannel = new QueueChannel();
PollableChannel discardChannel = context.getBean("stringFilterIgnoresCaseRejections", PollableChannel.class);
PollableChannel discardChannel = context.getBean("stringFilterIgnoresCaseRejections", PollableChannel.class);
Document docToAccept1 = XmlTestUtil.getDocumentForString("<name>OUTPUTONE</name>");
Document docToAccept2 = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
Document docToReject = XmlTestUtil.getDocumentForString("<name>outputTwo</name>");
@@ -134,9 +161,9 @@ public class XPathFilterParserTests {
@Test
public void stringExpressionRegex() throws Exception {
MessageChannel inputChannel = context.getBean("stringFilterRegexInput", MessageChannel.class);
MessageChannel inputChannel = context.getBean("stringFilterRegexInput", MessageChannel.class);
QueueChannel replyChannel = new QueueChannel();
PollableChannel discardChannel = context.getBean("stringFilterRegexRejections", PollableChannel.class);
PollableChannel discardChannel = context.getBean("stringFilterRegexRejections", PollableChannel.class);
Document docToAccept1 = XmlTestUtil.getDocumentForString("<name>aBcDeFgHiJk</name>");
Document docToAccept2 = XmlTestUtil.getDocumentForString("<name>xyz</name>");
Document docToReject = XmlTestUtil.getDocumentForString("<name>abc123</name>");

View File

@@ -13,9 +13,9 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<beans:prop key="booleanResult">BOOLEAN_RESULT</beans:prop>
<beans:prop key="stringResult">STRING_RESULT</beans:prop>
@@ -23,11 +23,21 @@
<beans:prop key="nodeResult">NODE_RESULT</beans:prop>
<beans:prop key="nodeListResult">NODE_LIST_RESULT</beans:prop>
</util:properties>
<si:channel id="output">
<si:queue/>
</si:channel>
<xpath-header-enricher id="parseOnly"
input-channel="input" output-channel="output"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123">
<header name="name" xpath-expression="/person/@name" />
</xpath-header-enricher>
<xpath-header-enricher input-channel="input" output-channel="output">
<header name="name" xpath-expression="/person/@name" />
<header name="age" xpath-expression="/person/@age" evaluation-type="${numberResult}" header-type="int"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,7 +16,10 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
@@ -28,22 +31,30 @@ import org.w3c.dom.Node;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.MultiValueMap;
/**
* @author Mark Fisher
* @author Artem Bilan
* @author Gary Russell
*
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class XPathHeaderEnricherParserTests {
@Autowired
@@ -58,6 +69,20 @@ public class XPathHeaderEnricherParserTests {
private final Message<?> message = MessageBuilder.withPayload("<person name='John Doe' age='42' married='true'/>").build();
@Test
public void testParse() throws Exception {
EventDrivenConsumer consumer = (EventDrivenConsumer) context.getBean("parseOnly");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
SmartLifecycleRoleController roleController = context.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
}
@Test
public void stringResultByDefault() {
Message<?> result = this.getResultMessage();

View File

@@ -17,23 +17,26 @@
package org.springframework.integration.xml.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.Test;
import org.w3c.dom.Document;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.w3c.dom.Document;
/**
* @author Jonas Partner
@@ -57,8 +60,14 @@ public class XPathMessageSplitterParserTests {
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper
.getTestAppContext(channelDefinitions
+ "<si-xml:xpath-splitter id='splitter' input-channel='test-input' output-channel='test-output'><si-xml:xpath-expression expression='//name'/></si-xml:xpath-splitter>");
+ "<si-xml:xpath-splitter id='splitter' "
+ "order='2' send-timeout='123' auto-startup='false' phase='-1' "
+ "input-channel='test-input' output-channel='test-output'><si-xml:xpath-expression expression='//name'/></si-xml:xpath-splitter>");
EventDrivenConsumer consumer = (EventDrivenConsumer) ctx.getBean("splitter");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
consumer.start();
ctx.getAutowireCapableBeanFactory().autowireBeanProperties(this, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE,
false);
@@ -98,7 +107,7 @@ public class XPathMessageSplitterParserTests {
Object documnetBuilderFactory = fieldAccessor.getPropertyValue("documentBuilderFactory");
assertTrue("DocumnetBuilderFactory was not expected stub ", documnetBuilderFactory instanceof DocumentBuilderFactory);
}
@Test
public void testXPathExpressionRef() throws Exception {
TestXmlApplicationContext ctx = TestXmlApplicationContextHelper

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,9 +16,14 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import java.util.List;
import org.junit.After;
import org.junit.Test;
@@ -29,12 +34,13 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.router.AbstractMappingMessageRouter;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.channel.BeanFactoryChannelResolver;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.DefaultXmlPayloadConverter;
import org.springframework.integration.xml.util.XmlTestUtil;
@@ -43,12 +49,14 @@ import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.util.MultiValueMap;
/**
* @author Jonas Partner
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Gary Russell
*/
@ContextConfiguration
public class XPathRouterParserTests {
@@ -84,6 +92,23 @@ public class XPathRouterParserTests {
}
}
@Test
public void testParse() throws Exception {
ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
EventDrivenConsumer consumer = (EventDrivenConsumer) context.getBean("parseOnly");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
SmartLifecycleRoleController roleController = context.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
context.close();
}
@Test
public void testSimpleStringExpression() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<name>outputOne</name>");
@@ -168,6 +193,7 @@ public class XPathRouterParserTests {
inputChannel.send(MessageBuilder.withPayload("<unrelated/>").build());
assertEquals("Wrong count of messages on default output channel",1, defaultOutput.getQueueSize());
}
@Test
public void testWithDynamicChanges() throws Exception {
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
@@ -187,7 +213,9 @@ public class XPathRouterParserTests {
inputChannel.send(docMessage);
assertNotNull(channelB.receive(10));
assertNull(channelA.receive(10));
ac.close();
}
@Test
public void testWithDynamicChangesWithExistingMappings() throws Exception {
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
@@ -207,6 +235,7 @@ public class XPathRouterParserTests {
inputChannel.send(docMessage);
assertNotNull(channelA.receive(10));
assertNull(channelB.receive(10));
ac.close();
}
@Test
@@ -230,7 +259,9 @@ public class XPathRouterParserTests {
inputChannel.send(docMessage);
assertNotNull(channelA.receive(10));
assertNotNull(channelB.receive(10));
ac.close();
}
@Test
public void testWithStringEvaluationType() throws Exception {
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("XPathRouterTests-context.xml", this.getClass());
@@ -240,6 +271,7 @@ public class XPathRouterParserTests {
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
inputChannel.send(docMessage);
assertNotNull(channelA.receive(10));
ac.close();
}
@Test
@@ -252,6 +284,7 @@ public class XPathRouterParserTests {
Message<?> result = channelZ.receive(0);
assertNotNull(result);
assertEquals("<name>channelA</name>", result.getPayload());
ac.close();
}

View File

@@ -7,6 +7,15 @@
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<int-xml:xpath-router id="parseOnly" input-channel="xpathRouterEmptyChannel"
order="2"
auto-startup="false"
role="foo"
send-timeout="123"
phase="-1">
<int-xml:xpath-expression expression="/name"/>
</int-xml:xpath-router>
<int-xml:xpath-router id="xpathRouterEmpty" input-channel="xpathRouterEmptyChannel">
<int-xml:xpath-expression expression="/name"/>
</int-xml:xpath-router>

View File

@@ -21,6 +21,11 @@
</util:properties>
<xpath-splitter id="xpathSplitter"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123"
input-channel="input"
apply-sequence="false"
create-documents="true"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2016 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.
@@ -16,34 +16,52 @@
package org.springframework.integration.xml.config;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
import java.util.Properties;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.SmartLifecycle;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.MessageHandler;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.MultiValueMap;
/**
* @author Artem Bilan
* @author Gary Russell
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class XPathSplitterParserTests {
@Autowired @Qualifier("xpathSplitter.handler")
private MessageHandler xpathSplitter;
@Autowired @Qualifier("xpathSplitter")
private EventDrivenConsumer consumer;
@Autowired @Qualifier("outputProperties")
private Properties outputProperties;
@Autowired
SmartLifecycleRoleController roleController;
@Test
public void testXpathSplitterConfig() {
assertTrue(TestUtils.getPropertyValue(this.xpathSplitter, "createDocuments", Boolean.class));
@@ -54,6 +72,14 @@ public class XPathSplitterParserTests {
TestUtils.getPropertyValue(this.xpathSplitter,
"xpathExpression.xpathExpression.xpath.m_patternString",
String.class));
assertEquals(2, TestUtils.getPropertyValue(xpathSplitter, "order"));
assertEquals(123L, TestUtils.getPropertyValue(xpathSplitter, "messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
}
}

View File

@@ -13,9 +13,9 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<beans:prop key="booleanResult">BOOLEAN_RESULT</beans:prop>
<beans:prop key="stringResult">STRING_RESULT</beans:prop>
@@ -23,11 +23,19 @@
<beans:prop key="nodeResult">NODE_RESULT</beans:prop>
<beans:prop key="nodeListResult">NODE_LIST_RESULT</beans:prop>
</util:properties>
<si:channel id="output">
<si:queue/>
</si:channel>
<xpath-transformer id="parseOnly"
input-channel="defaultInput" xpath-expression="/person/@name" output-channel="output"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123"/>
<xpath-transformer input-channel="defaultInput" xpath-expression="/person/@name" output-channel="output"/>
<xpath-transformer input-channel="numberInput" xpath-expression="/person/@age" evaluation-type="${numberResult}" output-channel="output"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,7 +16,10 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.io.StringReader;
@@ -33,21 +36,29 @@ import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.SmartLifecycle;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.XmlPayloadConverter;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.xml.XmlPayloadConverter;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.MultiValueMap;
import org.springframework.xml.xpath.NodeMapper;
/**
* @author Mark Fisher
* @author Gary Russell
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class XPathTransformerParserTests {
@Autowired
@@ -77,8 +88,25 @@ public class XPathTransformerParserTests {
@Autowired
private PollableChannel output;
@Autowired
private EventDrivenConsumer parseOnly;
@Autowired
SmartLifecycleRoleController roleController;
private final Message<?> message = MessageBuilder.withPayload("<person name='John Doe' age='42' married='true'/>").build();
@Test
public void testParse() throws Exception {
assertEquals(2, TestUtils.getPropertyValue(this.parseOnly, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(this.parseOnly, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(this.parseOnly, "phase"));
assertFalse(TestUtils.getPropertyValue(this.parseOnly, "autoStartup", Boolean.class));
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) this.parseOnly));
}
@Test
public void stringResultByDefault() {
@@ -139,6 +167,7 @@ public class XPathTransformerParserTests {
@SuppressWarnings("unused")
private static class TestNodeMapper implements NodeMapper<Object> {
@Override
public Object mapNode(Node node, int nodeNum) throws DOMException {
return node.getTextContent() + "-mapped";
}
@@ -148,10 +177,12 @@ public class XPathTransformerParserTests {
@SuppressWarnings("unused")
private static class TestXmlPayloadConverter implements XmlPayloadConverter {
@Override
public Source convertToSource(Object object) {
throw new UnsupportedOperationException();
}
@Override
public Node convertToNode(Object object) {
try {
return DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(
@@ -162,6 +193,7 @@ public class XPathTransformerParserTests {
}
}
@Override
public Document convertToDocument(Object object) {
throw new UnsupportedOperationException();
}

View File

@@ -12,42 +12,54 @@
http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<prop key="xmlSchema">xml-schema</prop>
</util:properties>
<int-xml:validating-filter id="filterA"
<int-xml:validating-filter id="parseOnly"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123"
schema-type="${xmlSchema}"
input-channel="inputChannelA"
output-channel="validOutputChannel"
discard-channel="invalidOutputChannel"
schema-location="org/springframework/integration/xml/config/validationTestsSchema.xsd"/>
<int-xml:validating-filter id="filterB"
<int-xml:validating-filter id="filterA"
schema-type="${xmlSchema}"
input-channel="inputChannelA"
output-channel="validOutputChannel"
discard-channel="invalidOutputChannel"
schema-location="org/springframework/integration/xml/config/validationTestsSchema.xsd"/>
<int-xml:validating-filter id="filterB"
input-channel="inputChannelB"
output-channel="validOutputChannel"
discard-channel="invalidOutputChannel"
throw-exception-on-rejection="true"
schema-location="org/springframework/integration/xml/config/validationTestsSchema.xsd"/>
<int-xml:validating-filter id="filterC"
<int-xml:validating-filter id="filterC"
input-channel="inputChannelC"
output-channel="validOutputChannel"
discard-channel="invalidOutputChannel"
xml-validator="xmlValidator"/>
<bean id="xmlValidator" class="org.springframework.xml.validation.XmlValidatorFactory" factory-method="createValidator">
<constructor-arg value="classpath:org/springframework/integration/xml/config/validationTestsSchema.xsd"/>
<constructor-arg value="http://www.w3.org/2001/XMLSchema"/>
</bean>
<int:channel id="validOutputChannel">
<int:queue/>
</int:channel>
<int:channel id="invalidOutputChannel">
<int:queue/>
</int:channel>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,11 +16,16 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,7 +33,11 @@ import org.w3c.dom.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.AggregatedXmlMessageValidationException;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.messaging.MessageChannel;
@@ -37,12 +46,14 @@ import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.MultiValueMap;
/**
* @author Jonas Partner
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Artem Bilan
* @author Gary Russell
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -52,6 +63,20 @@ public class XmlPayloadValidatingFilterParserTests {
@Autowired
private ApplicationContext ac;
@Test
public void testParse() throws Exception {
EventDrivenConsumer consumer = (EventDrivenConsumer) ac.getBean("parseOnly");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
SmartLifecycleRoleController roleController = ac.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
}
@Test
public void testValidMessage() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<greeting>hello</greeting>");
@@ -61,6 +86,7 @@ public class XmlPayloadValidatingFilterParserTests {
inputChannel.send(docMessage);
assertNotNull(validChannel.receive(100));
}
@Test
public void testInvalidMessageWithDiscardChannel() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");

View File

@@ -13,34 +13,44 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration/xml
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd">
<context:property-placeholder properties-ref="props"/>
<util:properties id="props">
<prop key="domResult">DOMResult</prop>
<prop key="stringResult">StringResult</prop>
</util:properties>
<si:channel id="output">
<si:queue capacity="1"/>
</si:channel>
<si:channel id="withResourceIn"/>
<si-xml:xslt-transformer id="parseOnly"
order="2"
auto-startup="false"
phase="-1"
role="foo"
send-timeout="123"
input-channel="withResourceIn"
output-channel="output"
xsl-resource="org/springframework/integration/xml/config/test.xsl"/>
<si-xml:xslt-transformer id="xsltTransformerWithResource"
input-channel="withResourceIn"
output-channel="output"
xsl-resource="org/springframework/integration/xml/config/test.xsl"/>
<si:channel id="withTemplatesIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplates"
input-channel="withTemplatesIn"
output-channel="output"
xsl-templates="templates"/>
<si:channel id="withTemplatesAndResultTransformerIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndResultTransformer"
input-channel="withTemplatesAndResultTransformerIn"
output-channel="output"
@@ -48,7 +58,7 @@
result-transformer="resultTransformer"/>
<si:channel id="withTemplatesAndResultFactoryIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndResultFactory"
input-channel="withTemplatesAndResultFactoryIn"
output-channel="output"
@@ -56,7 +66,7 @@
result-factory="stubResultFactory"/>
<si:channel id="withTemplatesAndStringResultTypeIn"/>
<si-xml:xslt-transformer id="xsltTransformerWithTemplatesAndStringResultType"
input-channel="withTemplatesAndStringResultTypeIn"
output-channel="output"

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
@@ -16,10 +16,15 @@
package org.springframework.integration.xml.config;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.List;
import javax.xml.transform.dom.DOMResult;
import org.junit.Assert;
@@ -28,22 +33,27 @@ import org.junit.Test;
import org.w3c.dom.Document;
import org.springframework.context.ApplicationContext;
import org.springframework.context.SmartLifecycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.SmartLifecycleRoleController;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.xml.config.StubResultFactory.StubStringResult;
import org.springframework.integration.xml.transformer.CustomTestResultFactory;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.util.MultiValueMap;
import org.springframework.xml.transform.StringResult;
/**
* @author Jonas Partner
* @author Mark Fisher
* @author Gunnar Hillert
* @author Gary Russell
*/
public class XsltPayloadTransformerParserTests {
@@ -59,6 +69,20 @@ public class XsltPayloadTransformerParserTests {
output = (PollableChannel) applicationContext.getBean("output");
}
@Test
public void testParse() throws Exception {
EventDrivenConsumer consumer = (EventDrivenConsumer) applicationContext.getBean("parseOnly");
assertEquals(2, TestUtils.getPropertyValue(consumer, "handler.order"));
assertEquals(123L, TestUtils.getPropertyValue(consumer, "handler.messagingTemplate.sendTimeout"));
assertEquals(-1, TestUtils.getPropertyValue(consumer, "phase"));
assertFalse(TestUtils.getPropertyValue(consumer, "autoStartup", Boolean.class));
SmartLifecycleRoleController roleController = applicationContext.getBean(SmartLifecycleRoleController.class);
@SuppressWarnings("unchecked")
List<SmartLifecycle> list = (List<SmartLifecycle>) TestUtils.getPropertyValue(roleController, "lifecycles",
MultiValueMap.class).get("foo");
assertThat(list, contains((SmartLifecycle) consumer));
}
@Test
public void testWithResourceProvided() throws Exception {
MessageChannel input = (MessageChannel) applicationContext.getBean("withResourceIn");