use of org.w3c.dom.Document in project camel by apache.
the class ManagedRouteDumpStatsAsXmlCustomDomainTest method testPerformanceCounterStats.
public void testPerformanceCounterStats() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance(CUSTOM_DOMAIN_NAME + ":context=camel-1,type=routes,name=\"foo\"");
getMockEndpoint("mock:result").expectedMessageCount(1);
template.asyncSendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
String xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[] { false, true }, new String[] { "boolean", "boolean" });
log.info(xml);
// should be valid XML
Document doc = context.getTypeConverter().convertTo(Document.class, xml);
assertNotNull(doc);
int processors = doc.getDocumentElement().getElementsByTagName("processorStat").getLength();
assertEquals(3, processors);
}
use of org.w3c.dom.Document in project camel by apache.
the class ManagedRouteDumpStatsAsXmlTest method testPerformanceCounterStats.
public void testPerformanceCounterStats() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
// get the stats for the route
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"foo\"");
getMockEndpoint("mock:result").expectedMessageCount(1);
template.asyncSendBody("direct:start", "Hello World");
assertMockEndpointsSatisfied();
String xml = (String) mbeanServer.invoke(on, "dumpRouteStatsAsXml", new Object[] { false, true }, new String[] { "boolean", "boolean" });
log.info(xml);
// should be valid XML
Document doc = context.getTypeConverter().convertTo(Document.class, xml);
assertNotNull(doc);
int processors = doc.getDocumentElement().getElementsByTagName("processorStat").getLength();
assertEquals(3, processors);
}
use of org.w3c.dom.Document in project camel by apache.
the class XmlLineNumberParserTest method testParseCamelContextForceNamespace.
public void testParseCamelContextForceNamespace() throws Exception {
FileInputStream fis = new FileInputStream("src/test/resources/org/apache/camel/util/camel-context.xml");
Document dom = XmlLineNumberParser.parseXml(fis, null, "camelContext", "http://camel.apache.org/schema/spring");
assertNotNull(dom);
NodeList list = dom.getElementsByTagName("camelContext");
assertEquals(1, list.getLength());
Node node = list.item(0);
String lineNumber = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER);
String lineNumberEnd = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
String ns = node.getNamespaceURI();
assertEquals("http://camel.apache.org/schema/spring", ns);
assertEquals("28", lineNumber);
assertEquals("46", lineNumberEnd);
// and there are two routes
list = dom.getElementsByTagName("route");
assertEquals(2, list.getLength());
Node node1 = list.item(0);
Node node2 = list.item(1);
String lineNumber1 = (String) node1.getUserData(XmlLineNumberParser.LINE_NUMBER);
String lineNumberEnd1 = (String) node1.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
assertEquals("30", lineNumber1);
assertEquals("36", lineNumberEnd1);
String lineNumber2 = (String) node2.getUserData(XmlLineNumberParser.LINE_NUMBER);
String lineNumberEnd2 = (String) node2.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
assertEquals("38", lineNumber2);
assertEquals("44", lineNumberEnd2);
}
use of org.w3c.dom.Document in project camel by apache.
the class XmlLineNumberParserTest method testParse.
public void testParse() throws Exception {
FileInputStream fis = new FileInputStream("src/test/resources/org/apache/camel/util/camel-context.xml");
Document dom = XmlLineNumberParser.parseXml(fis);
assertNotNull(dom);
NodeList list = dom.getElementsByTagName("beans");
assertEquals(1, list.getLength());
Node node = list.item(0);
String lineNumber = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER);
String lineNumberEnd = (String) node.getUserData(XmlLineNumberParser.LINE_NUMBER_END);
assertEquals("23", lineNumber);
assertEquals("48", lineNumberEnd);
}
use of org.w3c.dom.Document in project camel by apache.
the class CacheBasedXPathReplacer method process.
public void process(Exchange exchange) throws Exception {
String cacheKey = key.evaluate(exchange, String.class);
if (isValid(cacheManager, cacheName, cacheKey)) {
Ehcache cache = cacheManager.getCache(cacheName);
if (LOG.isDebugEnabled()) {
LOG.debug("Replacing XPath value {} in Message with value stored against key {} in CacheName {}", new Object[] { xpath, cacheKey, cacheName });
}
exchange.getIn().setHeader(CacheConstants.CACHE_KEY, cacheKey);
Object body = exchange.getIn().getBody();
InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, body);
Document document;
try {
document = exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, is);
} finally {
IOHelper.close(is, "is", LOG);
}
InputStream cis = exchange.getContext().getTypeConverter().convertTo(InputStream.class, cache.get(cacheKey).getObjectValue());
try {
Document cacheValueDocument = exchange.getContext().getTypeConverter().convertTo(Document.class, exchange, cis);
// Create/setup the Transformer
XmlConverter xmlConverter = new XmlConverter();
String xslString = IOConverter.toString(new File("./src/main/resources/xpathreplacer.xsl"), exchange);
xslString = xslString.replace("##match_token##", xpath);
Source xslSource = xmlConverter.toStreamSource(new StringReader(xslString));
TransformerFactory transformerFactory = xmlConverter.createTransformerFactory();
Transformer transformer = transformerFactory.newTransformer(xslSource);
DOMSource source = xmlConverter.toDOMSource(document);
DOMResult result = new DOMResult();
transformer.setParameter("cacheValue", cacheValueDocument);
transformer.transform(source, result);
// DOMSource can be converted to byte[] by camel type converter mechanism
DOMSource dom = new DOMSource(result.getNode());
exchange.getIn().setBody(dom, byte[].class);
} finally {
IOHelper.close(cis, "cis", LOG);
}
}
}
Aggregations