INT-909 Added support for the 'extract-payload' attribute on the 'marshalling-transformer' element. The default value is "true".

This commit is contained in:
Mark Fisher
2009-12-14 00:44:50 +00:00
parent 8124446f9d
commit 9494dd9371
4 changed files with 36 additions and 6 deletions

View File

@@ -46,6 +46,10 @@ public class MarshallingTransformerParser extends AbstractTransformerParser {
if (StringUtils.hasText(resultTransformer)) {
builder.addConstructorArgReference(resultTransformer);
}
String extractPayload = element.getAttribute("extract-payload");
if (StringUtils.hasText(extractPayload)) {
builder.addPropertyValue("extractPayload", extractPayload);
}
XmlNamespaceUtils.configureResultFactory(builder, resultType, resultFactory);
}

View File

@@ -62,6 +62,14 @@
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="extract-payload" type="xsd:string" default="true">
<xsd:annotation>
<xsd:documentation>
Specify whether to extract the payload before passing to the Marshaller. By default, this
value is "true". To have the full Message passed instead, set this to "false".
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>

View File

@@ -46,8 +46,14 @@
input-channel="marshallingTransformerWithResultTransformer"
output-channel="output"
marshaller="marshaller"
result-transformer="resultTransformer">
</si-xml:marshalling-transformer>
result-transformer="resultTransformer" />
<si:channel id="marshallingTransformerWithFullMessage"/>
<si-xml:marshalling-transformer
input-channel="marshallingTransformerWithFullMessage"
output-channel="output"
extract-payload="false"
marshaller="marshaller" />
<bean id="marshaller" class="org.springframework.integration.xml.config.StubMarshaller" />

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2009 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.
@@ -60,7 +60,7 @@ public class XmlMarshallingTransformerParserTests {
Message<?> result = output.receive(0);
assertTrue("Wrong payload type", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
assertEquals("Wrong palyoad", "hello", doc.getDocumentElement().getTextContent());
assertEquals("Wrong payload", "hello", doc.getDocumentElement().getTextContent());
}
@Test
@@ -71,7 +71,7 @@ public class XmlMarshallingTransformerParserTests {
Message<?> result = output.receive(0);
assertTrue("Wrong payload type", result.getPayload() instanceof String);
String resultPayload = (String)result.getPayload();
assertEquals("Wrong palyoad", "testReturn", resultPayload);
assertEquals("Wrong payload", "testReturn", resultPayload);
}
@Test
@@ -82,7 +82,7 @@ public class XmlMarshallingTransformerParserTests {
Message<?> result = output.receive(0);
assertTrue("Wrong payload type ", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
assertEquals("Wrong palyoad", "hello", doc.getDocumentElement().getTextContent());
assertEquals("Wrong payload", "hello", doc.getDocumentElement().getTextContent());
}
@Test
@@ -103,4 +103,16 @@ public class XmlMarshallingTransformerParserTests {
assertTrue("Wrong payload type", result.getPayload() instanceof StubStringResult);
}
@Test
public void testFullMessage() throws Exception {
MessageChannel input = (MessageChannel) appContext.getBean("marshallingTransformerWithFullMessage");
GenericMessage<Object> message = new GenericMessage<Object>("hello");
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Wrong payload type", result.getPayload() instanceof DOMResult);
Document doc = (Document) ((DOMResult) result.getPayload()).getNode();
String expected = "[Payload=hello][Headers=";
assertEquals("Wrong payload", expected, doc.getDocumentElement().getTextContent().substring(0, expected.length()));
}
}