use of javax.xml.transform.sax.SAXSource in project camel by apache.
the class XmlConverterTest method testOutOptionsFromCamelContext.
public void testOutOptionsFromCamelContext() throws Exception {
CamelContext context = new DefaultCamelContext();
Exchange exchange = new DefaultExchange(context);
// shows how to set the OutputOptions from camelContext
context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.ENCODING, "UTF-8");
context.getGlobalOptions().put(XmlConverter.OUTPUT_PROPERTIES_PREFIX + OutputKeys.STANDALONE, "no");
XmlConverter conv = new XmlConverter();
SAXSource source = conv.toSAXSource("<foo>bar</foo>", exchange);
DOMSource out = conv.toDOMSource(source, exchange);
assertNotSame(source, out);
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><foo>bar</foo>", conv.toString(out, exchange));
}
use of javax.xml.transform.sax.SAXSource in project camel by apache.
the class XmlConverterTest method testToDomElement.
public void testToDomElement() throws Exception {
XmlConverter conv = new XmlConverter();
SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
Element out = conv.toDOMElement(source);
assertNotNull(out);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
use of javax.xml.transform.sax.SAXSource in project camel by apache.
the class MultiCastParallelAndStreamCachingTest method testSourceCache.
public void testSourceCache() throws Exception {
String input = "<A>a</A>";
MockEndpoint mock = getMockEndpoint("mock:resulta");
mock.expectedBodiesReceived(input);
mock = getMockEndpoint("mock:resultb");
mock.expectedBodiesReceived(input);
StringSource ss = new StringSource(input);
SAXSource saxSource = new SAXSource(SAXSource.sourceToInputSource(ss));
template.sendBody("direct:start", saxSource);
assertMockEndpointsSatisfied();
}
use of javax.xml.transform.sax.SAXSource in project camel by apache.
the class XmlConverterTest method testToReaderFromSource.
public void testToReaderFromSource() throws Exception {
XmlConverter conv = new XmlConverter();
SAXSource source = conv.toSAXSource("<foo>bar</foo>", null);
Reader out = conv.toReaderFromSource(source, null);
assertNotNull(out);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
use of javax.xml.transform.sax.SAXSource in project camel by apache.
the class XmlConverterTest method testToSaxSourceFromFile.
public void testToSaxSourceFromFile() throws Exception {
XmlConverter conv = new XmlConverter();
template.sendBodyAndHeader("file:target/xml", "<foo>bar</foo>", Exchange.FILE_NAME, "myxml.xml");
File file = new File("target/xml/myxml.xml");
SAXSource out = conv.toSAXSource(file, null);
assertNotNull(out);
assertEquals("<foo>bar</foo>", context.getTypeConverter().convertTo(String.class, out));
}
Aggregations