Search in sources :

Example 11 with StringResult

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();
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringResult(org.springframework.xml.transform.StringResult) Document(org.w3c.dom.Document)

Example 12 with StringResult

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);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) StringResult(org.springframework.xml.transform.StringResult) StubStringResult(org.springframework.integration.xml.config.StubResultFactory.StubStringResult) Test(org.junit.Test)

Example 13 with 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();
}
Also used : StringResult(org.springframework.xml.transform.StringResult) StringSource(org.springframework.xml.transform.StringSource) DOMSource(javax.xml.transform.dom.DOMSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) StringSource(org.springframework.xml.transform.StringSource)

Example 14 with StringResult

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();
}
Also used : Transformer(javax.xml.transform.Transformer) StringResult(org.springframework.xml.transform.StringResult)

Example 15 with StringResult

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);
}
Also used : StringResult(org.springframework.xml.transform.StringResult) Test(org.junit.Test)

Aggregations

StringResult (org.springframework.xml.transform.StringResult)18 Transformer (javax.xml.transform.Transformer)8 DOMSource (javax.xml.transform.dom.DOMSource)7 Test (org.junit.Test)7 StringSource (org.springframework.xml.transform.StringSource)4 Document (org.w3c.dom.Document)3 Result (javax.xml.transform.Result)2 Source (javax.xml.transform.Source)2 TransformerFactory (javax.xml.transform.TransformerFactory)2 DOMResult (javax.xml.transform.dom.DOMResult)2 BeanFactory (org.springframework.beans.factory.BeanFactory)2 StubStringResult (org.springframework.integration.xml.config.StubResultFactory.StubStringResult)2 MessageChannel (org.springframework.messaging.MessageChannel)2 MessageHandlingException (org.springframework.messaging.MessageHandlingException)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 SettableListenableFuture (org.springframework.util.concurrent.SettableListenableFuture)2 WebServiceMessage (org.springframework.ws.WebServiceMessage)2 ClientInterceptorAdapter (org.springframework.ws.client.support.interceptor.ClientInterceptorAdapter)2 MessageContext (org.springframework.ws.context.MessageContext)2 IOException (java.io.IOException)1