Moved GatewayParser, AbstractTransformerParser, and SimpleHeaderEnricherParser into org.springframework.integration.config to avoid dependency cycles.
This commit is contained in:
@@ -20,8 +20,8 @@ import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.AbstractTransformerParser;
|
||||
import org.springframework.integration.transformer.Transformer;
|
||||
import org.springframework.integration.transformer.config.AbstractTransformerParser;
|
||||
import org.springframework.integration.xml.transformer.XmlPayloadMarshallingTransformer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -42,10 +42,10 @@ public class XmlMarshallingTransformerParser extends AbstractTransformerParser {
|
||||
|
||||
@Override
|
||||
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
String resultTransformer = element.getAttribute("result-transformer");
|
||||
String resultFactory = element.getAttribute("result-factory");
|
||||
String resultType = element.getAttribute("result-type");
|
||||
String marshaller = element.getAttribute("marshaller");
|
||||
String resultTransformer = element.getAttribute("result-transformer");
|
||||
Assert.hasText(marshaller, "the 'marshaller' attribute is required");
|
||||
builder.addConstructorArgReference(marshaller);
|
||||
if (StringUtils.hasText(resultTransformer)) {
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.AbstractTransformerParser;
|
||||
import org.springframework.integration.transformer.Transformer;
|
||||
import org.springframework.integration.transformer.config.AbstractTransformerParser;
|
||||
import org.springframework.integration.xml.transformer.XmlPayloadUnmarshallingTransformer;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ import org.w3c.dom.Element;
|
||||
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.integration.config.AbstractTransformerParser;
|
||||
import org.springframework.integration.config.IntegrationNamespaceUtils;
|
||||
import org.springframework.integration.transformer.Transformer;
|
||||
import org.springframework.integration.transformer.config.AbstractTransformerParser;
|
||||
import org.springframework.integration.xml.transformer.XsltPayloadTransformer;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -47,24 +48,20 @@ public class XsltPayloadTransformerParser extends AbstractTransformerParser {
|
||||
String resultTransformer = element.getAttribute("result-transformer");
|
||||
String resultFactory = element.getAttribute("result-factory");
|
||||
String resultType = element.getAttribute("result-type");
|
||||
boolean bothHaveText = StringUtils.hasText(xslResource) && StringUtils.hasText(xslTemplates);
|
||||
boolean oneHasText = StringUtils.hasText(xslResource) || StringUtils.hasText(xslTemplates);
|
||||
Assert.state(!bothHaveText && oneHasText, "Exactly one of 'xsl-resource' or 'xsl-templates' is required.");
|
||||
Assert.isTrue(StringUtils.hasText(xslResource) ^ StringUtils.hasText(xslTemplates),
|
||||
"Exactly one of 'xsl-resource' or 'xsl-templates' is required.");
|
||||
if (StringUtils.hasText(xslResource)) {
|
||||
builder.addConstructorArgValue(xslResource);
|
||||
}
|
||||
else if (StringUtils.hasText(xslTemplates)) {
|
||||
builder.addConstructorArgReference(xslTemplates);
|
||||
}
|
||||
String sourceFactory = element.getAttribute("source-factory");
|
||||
if (StringUtils.hasText(sourceFactory)) {
|
||||
builder.addPropertyReference("sourceFactory", sourceFactory);
|
||||
}
|
||||
resultFactoryHelper.assertResultFactoryAndTypeValid(resultFactory, resultType);
|
||||
resultFactoryHelper.addResultFactory(builder, resultType, resultFactory);
|
||||
if (StringUtils.hasText(resultTransformer)) {
|
||||
builder.addConstructorArgReference(resultTransformer);
|
||||
}
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "source-factory");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,17 +26,18 @@ import javax.xml.transform.dom.DOMResult;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.integration.message.MessagingException;
|
||||
import org.springframework.integration.xml.util.XmlTestUtil;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
*/
|
||||
public class XsltPayloadTransformerTest {
|
||||
public class XsltPayloadTransformerTests {
|
||||
|
||||
private XsltPayloadTransformer transformer;
|
||||
|
||||
@@ -44,42 +45,42 @@ public class XsltPayloadTransformerTest {
|
||||
|
||||
private String outputAsString = "<bob>test</bob>";
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
transformer = new XsltPayloadTransformer(getXslResource());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDocumentAsPayload() throws Exception {
|
||||
Object transformed = transformer.transformPayload(XmlTestUtil
|
||||
.getDocumentForString(docAsString));
|
||||
assertTrue("Wrong return type for document payload", Document.class
|
||||
.isAssignableFrom(transformed.getClass()));
|
||||
Object transformed = transformer.transformPayload(
|
||||
XmlTestUtil.getDocumentForString(docAsString));
|
||||
assertTrue("Wrong return type for document payload",
|
||||
Document.class.isAssignableFrom(transformed.getClass()));
|
||||
Document transformedDocument = (Document) transformed;
|
||||
assertXMLEqual(outputAsString, XmlTestUtil
|
||||
.docToString(transformedDocument));
|
||||
assertXMLEqual(outputAsString, XmlTestUtil.docToString(transformedDocument));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceAsPayload() throws Exception {
|
||||
Object transformed = transformer
|
||||
.transformPayload(new StringSource(docAsString));
|
||||
assertEquals("Wrong return type for source payload", DOMResult.class,
|
||||
transformed.getClass());
|
||||
Object transformed = transformer.transformPayload(new StringSource(docAsString));
|
||||
assertEquals("Wrong return type for source payload",
|
||||
DOMResult.class, transformed.getClass());
|
||||
DOMResult result = (DOMResult) transformed;
|
||||
assertXMLEqual("Document incorrect after transformation", XmlTestUtil
|
||||
.getDocumentForString(outputAsString), (Document) result
|
||||
.getNode());
|
||||
assertXMLEqual("Document incorrect after transformation",
|
||||
XmlTestUtil.getDocumentForString(outputAsString),
|
||||
(Document) result.getNode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringAsPayload() throws Exception {
|
||||
Object transformed = transformer.transformPayload(docAsString);
|
||||
assertEquals("Wrong return type for string payload", String.class,
|
||||
transformed.getClass());
|
||||
assertEquals("Wrong return type for string payload",
|
||||
String.class, transformed.getClass());
|
||||
String transformedString = (String) transformed;
|
||||
assertXMLEqual("String incorrect after transform", outputAsString,
|
||||
transformedString);
|
||||
assertXMLEqual("String incorrect after transform",
|
||||
outputAsString, transformedString);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,19 +90,17 @@ public class XsltPayloadTransformerTest {
|
||||
assertEquals("Wrong return type for useFactories true",
|
||||
DOMResult.class, transformed.getClass());
|
||||
DOMResult result = (DOMResult) transformed;
|
||||
assertXMLEqual("Document incorrect after transformation", XmlTestUtil
|
||||
.getDocumentForString(outputAsString), (Document) result
|
||||
.getNode());
|
||||
assertXMLEqual("Document incorrect after transformation",
|
||||
XmlTestUtil.getDocumentForString(outputAsString),
|
||||
(Document) result.getNode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSourceWithResultTransformer() throws Exception {
|
||||
Integer returnValue = new Integer(13);
|
||||
transformer = new XsltPayloadTransformer(getXslResource(), new StubResultTransformer(returnValue));
|
||||
Object transformed = transformer
|
||||
.transformPayload(new StringSource(docAsString));
|
||||
assertEquals("Wrong value from result conversion", returnValue,
|
||||
transformed);
|
||||
Object transformed = transformer.transformPayload(new StringSource(docAsString));
|
||||
assertEquals("Wrong value from result conversion", returnValue, transformed);
|
||||
}
|
||||
|
||||
@Test(expected = TransformerException.class)
|
||||
@@ -114,23 +113,24 @@ public class XsltPayloadTransformerTest {
|
||||
transformer.transformPayload(new Long(12));
|
||||
}
|
||||
|
||||
|
||||
private Resource getXslResource() throws Exception {
|
||||
String xsl = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"order\"><bob>test</bob></xsl:template></xsl:stylesheet>";
|
||||
return new ByteArrayResource(xsl.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
|
||||
public static class StubResultTransformer implements ResultTransformer {
|
||||
|
||||
private Object objToReturn;
|
||||
private Object objectToReturn;
|
||||
|
||||
public StubResultTransformer(Object objToReturn) {
|
||||
this.objToReturn = objToReturn;
|
||||
public StubResultTransformer(Object objectToReturn) {
|
||||
this.objectToReturn = objectToReturn;
|
||||
}
|
||||
|
||||
public Object transformResult(Result res) {
|
||||
return objToReturn;
|
||||
public Object transformResult(Result result) {
|
||||
return objectToReturn;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user