INT-1519, INT-957, INT-1515, Added support for propagating XML Validation exceptions with MessageRejectedException, added support for 'xml-validator' attribute, change XmlValidatingMessageSelector to be bootstrapped with either Resource/Schema or XmlValidator
This commit is contained in:
@@ -8,11 +8,29 @@
|
||||
http://www.springframework.org/schema/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.0.xsd">
|
||||
|
||||
|
||||
<int-xml:validating-filter id="filter"
|
||||
input-channel="inputChannel"
|
||||
<int-xml:validating-filter id="filterA"
|
||||
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"
|
||||
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/>
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.core.PollableChannel;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.xml.util.XmlTestUtil;
|
||||
@@ -42,21 +43,53 @@ public class XmlPayloadValidatingFilterParserTests {
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting>hello</greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannelA", MessageChannel.class);
|
||||
inputChannel.send(docMessage);
|
||||
assertNotNull(validChannel.receive(100));
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testInvalidMessage() throws Exception {
|
||||
public void testInvalidMessageWithDiscardChannel() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
PollableChannel invalidChannel = ac.getBean("invalidOutputChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannelA", MessageChannel.class);
|
||||
inputChannel.send(docMessage);
|
||||
assertNotNull(invalidChannel.receive(100));
|
||||
assertNull(validChannel.receive(100));
|
||||
}
|
||||
@Test(expected=MessageRejectedException.class)
|
||||
public void testInvalidMessageWithThrowException() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
PollableChannel invalidChannel = ac.getBean("invalidOutputChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannelB", MessageChannel.class);
|
||||
inputChannel.send(docMessage);
|
||||
assertNotNull(invalidChannel.receive(100));
|
||||
assertNull(validChannel.receive(100));
|
||||
}
|
||||
@Test
|
||||
public void testValidMessageWithValidator() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting>hello</greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannelC", MessageChannel.class);
|
||||
inputChannel.send(docMessage);
|
||||
assertNotNull(validChannel.receive(100));
|
||||
}
|
||||
@Test
|
||||
public void testInvalidMessageWithValidatorAndDiscardChannel() throws Exception {
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("XmlPayloadValidatingFilterParserTests-context.xml", this.getClass());
|
||||
Document doc = XmlTestUtil.getDocumentForString("<greeting><other/></greeting>");
|
||||
GenericMessage<Document> docMessage = new GenericMessage<Document>(doc);
|
||||
PollableChannel validChannel = ac.getBean("validOutputChannel", PollableChannel.class);
|
||||
PollableChannel invalidChannel = ac.getBean("invalidOutputChannel", PollableChannel.class);
|
||||
MessageChannel inputChannel = ac.getBean("inputChannelC", MessageChannel.class);
|
||||
inputChannel.send(docMessage);
|
||||
assertNotNull(invalidChannel.receive(100));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user