Search in sources :

Example 16 with StringSource

use of org.springframework.xml.transform.StringSource 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 17 with StringSource

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

the class StringSourceTests method testWithString.

@Test
public void testWithString() throws Exception {
    String docString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>";
    StringSource source = (StringSource) sourceFactory.createSource(docString);
    BufferedReader reader = new BufferedReader(source.getReader());
    String docAsString = reader.readLine();
    assertXMLEqual("Wrong content in StringSource", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>", docAsString);
}
Also used : BufferedReader(java.io.BufferedReader) StringSource(org.springframework.xml.transform.StringSource) Test(org.junit.Test)

Example 18 with StringSource

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

the class StringSourceTests method testWithUnsupportedPayload.

@Test(expected = MessagingException.class)
public void testWithUnsupportedPayload() throws Exception {
    String docString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>";
    StringBuffer buffer = new StringBuffer(docString);
    StringSource source = (StringSource) sourceFactory.createSource(buffer);
    BufferedReader reader = new BufferedReader(source.getReader());
    String docAsString = reader.readLine();
    assertXMLEqual("Wrong content in StringSource", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><item>one</item>", docAsString);
}
Also used : BufferedReader(java.io.BufferedReader) StringSource(org.springframework.xml.transform.StringSource) Test(org.junit.Test)

Example 19 with StringSource

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

the class StubMarshaller method marshal.

public void marshal(Object graph, Result result) throws XmlMappingException, IOException {
    try {
        Transformer transformer = TransformerFactory.newInstance().newTransformer();
        StringSource stringSource = new StringSource("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?><root>" + graph.toString() + "</root>");
        transformer.transform(stringSource, result);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Transformer(javax.xml.transform.Transformer) StringSource(org.springframework.xml.transform.StringSource) XmlMappingException(org.springframework.oxm.XmlMappingException) IOException(java.io.IOException)

Example 20 with StringSource

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

the class XsltPayloadTransformerTests method testSourceAsPayload.

@Test
public void testSourceAsPayload() throws Exception {
    Object transformed = transformer.doTransform(buildMessage(new StringSource(docAsString)));
    assertEquals("Wrong return type for source payload", DOMResult.class, transformed.getClass());
    DOMResult result = (DOMResult) transformed;
    assertXMLEqual("Document incorrect after transformation", XmlTestUtil.getDocumentForString(outputAsString), (Document) result.getNode());
}
Also used : DOMResult(javax.xml.transform.dom.DOMResult) StringSource(org.springframework.xml.transform.StringSource) Test(org.junit.Test)

Aggregations

StringSource (org.springframework.xml.transform.StringSource)22 Test (org.junit.Test)15 Source (javax.xml.transform.Source)7 Transformer (javax.xml.transform.Transformer)5 DOMSource (javax.xml.transform.dom.DOMSource)4 GenericMessage (org.springframework.messaging.support.GenericMessage)4 StringResult (org.springframework.xml.transform.StringResult)4 BufferedReader (java.io.BufferedReader)3 IOException (java.io.IOException)3 MessageChannel (org.springframework.messaging.MessageChannel)3 PollableChannel (org.springframework.messaging.PollableChannel)3 Unmarshaller (org.springframework.oxm.Unmarshaller)3 StringWriter (java.io.StringWriter)2 StreamResult (javax.xml.transform.stream.StreamResult)2 XmlMappingException (org.springframework.oxm.XmlMappingException)2 WebServiceMessage (org.springframework.ws.WebServiceMessage)2 MessageContext (org.springframework.ws.context.MessageContext)2 Document (org.w3c.dom.Document)2 ServiceException (com.consol.citrus.samples.incident.exception.ServiceException)1 HashMap (java.util.HashMap)1