use of org.springframework.xml.transform.StringResult in project spring-integration by spring-projects.
the class WebServiceOutboundGatewayWithHeaderMapperTests method extractStringResult.
private String extractStringResult(Message<?> replyMessage) throws Exception {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StringResult result = new StringResult();
Object payload = replyMessage.getPayload();
if (payload instanceof DOMSource) {
transformer.transform(((DOMSource) replyMessage.getPayload()), result);
} else if (payload instanceof Document) {
transformer.transform(new DOMSource((Document) replyMessage.getPayload()), result);
} else {
throw new IllegalArgumentException("Unsupported payload type: " + payload.getClass().getName());
}
return result.toString();
}
use of org.springframework.xml.transform.StringResult in project spring-integration by spring-projects.
the class MarshallingTransformerParserTests method testStringResult.
@Test
public void testStringResult() throws Exception {
MessageChannel input = (MessageChannel) appContext.getBean("marshallingTransformerStringResultFactory");
GenericMessage<Object> message = new GenericMessage<Object>("hello");
input.send(message);
Message<?> result = output.receive(0);
assertTrue("Wrong payload type", result.getPayload() instanceof StringResult);
}
use of org.springframework.xml.transform.StringResult in project spring-integration by spring-projects.
the class XsltPayloadTransformer method transformString.
private String transformString(String stringPayload, Transformer transformer) throws TransformerException {
StringResult result = new StringResult();
Source source;
if (this.alwaysUseSourceFactory) {
source = this.sourceFactory.createSource(stringPayload);
} else {
source = new StringSource(stringPayload);
}
transformer.transform(source, result);
return result.toString();
}
use of org.springframework.xml.transform.StringResult in project spring-integration by spring-projects.
the class DomSourceFactoryTests method getAsString.
private String getAsString(Source source) throws Exception {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StringResult res = new StringResult();
transformer.transform(source, res);
return res.toString();
}
use of org.springframework.xml.transform.StringResult in project spring-integration by spring-projects.
the class ResultToStringTransformerTests method testWithStringResult.
@Test
public void testWithStringResult() throws Exception {
StringResult result = XmlTestUtil.getStringResultForString(doc);
Object transformed = transformer.transformResult(result);
assertTrue("Wrong transformed type expected String", transformed instanceof String);
String transformedString = (String) transformed;
assertXMLEqual("Wrong content", doc, transformedString);
}
Aggregations