Added ability to specify a result-factory rather than a result-type on XmlPayloadMarshallingTransformer
relates to INT-310: XML Document Builders Not Namespace Aware
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2002-2007 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.integration.xml.config;
|
||||
|
||||
import javax.xml.transform.Result;
|
||||
|
||||
import org.springframework.integration.xml.result.ResultFactory;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
|
||||
public class StubResultFactory implements ResultFactory {
|
||||
|
||||
public Result createResult(Object payload) {
|
||||
return new StubStringResult();
|
||||
}
|
||||
|
||||
public class StubStringResult extends StringResult {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,11 +10,15 @@
|
||||
|
||||
<si-xml:marshalling-transformer
|
||||
id="marshallingTransformerStringResultFactory" marshaller="marshaller"
|
||||
result-factory="StringResult" />
|
||||
result-type="StringResult" />
|
||||
|
||||
<si-xml:marshalling-transformer
|
||||
id="marshallingTransformerDOMResultFactory" marshaller="marshaller"
|
||||
result-factory="DOMResult" />
|
||||
result-type="DOMResult" />
|
||||
|
||||
<si-xml:marshalling-transformer
|
||||
id="marshallingTransformerCustomResultFactory" marshaller="marshaller"
|
||||
result-factory="stubResultFactory" />
|
||||
|
||||
<si-xml:marshalling-transformer
|
||||
id="marshallingTransformerWithResultTransformer"
|
||||
@@ -26,4 +30,6 @@
|
||||
<constructor-arg value="testReturn" />
|
||||
</bean>
|
||||
|
||||
<bean id="stubResultFactory" class="org.springframework.integration.xml.config.StubResultFactory" />
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -20,18 +20,18 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import javax.xml.transform.dom.DOMResult;
|
||||
import javax.xml.transform.sax.SAXResult;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.transformer.Transformer;
|
||||
import org.springframework.integration.xml.config.StubResultFactory.StubStringResult;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* @author Jonas Partner
|
||||
@@ -84,5 +84,13 @@ public class XmlMarshallingTransformerParserTests {
|
||||
Message<?> result = transformer.transform(message);
|
||||
assertTrue("Wrong payload type", result.getPayload() instanceof StringResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomResultFactory() throws Exception {
|
||||
Transformer transformer = (Transformer) appContext.getBean("marshallingTransformerCustomResultFactory");
|
||||
GenericMessage<Object> message = new GenericMessage<Object>("hello");
|
||||
Message<?> result = transformer.transform(message);
|
||||
assertTrue("Wrong payload type", result.getPayload() instanceof StubStringResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user