Search in sources :

Example 56 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class JmxNotificationEventNotifierTest method testExchangeFailed.

public void testExchangeFailed() throws Exception {
    ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=eventnotifiers,name=JmxEventNotifier");
    MyNotificationListener listener = new MyNotificationListener();
    context.getManagementStrategy().getManagementAgent().getMBeanServer().addNotificationListener(on, listener, new NotificationFilter() {

        private static final long serialVersionUID = 1L;

        public boolean isNotificationEnabled(Notification notification) {
            return true;
        }
    }, null);
    try {
        template.sendBody("direct:fail", "Hello World");
        fail("Should have thrown an exception");
    } catch (Exception e) {
        // expected
        assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
    }
    assertEquals("Get a wrong number of events", 4, listener.getEventCounter());
    context.stop();
}
Also used : NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 57 with ObjectName

use of javax.management.ObjectName 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 58 with ObjectName

use of javax.management.ObjectName 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 59 with ObjectName

use of javax.management.ObjectName 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 60 with ObjectName

use of javax.management.ObjectName 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)

Aggregations

ObjectName (javax.management.ObjectName)1515 MBeanServer (javax.management.MBeanServer)691 Test (org.junit.Test)258 MalformedObjectNameException (javax.management.MalformedObjectNameException)168 IOException (java.io.IOException)101 HashMap (java.util.HashMap)99 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)97 Attribute (javax.management.Attribute)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)94 ArrayList (java.util.ArrayList)91 MBeanServerConnection (javax.management.MBeanServerConnection)72 Map (java.util.Map)66 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)66 MBeanInfo (javax.management.MBeanInfo)64 TabularData (javax.management.openmbean.TabularData)55 JMXServiceURL (javax.management.remote.JMXServiceURL)55 MBeanRegistrationException (javax.management.MBeanRegistrationException)53 JMXConnector (javax.management.remote.JMXConnector)53 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)48 Notification (javax.management.Notification)47