use of javax.management.MBeanServer in project camel by apache.
the class ManagedBrowsableEndpointAsXmlTest method testBrowseableEndpointAsXmlIncludeBody.
public void testBrowseableEndpointAsXmlIncludeBody() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(7);
template.sendBody("direct:start", "<foo>Camel > Donkey</foo>");
template.sendBody("direct:start", "Camel > Donkey");
template.sendBodyAndHeader("direct:start", "<foo>Camel > Donkey</foo>", "name", "Me & You");
template.sendBodyAndHeader("direct:start", "<foo>Camel > Donkey</foo>", "title", "<title>Me & You</title>");
template.sendBodyAndHeader("direct:start", "Camel > Donkey", "name", "Me & You");
template.sendBodyAndHeader("direct:start", 123, "user", true);
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("user", false);
headers.put("uid", 123);
headers.put("title", "Camel rocks");
template.sendBodyAndHeaders("direct:start", "<animal><name>Donkey</name><age>17</age></animal>", headers);
assertMockEndpointsSatisfied();
List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
MBeanServer mbeanServer = getMBeanServer();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://result\"");
String out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 0, true }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n <body type=\"java.lang.String\"><foo>Camel &gt; Donkey</foo></body>\n</message>", out);
out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 1, true }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n <body type=\"java.lang.String\">Camel > Donkey</body>\n</message>", out);
out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 2, true }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(2).getExchangeId() + "\">\n <headers>\n <header key=\"name\" type=\"java.lang.String\">Me & You</header>\n </headers>\n" + " <body type=\"java.lang.String\"><foo>Camel &gt; Donkey</foo></body>\n</message>", out);
out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 3, true }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(3).getExchangeId() + "\">\n <headers>\n" + " <header key=\"title\" type=\"java.lang.String\"><title>Me &amp; You</title></header>\n </headers>\n" + " <body type=\"java.lang.String\"><foo>Camel &gt; Donkey</foo></body>\n</message>", out);
out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 4, true }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(4).getExchangeId() + "\">\n <headers>\n <header key=\"name\" type=\"java.lang.String\">Me & You</header>\n </headers>\n" + " <body type=\"java.lang.String\">Camel > Donkey</body>\n</message>", out);
out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 5, true }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(5).getExchangeId() + "\">\n <headers>\n <header key=\"user\" type=\"java.lang.Boolean\">true</header>\n </headers>\n" + " <body type=\"java.lang.Integer\">123</body>\n</message>", out);
out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 6, true }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(6).getExchangeId() + "\">\n <headers>\n <header key=\"title\" type=\"java.lang.String\">Camel rocks</header>\n" + " <header key=\"uid\" type=\"java.lang.Integer\">123</header>\n" + " <header key=\"user\" type=\"java.lang.Boolean\">false</header>\n </headers>\n" + " <body type=\"java.lang.String\"><animal><name>Donkey</name><age>17</age></animal></body>\n</message>", out);
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedBrowsableEndpointAsXmlTest method testBrowseableEndpointAsXml.
public void testBrowseableEndpointAsXml() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(2);
template.sendBodyAndHeader("direct:start", "Hello World", "foo", 123);
template.sendBodyAndHeader("direct:start", "Bye World", "foo", 456);
assertMockEndpointsSatisfied();
List<Exchange> exchanges = getMockEndpoint("mock:result").getReceivedExchanges();
MBeanServer mbeanServer = getMBeanServer();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://result\"");
String out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 0, false }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(0).getExchangeId() + "\">\n <headers>\n <header key=\"foo\" type=\"java.lang.Integer\">123</header>\n </headers>\n</message>", out);
out = (String) mbeanServer.invoke(name, "browseMessageAsXml", new Object[] { 1, false }, new String[] { "java.lang.Integer", "java.lang.Boolean" });
assertNotNull(out);
log.info(out);
assertEquals("<message exchangeId=\"" + exchanges.get(1).getExchangeId() + "\">\n <headers>\n <header key=\"foo\" type=\"java.lang.Integer\">456</header>\n </headers>\n</message>", out);
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedBrowsableEndpointAsXmlTest method testBrowseableEndpointAsXmlRangeInvalidIndex.
public void testBrowseableEndpointAsXmlRangeInvalidIndex() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://result\"");
try {
mbeanServer.invoke(name, "browseRangeMessagesAsXml", new Object[] { 3, 1, false }, new String[] { "java.lang.Integer", "java.lang.Integer", "java.lang.Boolean" });
fail("Should have thrown exception");
} catch (Exception e) {
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("From index cannot be larger than to index, was: 3 > 1", e.getCause().getMessage());
}
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedBrowsableEndpointTest method testBrowseableEndpoint.
public void testBrowseableEndpoint() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
getMockEndpoint("mock:result").expectedMessageCount(2);
template.sendBody("direct:start", "Hello World");
template.sendBody("direct:start", "Bye World");
assertMockEndpointsSatisfied();
MBeanServer mbeanServer = getMBeanServer();
ObjectName name = ObjectName.getInstance("org.apache.camel:context=camel-1,type=endpoints,name=\"mock://result\"");
String uri = (String) mbeanServer.getAttribute(name, "EndpointUri");
assertEquals("mock://result", uri);
Long size = (Long) mbeanServer.invoke(name, "queueSize", null, null);
assertEquals(2, size.longValue());
String out = (String) mbeanServer.invoke(name, "browseExchange", new Object[] { 0 }, new String[] { "java.lang.Integer" });
assertNotNull(out);
// message body is not dumped when browsing exchange
assertFalse(out.contains("Hello World"));
out = (String) mbeanServer.invoke(name, "browseExchange", new Object[] { 1 }, new String[] { "java.lang.Integer" });
assertNotNull(out);
// message body is not dumped when browsing exchange
assertFalse(out.contains("Bye World"));
out = (String) mbeanServer.invoke(name, "browseMessageBody", new Object[] { 1 }, new String[] { "java.lang.Integer" });
assertNotNull(out);
assertEquals("Bye World", out);
}
use of javax.management.MBeanServer in project camel by apache.
the class ManagedCBRTest method testManagedCBR.
// CAMEL-4044: mbeans not registered for children of choice
public void testManagedCBR() throws Exception {
// JMX tests dont work well on AIX CI servers (hangs them)
if (isPlatform("aix")) {
return;
}
MBeanServer mbeanServer = getMBeanServer();
ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-a\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"choice\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-b\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-c\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-d\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-e\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"task-done\"");
assertTrue("MBean '" + on + "' not registered", mbeanServer.isRegistered(on));
}
Aggregations