camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-7016: Fixed updateRouteFromXML on route mbean to handle if the xml does not contain the route id, or does not match.
Date Wed, 27 Nov 2013 08:50:44 GMT
Updated Branches:
  refs/heads/camel-2.12.x f7ee839d1 -> ae4bb74bc
  refs/heads/master a193ea9cf -> 4ed448c75


CAMEL-7016: Fixed updateRouteFromXML on route mbean to handle if the xml does not contain
the route id, or does not match.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4ed448c7
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4ed448c7
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4ed448c7

Branch: refs/heads/master
Commit: 4ed448c752fd92c54d425cf837c31267ca24048c
Parents: a193ea9
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Nov 27 09:51:56 2013 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Nov 27 09:51:56 2013 +0100

----------------------------------------------------------------------
 .../camel/management/mbean/ManagedRoute.java    | 10 +++
 .../ManagedRouteUpdateRouteFromXmlTest.java     | 76 ++++++++++++++++++++
 2 files changed, 86 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4ed448c7/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
index b1cc984..51ce287 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
@@ -230,6 +230,16 @@ public class ManagedRoute extends ManagedPerformanceCounter implements
TimerList
             return;
         }
 
+        // if the xml does not contain the route-id then we fix this by adding the actual
route id
+        // this may be needed if the route-id was auto-generated, as the intend is to update
this route
+        // and not add a new route, adding a new route, use the MBean operation on ManagedCamelContext
instead.
+        if (ObjectHelper.isEmpty(def.getId())) {
+            def.setId(getRouteId());
+        } else if (!def.getId().equals(getRouteId())) {
+            throw new IllegalArgumentException("Cannot update route from XML as routeIds
does not match. routeId: "
+                    + getRouteId() + ", routeId from XML: " + def.getId());
+        }
+
         // add will remove existing route first
         context.addRouteDefinition(def);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/4ed448c7/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
index eed6e22..0469e86 100644
--- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
+++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteUpdateRouteFromXmlTest.java
@@ -57,6 +57,46 @@ public class ManagedRouteUpdateRouteFromXmlTest extends ManagementTestSupport
{
 
         mbeanServer.invoke(on, "updateRouteFromXml", new Object[]{xml}, new String[]{"java.lang.String"});
 
+        assertEquals(1, context.getRoutes().size());
+
+        getMockEndpoint("mock:changed").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testUpdateRouteFromXmlWithoutRouteId() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        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 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"});
+
+        assertEquals(1, context.getRoutes().size());
+
         getMockEndpoint("mock:changed").expectedMessageCount(1);
 
         template.sendBody("direct:start", "Bye World");
@@ -64,6 +104,42 @@ public class ManagedRouteUpdateRouteFromXmlTest extends ManagementTestSupport
{
         assertMockEndpointsSatisfied();
     }
 
+    public void testUpdateRouteFromXmlMismatchRouteId() throws Exception {
+        // JMX tests dont work well on AIX CI servers (hangs them)
+        if (isPlatform("aix")) {
+            return;
+        }
+
+        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=\"foo\" 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>";
+
+        try {
+            mbeanServer.invoke(on, "updateRouteFromXml", new Object[]{xml}, new String[]{"java.lang.String"});
+            fail("Should have thrown exception");
+        } catch (Exception e) {
+            assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+            assertEquals("Cannot update route from XML as routeIds does not match. routeId:
myRoute, routeId from XML: foo", e.getCause().getMessage());
+        }
+    }
+
     static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception {
         Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"),
null);
         assertEquals(1, set.size());


Mime
View raw message