INT-3599/INT-2042: Improve XPathMessageSplitter

JIRA: https://jira.spring.io/browse/INT-2042,
https://jira.spring.io/browse/INT-3599

* Expose `outputProperties` for the `XPathMessageSplitter`
* Add `iterator` mode for the `XPathMessageSplitter`

Address PR comments

Doc Polishing
This commit is contained in:
Artem Bilan
2015-04-14 21:30:39 +03:00
committed by Gary Russell
parent 8059566b9b
commit 256ff4c46f
9 changed files with 306 additions and 73 deletions

View File

@@ -1,20 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration/xml"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
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">
http://www.springframework.org/schema/integration/xml/spring-integration-xml.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<si:channel id="output">
<si:queue/>
</si:channel>
<xpath-splitter id="xpathSplitter" input-channel="input" apply-sequence="false" create-documents="true">
<util:properties id="outputProperties">
<beans:prop key="#{T (javax.xml.transform.OutputKeys).OMIT_XML_DECLARATION}">yes</beans:prop>
</util:properties>
<xpath-splitter id="xpathSplitter"
input-channel="input"
apply-sequence="false"
create-documents="true"
output-properties="outputProperties"
iterator="false">
<xpath-expression expression="/orders/order"/>
</xpath-splitter>

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.
@@ -18,6 +18,8 @@ package org.springframework.integration.xml.config;
import static org.junit.Assert.*;
import java.util.Properties;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -39,10 +41,15 @@ public class XPathSplitterParserTests {
@Autowired @Qualifier("xpathSplitter.handler")
private MessageHandler xpathSplitter;
@Autowired @Qualifier("outputProperties")
private Properties outputProperties;
@Test
public void testXpathSplitterConfig() {
assertTrue(TestUtils.getPropertyValue(this.xpathSplitter, "createDocuments", Boolean.class));
assertFalse(TestUtils.getPropertyValue(this.xpathSplitter, "applySequence", Boolean.class));
assertFalse(TestUtils.getPropertyValue(this.xpathSplitter, "iterator", Boolean.class));
assertSame(this.outputProperties, TestUtils.getPropertyValue(this.xpathSplitter, "outputProperties"));
assertEquals("/orders/order",
TestUtils.getPropertyValue(this.xpathSplitter,
"xpathExpression.xpathExpression.xpath.m_patternString",

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-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.
@@ -27,19 +27,18 @@ import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.integration.handler.ReplyRequiredException;
import org.springframework.integration.xml.util.XmlTestUtil;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.support.GenericMessage;
/**
* @author Jonas Partner
*/
public class XPathMessageSplitterTests {
private String splittingXPath = "/orders/order";
private XPathMessageSplitter splitter;
private QueueChannel replyChannel = new QueueChannel();
@@ -47,8 +46,10 @@ public class XPathMessageSplitterTests {
@Before
public void setUp(){
String splittingXPath = "/orders/order";
splitter = new XPathMessageSplitter(splittingXPath);
splitter.setOutputChannel(replyChannel);
splitter.setRequiresReply(true);
}
@@ -64,7 +65,7 @@ public class XPathMessageSplitterTests {
}
}
@Test(expected = MessagingException.class)
@Test(expected = ReplyRequiredException.class)
public void splitDocumentThatDoesNotMatch() throws Exception {
Document doc = XmlTestUtil.getDocumentForString("<wrongDocument/>");
splitter.handleMessage(new GenericMessage<Document>(doc));
@@ -95,7 +96,7 @@ public class XPathMessageSplitterTests {
}
}
@Test(expected = MessagingException.class)
@Test(expected = MessageHandlingException.class)
public void invalidPayloadType() {
splitter.handleMessage(new GenericMessage<Integer>(123));
}