Search in sources :

Example 6 with StringResult

use of org.springframework.xml.transform.StringResult in project spring-integration by spring-projects.

the class XsltPayloadTransformer method transformSource.

private Object transformSource(Source source, Object payload, Transformer transformer) throws TransformerException {
    Result result;
    if (!this.resultFactoryExplicitlySet && "text".equals(transformer.getOutputProperties().getProperty("method"))) {
        result = new StringResult();
    } else {
        result = this.getResultFactory().createResult(payload);
    }
    transformer.transform(source, result);
    if (this.resultTransformer != null) {
        return this.resultTransformer.transformResult(result);
    }
    return result;
}
Also used : StringResult(org.springframework.xml.transform.StringResult) Result(javax.xml.transform.Result) StringResult(org.springframework.xml.transform.StringResult) DOMResult(javax.xml.transform.dom.DOMResult)

Example 7 with StringResult

use of org.springframework.xml.transform.StringResult in project spring-integration by spring-projects.

the class XsltPayloadTransformerParserTests method testWithResourceAndStringResultType.

@Test
public void testWithResourceAndStringResultType() throws Exception {
    MessageChannel input = (MessageChannel) applicationContext.getBean("withTemplatesAndStringResultTypeIn");
    GenericMessage<Object> message = new GenericMessage<Object>(XmlTestUtil.getDomSourceForString(doc));
    input.send(message);
    Message<?> result = output.receive(0);
    assertTrue("Payload was not a StringResult", result.getPayload() instanceof StringResult);
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageChannel(org.springframework.messaging.MessageChannel) StubStringResult(org.springframework.integration.xml.config.StubResultFactory.StubStringResult) StringResult(org.springframework.xml.transform.StringResult) Test(org.junit.Test)

Example 8 with StringResult

use of org.springframework.xml.transform.StringResult in project spring-integration-samples by spring-projects.

the class WeatherMarshaller method writeXml.

public static final void writeXml(Document document) {
    Transformer transformer = createIndentingTransformer();
    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
    try {
        StringResult streamResult = new StringResult();
        transformer.transform(new DOMSource(document), streamResult);
    } catch (Exception ex) {
        throw new IllegalStateException(ex);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringResult(org.springframework.xml.transform.StringResult) MarshallingFailureException(org.springframework.oxm.MarshallingFailureException) IOException(java.io.IOException) XmlMappingException(org.springframework.oxm.XmlMappingException)

Example 9 with StringResult

use of org.springframework.xml.transform.StringResult in project spring-integration-samples by spring-projects.

the class InContainerTests method testWebServiceRequestAndResponse.

@Test
public void testWebServiceRequestAndResponse() {
    StringResult result = new StringResult();
    Source payload = new StringSource("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<echoRequest xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoRequest>");
    template.sendSourceAndReceiveToResult(WS_URI, payload, result);
    logger.info("RESULT: " + result.toString());
    assertThat(result.toString(), equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<echoResponse xmlns=\"http://www.springframework.org/spring-ws/samples/echo\">hello</echoResponse>"));
}
Also used : StringResult(org.springframework.xml.transform.StringResult) StringSource(org.springframework.xml.transform.StringSource) StringSource(org.springframework.xml.transform.StringSource) Source(javax.xml.transform.Source) Test(org.junit.Test)

Example 10 with StringResult

use of org.springframework.xml.transform.StringResult in project spring-integration-samples by spring-projects.

the class XmlUtil method docAsString.

public static String docAsString(Document doc) {
    try {
        StringResult res = new StringResult();
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        transformer.transform(new DOMSource(doc), res);
        return res.toString();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StringResult(org.springframework.xml.transform.StringResult)

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