camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1102648 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/management/mbean/ camel-core/src/main/java/org/apache/camel/util/ camel-core/src/test/java/org/apache/camel/management/ co...
Date Fri, 13 May 2011 10:13:26 GMT
Author: davsclaus
Date: Fri May 13 10:13:26 2011
New Revision: 1102648

URL: http://svn.apache.org/viewvc?rev=1102648&view=rev
Log:
CAMEL-3970: Added operations to JMX to show routes in XML. As well as update/add routes from
XML.

Added:
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ModelHelper.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextDumpRoutesAsXmlTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesFromXmlTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java
  (contents, props changed)
      - copied, changed from r1102162, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteRemoveTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpRoutesAsXmlTest.java
  (contents, props changed)
      - copied, changed from r1102162, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxRecipientListTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpRouteAsXmlTest.xml
      - copied, changed from r1102162, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1102648&r1=1102647&r2=1102648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Fri
May 13 10:13:26 2011
@@ -614,7 +614,8 @@ public class DefaultCamelContext extends
     public synchronized RoutesDefinition loadRoutesDefinition(InputStream is) throws Exception
{
         // load routes using JAXB
         if (jaxbContext == null) {
-            jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES);
+            // must use classloader from CamelContext to have JAXB working
+            jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES, CamelContext.class.getClassLoader());
         }
 
         Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java?rev=1102648&r1=1102647&r2=1102648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
Fri May 13 10:13:26 2011
@@ -16,13 +16,18 @@
  */
 package org.apache.camel.management.mbean;
 
+import java.io.InputStream;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.ServiceStatus;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.model.RoutesDefinition;
 import org.apache.camel.spi.ManagementStrategy;
+import org.apache.camel.util.ModelHelper;
 import org.springframework.jmx.export.annotation.ManagedAttribute;
 import org.springframework.jmx.export.annotation.ManagedOperation;
 import org.springframework.jmx.export.annotation.ManagedResource;
@@ -175,4 +180,30 @@ public class ManagedCamelContext {
         return answer;
     }
 
+    @ManagedOperation(description = "Dumps the routes as XML")
+    public String dumpRoutesAsXml() throws Exception {
+        List<RouteDefinition> routes = context.getRouteDefinitions();
+        if (routes.isEmpty()) {
+            return null;
+        }
+
+        // use a routes definition to dump the routes
+        RoutesDefinition def = new RoutesDefinition();
+        def.setRoutes(routes);
+        return ModelHelper.dumpModelAsXml(def);
+    }
+
+    @ManagedOperation(description = "Adds or updates existing routes from XML")
+    public void addOrUpdateRoutesFromXml(String xml) throws Exception {
+        // convert to model from xml
+        InputStream is = context.getTypeConverter().mandatoryConvertTo(InputStream.class,
xml);
+        RoutesDefinition def = context.loadRoutesDefinition(is);
+        if (def == null) {
+            return;
+        }
+
+        // add will remove existing route first
+        context.addRouteDefinitions(def.getRoutes());
+    }
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java?rev=1102648&r1=1102647&r2=1102648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
Fri May 13 10:13:26 2011
@@ -24,7 +24,9 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.ManagementStatisticsLevel;
 import org.apache.camel.Route;
 import org.apache.camel.ServiceStatus;
+import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.spi.RoutePolicy;
+import org.apache.camel.util.ModelHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.springframework.jmx.export.annotation.ManagedAttribute;
 import org.springframework.jmx.export.annotation.ManagedOperation;
@@ -192,4 +194,27 @@ public class ManagedRoute extends Manage
         }
         return context.removeRoute(getRouteId());
     }
+
+    @ManagedOperation(description = "Dumps the route as XML")
+    public String dumpRouteAsXml() throws Exception {
+        String id = route.getId();
+        RouteDefinition def = context.getRouteDefinition(id);
+        if (def != null) {
+            return ModelHelper.dumpModelAsXml(def);
+        }
+        return null;
+    }
+
+    @ManagedOperation(description = "Updates the route from XML")
+    public void updateRouteFromXml(String xml) throws Exception {
+        // convert to model from xml
+        RouteDefinition def = ModelHelper.createModelFromXml(xml, RouteDefinition.class);
+        if (def == null) {
+            return;
+        }
+
+        // add will remove existing route first
+        context.addRouteDefinition(def);
+    }
+
 }

Added: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ModelHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ModelHelper.java?rev=1102648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ModelHelper.java (added)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ModelHelper.java Fri May 13
10:13:26 2011
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.util;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.Constants;
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+
+/**
+ * Helper for the Camel {@link org.apache.camel.model model} classes.
+ */
+public final class ModelHelper {
+
+    private ModelHelper() {
+        // utility class
+    }
+
+    /**
+     * Dumps the definition as XML
+     *
+     * @param definition  the definition, such as a {@link org.apache.camel.model.RouteDefinition}
+     * @return            the output in XML (is formatted)
+     * @throws JAXBException is throw if error marshalling to XML
+     */
+    public static String dumpModelAsXml(OptionalIdentifiedDefinition definition) throws JAXBException
{
+        // create a new jaxb context
+        // must use classloader from CamelContext to have JAXB working
+        JAXBContext jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES,
CamelContext.class.getClassLoader());
+
+        Marshaller marshaller = jaxbContext.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+        StringWriter buffer = new StringWriter();
+        marshaller.marshal(definition, buffer);
+
+        return buffer.toString();
+    }
+
+    /**
+     * Marshal the xml to the model definition
+     *
+     * @param xml the xml
+     * @param type the definition type to return, will throw a {@link ClassCastException}
if not the expected type
+     * @return the model definition
+     * @throws javax.xml.bind.JAXBException is thrown if error unmarshalling from xml to
model
+     */
+    public static <T extends OptionalIdentifiedDefinition> T createModelFromXml(String
xml, Class<T> type) throws JAXBException {
+        // create a new jaxb context
+        // must use classloader from CamelContext to have JAXB working
+        JAXBContext jaxbContext = JAXBContext.newInstance(Constants.JAXB_CONTEXT_PACKAGES,
CamelContext.class.getClassLoader());
+
+        StringReader reader = new StringReader(xml);
+        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+        Object result = unmarshaller.unmarshal(reader);
+        reader.close();
+
+        if (result == null) {
+            throw new JAXBException("Cannot unmarshal to " + type + " using JAXB from XML:
" + xml);
+        }
+
+        return type.cast(result);
+    }
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextDumpRoutesAsXmlTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextDumpRoutesAsXmlTest.java?rev=1102648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextDumpRoutesAsXmlTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextDumpRoutesAsXmlTest.java
Fri May 13 10:13:26 2011
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class ManagedCamelContextDumpRoutesAsXmlTest extends ManagementTestSupport {
+
+    public void testDumpAsXml() throws Exception {
+        MBeanServer mbeanServer = getMBeanServer();
+
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=context,name=\"camel-1\"");
+
+        String xml = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
+        assertNotNull(xml);
+        log.info(xml);
+
+        assertTrue(xml.contains("route"));
+        assertTrue(xml.contains("myRoute"));
+        assertTrue(xml.contains("myOtherRoute"));
+        assertTrue(xml.contains("direct:start"));
+        assertTrue(xml.contains("mock:result"));
+        assertTrue(xml.contains("seda:bar"));
+        assertTrue(xml.contains("mock:bar"));
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId("myRoute")
+                    .log("Got ${body}")
+                    .to("mock:result");
+
+                from("seda:bar").routeId("myOtherRoute")
+                    .filter().header("bar")
+                        .to("mock:bar")
+                    .end();
+            }
+        };
+    }
+
+}

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesFromXmlTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesFromXmlTest.java?rev=1102648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesFromXmlTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextUpdateRoutesFromXmlTest.java
Fri May 13 10:13:26 2011
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version 
+ */
+public class ManagedCamelContextUpdateRoutesFromXmlTest extends ManagementTestSupport {
+
+    public void testDumpAsXml() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+        template.sendBody("direct:start", "Hello World");
+        assertMockEndpointsSatisfied();
+
+        MBeanServer mbeanServer = getMBeanServer();
+
+        // there should be 1 routes to start with
+        Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"),
null);
+        assertEquals(1, set.size());
+
+        // update existing route, and add a 2nd
+        String xml =
+                  "<routes id=\"myRoute\" xmlns=\"http://camel.apache.org/schema/spring\">"
+                + "<route id=\"myRoute\">"
+                + "  <from uri=\"direct:start\"/>"
+                + "  <log message=\"This is a changed route saying ${body}\"/>"
+                + "  <to uri=\"mock:changed\"/>"
+                + "</route>"
+                + "<route id=\"myOtherRoute\">"
+                + "  <from uri=\"seda:bar\"/>"
+                + "  <to uri=\"mock:bar\"/>"
+                + "</route>"
+                + "</routes>";
+
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=context,name=\"camel-1\"");
+        mbeanServer.invoke(on, "addOrUpdateRoutesFromXml", new Object[]{xml}, new String[]{"java.lang.String"});
+
+        // there should be 2 routes now
+        set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null);
+        assertEquals(2, set.size());
+
+        // test updated route
+        getMockEndpoint("mock:changed").expectedMessageCount(1);
+        template.sendBody("direct:start", "Bye World");
+        assertMockEndpointsSatisfied();
+
+        // test new route
+        getMockEndpoint("mock:bar").expectedMessageCount(1);
+        template.sendBody("seda:bar", "Hi Camel");
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId("myRoute")
+                    .log("Got ${body}")
+                    .to("mock:result");
+            }
+        };
+    }
+
+}

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java
(from r1102162, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteRemoveTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteRemoveTest.java&r1=1102162&r2=1102648&rev=1102648&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteRemoveTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java
Fri May 13 10:13:26 2011
@@ -20,53 +20,36 @@ import java.util.Set;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import org.apache.camel.Exchange;
-import org.apache.camel.ServiceStatus;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 
 /**
  * @version 
  */
-public class ManagedRouteRemoveTest extends ManagementTestSupport {
+public class ManagedRouteDumpRouteAsXmlTest extends ManagementTestSupport {
 
-    @Override
-    protected void setUp() throws Exception {
-        deleteDirectory("target/managed");
-        super.setUp();
-    }
-
-    public void testRemove() throws Exception {
+    public void testDumpAsXml() throws Exception {
         MBeanServer mbeanServer = getMBeanServer();
         ObjectName on = getRouteObjectName(mbeanServer);
 
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedBodiesReceived("Hello World");
 
-        template.sendBodyAndHeader("file://target/managed", "Hello World", Exchange.FILE_NAME,
"hello.txt");
+        template.sendBody("direct:start", "Hello World");
 
         assertMockEndpointsSatisfied();
 
         // should be started
-        String state = (String) mbeanServer.getAttribute(on, "State");
-        assertEquals("Should be started", ServiceStatus.Started.name(), state);
-
-        // stop
-        mbeanServer.invoke(on, "stop", null, null);
+        String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+        assertEquals("myRoute", routeId);
 
-        state = (String) mbeanServer.getAttribute(on, "State");
-        assertEquals("Should be stopped", ServiceStatus.Stopped.name(), state);
-
-        // remove
-        mbeanServer.invoke(on, "remove", null, null);
-
-        // should not be registered anymore
-        boolean registered = mbeanServer.isRegistered(on);
-        assertFalse("Route mbean should have been unregistered", registered);
-
-        // and no more routes
-        Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"),
null);
-        assertEquals(0, set.size());
+        String xml = (String) mbeanServer.invoke(on, "dumpRouteAsXml", null, null);
+        assertNotNull(xml);
+        log.info(xml);
+
+        assertTrue(xml.contains("route"));
+        assertTrue(xml.contains("myRoute"));
+        assertTrue(xml.contains("mock:result"));
     }
 
     static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception {
@@ -81,7 +64,9 @@ public class ManagedRouteRemoveTest exte
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                from("file://target/managed").to("mock:result");
+                from("direct:start").routeId("myRoute")
+                    .log("Got ${body}")
+                    .to("mock:result");
             }
         };
     }

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java?rev=1102648&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
Fri May 13 10:13:26 2011
@@ -0,0 +1,81 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.management;
+
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version 
+ */
+public class ManagedRouteUpdateRouteFromXmlTest extends ManagementTestSupport {
+
+    public void testUpdateRouteFromXml() throws Exception {
+        MBeanServer mbeanServer = getMBeanServer();
+        ObjectName on = getRouteObjectName(mbeanServer);
+
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello World");
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+
+        // should be started
+        String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+        assertEquals("myRoute", routeId);
+
+        String xml =
+                  "<route id=\"myRoute\" xmlns=\"http://camel.apache.org/schema/spring\">"
+                + "  <from uri=\"direct:start\"/>"
+                + "  <log message=\"This is a changed route saying ${body}\"/>"
+                + "  <to uri=\"mock:changed\"/>"
+                + "</route>";
+
+        mbeanServer.invoke(on, "updateRouteFromXml", new Object[]{xml}, new String[]{"java.lang.String"});
+
+        getMockEndpoint("mock:changed").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception {
+        Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"),
null);
+        assertEquals(1, set.size());
+
+        return set.iterator().next();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").routeId("myRoute")
+                    .log("Got ${body}")
+                    .to("mock:result");
+            }
+        };
+    }
+
+}

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpRoutesAsXmlTest.java
(from r1102162, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxRecipientListTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpRoutesAsXmlTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpRoutesAsXmlTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxRecipientListTest.java&r1=1102162&r2=1102648&rev=1102648&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxRecipientListTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpRoutesAsXmlTest.java
Fri May 13 10:13:26 2011
@@ -19,7 +19,6 @@ package org.apache.camel.spring.manageme
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.spring.SpringTestSupport;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -27,49 +26,32 @@ import org.springframework.context.suppo
 /**
  * @version 
  */
-public class SpringJmxRecipientListTest extends SpringTestSupport {
+public class SpringJmxDumpRoutesAsXmlTest extends SpringTestSupport {
 
     @Override
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("org/apache/camel/spring/management/SpringJmxRecipientListTest.xml");
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/management/SpringJmxDumpRouteAsXmlTest.xml");
     }
 
     protected MBeanServer getMBeanServer() {
         return context.getManagementStrategy().getManagementAgent().getMBeanServer();
     }
 
-    public void testJmxEndpointsAddedDynamicallyDefaultRegister() throws Exception {
-        MockEndpoint x = getMockEndpoint("mock:x");
-        MockEndpoint y = getMockEndpoint("mock:y");
-        MockEndpoint z = getMockEndpoint("mock:z");
-
-        x.expectedBodiesReceived("answer");
-        y.expectedBodiesReceived("answer");
-        z.expectedBodiesReceived("answer");
-
-        template.sendBodyAndHeader("direct:a", "answer", "recipientListHeader", "mock:x,mock:y,mock:z");
-
-        assertMockEndpointsSatisfied();
-
+    public void testJmxDumpRoutesAsXml() throws Exception {
         MBeanServer mbeanServer = getMBeanServer();
 
-        // this endpoint is part of the route and should be registered
-        ObjectName name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"direct://a\"");
-        assertTrue("Should be registered", mbeanServer.isRegistered(name));
-
-        // endpoints added after routes has been started is by default not registered
-        name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://x\"");
-        assertFalse("Should not be registered", mbeanServer.isRegistered(name));
-
-        name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://y\"");
-        assertFalse("Should not be registered", mbeanServer.isRegistered(name));
-
-        name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=endpoints,name=\"mock://z\"");
-        assertFalse("Should not be registered", mbeanServer.isRegistered(name));
-
-        // however components is always registered
-        name = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=components,name=\"mock\"");
-        assertTrue("Should be registered", mbeanServer.isRegistered(name));
+        ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=context,name=\"camel-1\"");
+        String xml = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null);
+        assertNotNull(xml);
+        log.info(xml);
+
+        assertTrue(xml.contains("route"));
+        assertTrue(xml.contains("myRoute"));
+        assertTrue(xml.contains("myOtherRoute"));
+        assertTrue(xml.contains("direct:start"));
+        assertTrue(xml.contains("mock:result"));
+        assertTrue(xml.contains("seda:bar"));
+        assertTrue(xml.contains("mock:bar"));
     }
 
 }

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpRoutesAsXmlTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpRoutesAsXmlTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpRouteAsXmlTest.xml
(from r1102162, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpRouteAsXmlTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpRouteAsXmlTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml&r1=1102162&r2=1102648&rev=1102648&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxRecipientListTest.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpRouteAsXmlTest.xml
Fri May 13 10:13:26 2011
@@ -27,21 +27,24 @@
         <property name="domainName" value="org.apache.camel"/>
     </bean>
 
-    <!-- START SNIPPET: e1 -->
     <camelContext xmlns="http://camel.apache.org/schema/spring">
         <!-- enable JMX -->
         <jmxAgent id="agent" disabled="false"/>
 
-        <route>
-            <from uri="direct:a"/>
-            <!-- this is a dynamic EIP so we may register mbeans after the route has started
-                 such as new endpoints, and its associated producers. Camel does NOT do this
-                 by default, you would have to enable that on the jmxAgent if you want this.
-->
-            <recipientList>
-                <header>recipientListHeader</header>
-            </recipientList>
+        <route id="myRoute">
+            <from uri="direct:start"/>
+            <log message="Got ${body}"/>
+            <to uri="mock:result"/>
         </route>
+
+        <route id="myOtherRoute">
+            <from uri="seda:bar"/>
+            <filter>
+                <header>bar</header>
+                <to uri="mock:bar"/>
+            </filter>
+        </route>
+
     </camelContext>
-    <!-- END SNIPPET: e1 -->
 
 </beans>



Mime
View raw message