Search in sources :

Example 51 with MBeanServer

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 &gt; Donkey</foo>");
    template.sendBody("direct:start", "Camel > Donkey");
    template.sendBodyAndHeader("direct:start", "<foo>Camel &gt; Donkey</foo>", "name", "Me & You");
    template.sendBodyAndHeader("direct:start", "<foo>Camel &gt; Donkey</foo>", "title", "<title>Me &amp; 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\">&lt;foo&gt;Camel &amp;gt; Donkey&lt;/foo&gt;</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 &gt; 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 &amp; You</header>\n  </headers>\n" + "  <body type=\"java.lang.String\">&lt;foo&gt;Camel &amp;gt; Donkey&lt;/foo&gt;</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\">&lt;title&gt;Me &amp;amp; You&lt;/title&gt;</header>\n  </headers>\n" + "  <body type=\"java.lang.String\">&lt;foo&gt;Camel &amp;gt; Donkey&lt;/foo&gt;</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 &amp; You</header>\n  </headers>\n" + "  <body type=\"java.lang.String\">Camel &gt; 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\">&lt;animal&gt;&lt;name&gt;Donkey&lt;/name&gt;&lt;age&gt;17&lt;/age&gt;&lt;/animal&gt;</body>\n</message>", out);
}
Also used : Exchange(org.apache.camel.Exchange) HashMap(java.util.HashMap) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 52 with MBeanServer

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);
}
Also used : Exchange(org.apache.camel.Exchange) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 53 with MBeanServer

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());
    }
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 54 with MBeanServer

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);
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 55 with MBeanServer

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));
}
Also used : MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

MBeanServer (javax.management.MBeanServer)830 ObjectName (javax.management.ObjectName)690 Test (org.junit.Test)143 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)93 MalformedObjectNameException (javax.management.MalformedObjectNameException)62 JMXServiceURL (javax.management.remote.JMXServiceURL)60 Attribute (javax.management.Attribute)56 IOException (java.io.IOException)54 HashMap (java.util.HashMap)51 TabularData (javax.management.openmbean.TabularData)51 JMXConnectorServer (javax.management.remote.JMXConnectorServer)44 JMXConnector (javax.management.remote.JMXConnector)37 ArrayList (java.util.ArrayList)35 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)34 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)34 InstanceNotFoundException (javax.management.InstanceNotFoundException)32 MBeanRegistrationException (javax.management.MBeanRegistrationException)29 Map (java.util.Map)28 MBeanServerConnection (javax.management.MBeanServerConnection)28 LocalMBeanServer (org.apache.openejb.monitoring.LocalMBeanServer)28