Search in sources :

Example 1 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class TestHelper method logMessage.

private void logMessage(Exchange exchange, Document inDoc) throws Exception {
    XmlConverter converter = new XmlConverter();
    String xmlStr = converter.toString(inDoc, exchange);
    log.debug(xmlStr);
}
Also used : XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 2 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class CxfUtilsTest method getSubElementString.

private String getSubElementString(String string) throws Exception {
    InputStream is = new ByteArrayInputStream(string.getBytes("UTF-8"));
    XmlConverter converter = new XmlConverter();
    Element element = converter.toDOMElement(converter.toDOMSource(is, null));
    Element subElement = (Element) element.getFirstChild();
    return CxfUtils.elementToString(subElement);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.w3c.dom.Element) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 3 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class XsltBuilderTest method testXsltTemplates.

public void testXsltTemplates() throws Exception {
    File file = new File("src/test/resources/org/apache/camel/builder/xml/example.xsl");
    Source source = new SAXSource(new InputSource(new FileInputStream(file)));
    XmlConverter converter = new XmlConverter();
    Templates styleSheet = converter.getTransformerFactory().newTemplates(source);
    XsltBuilder builder = XsltBuilder.xslt(styleSheet);
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("<hello>world!</hello>");
    builder.process(exchange);
    assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><goodbye>world!</goodbye>", exchange.getOut().getBody());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) InputSource(org.xml.sax.InputSource) SAXSource(javax.xml.transform.sax.SAXSource) Templates(javax.xml.transform.Templates) File(java.io.File) InputSource(org.xml.sax.InputSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) FileInputStream(java.io.FileInputStream) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 4 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class StreamCacheConverterTest method testConvertToStreamCacheStreamSource.

public void testConvertToStreamCacheStreamSource() throws Exception {
    context.start();
    StreamSource source = new StreamSource(getTestFileStream());
    StreamCache cache = StreamCacheConverter.convertToStreamCache(source, exchange);
    //assert re-readability of the cached StreamSource
    XmlConverter converter = new XmlConverter();
    assertNotNull(converter.toString((Source) cache, null));
    cache.reset();
    assertNotNull(converter.toString((Source) cache, null));
}
Also used : StreamCache(org.apache.camel.StreamCache) StreamSource(javax.xml.transform.stream.StreamSource) InputSource(org.xml.sax.InputSource) StreamSource(javax.xml.transform.stream.StreamSource) Source(javax.xml.transform.Source) SAXSource(javax.xml.transform.sax.SAXSource) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Example 5 with XmlConverter

use of org.apache.camel.converter.jaxp.XmlConverter in project camel by apache.

the class DumpModelAsXmlSplitBodyRouteTest method testDumpModelAsXml.

public void testDumpModelAsXml() throws Exception {
    String xml = ModelHelper.dumpModelAsXml(context, context.getRouteDefinition("myRoute"));
    assertNotNull(xml);
    log.info(xml);
    Document doc = new XmlConverter().toDOMDocument(xml);
    NodeList nodes = doc.getElementsByTagName("simple");
    assertEquals(1, nodes.getLength());
    Element node = (Element) nodes.item(0);
    assertNotNull("Node <simple> expected to be instanceof Element", node);
    assertEquals("body", node.getTextContent());
    nodes = doc.getElementsByTagName("split");
    assertEquals(1, nodes.getLength());
    nodes = doc.getElementsByTagName("to");
    assertEquals(1, nodes.getLength());
    node = (Element) nodes.item(0);
    assertNotNull("Node <to> expected to be instanceof Element", node);
    assertEquals("mock:sub", node.getAttribute("uri"));
    assertEquals("myMock", node.getAttribute("id"));
    assertEquals("true", node.getAttribute("customId"));
}
Also used : NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) XmlConverter(org.apache.camel.converter.jaxp.XmlConverter)

Aggregations

XmlConverter (org.apache.camel.converter.jaxp.XmlConverter)29 Element (org.w3c.dom.Element)14 Exchange (org.apache.camel.Exchange)10 Document (org.w3c.dom.Document)10 Source (javax.xml.transform.Source)9 Processor (org.apache.camel.Processor)7 RouteBuilder (org.apache.camel.builder.RouteBuilder)6 NodeList (org.w3c.dom.NodeList)4 StringReader (java.io.StringReader)3 List (java.util.List)3 TransformerException (javax.xml.transform.TransformerException)3 DOMSource (javax.xml.transform.dom.DOMSource)3 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 JAXBContext (javax.xml.bind.JAXBContext)2