Repository: camel Updated Branches: refs/heads/master 75dfe61ed -> 4f393f31c
CAMEL-7572: Fixed setting custom id on CBR would duplicate the id on the otherwise or last when. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4f393f31 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4f393f31 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4f393f31 Branch: refs/heads/master Commit: 4f393f31c9807865240fdb341b64350ff4a3419d Parents: 75dfe61 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Jul 3 12:40:05 2014 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Jul 3 12:40:05 2014 +0200 ---------------------------------------------------------------------- .../camel/model/RouteDefinitionHelper.java | 12 ++++- .../SpringJmxDumpCBRRoutesAsXmlTest.java | 55 ++++++++++++++++++++ .../SpringJmxDumpCBRRouteAsXmlTest.xml | 43 +++++++++++++++ 3 files changed, 108 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/4f393f31/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java index 7ad3ff4..5c67d57 100644 --- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java +++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java @@ -125,7 +125,11 @@ public final class RouteDefinitionHelper { // if there was a custom id assigned, then make sure to support property placeholders if (route.hasCustomIdAssigned()) { String id = route.getId(); - route.setId(context.resolvePropertyPlaceholders(id)); + id = context.resolvePropertyPlaceholders(id); + // only set id if its changed, such as we did property placeholder + if (!route.getId().equals(id)) { + route.setId(id); + } } } } @@ -537,7 +541,11 @@ public final class RouteDefinitionHelper { if (processor.hasCustomIdAssigned()) { String id = processor.getId(); try { - processor.setId(context.resolvePropertyPlaceholders(id)); + id = context.resolvePropertyPlaceholders(id); + // only set id if its changed, such as we did property placeholder + if (!processor.getId().equals(id)) { + processor.setId(id); + } } catch (Exception e) { throw ObjectHelper.wrapRuntimeCamelException(e); } http://git-wip-us.apache.org/repos/asf/camel/blob/4f393f31/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpCBRRoutesAsXmlTest.java ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpCBRRoutesAsXmlTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpCBRRoutesAsXmlTest.java new file mode 100644 index 0000000..2b4940e --- /dev/null +++ b/components/camel-spring/src/test/java/org/apache/camel/spring/management/SpringJmxDumpCBRRoutesAsXmlTest.java @@ -0,0 +1,55 @@ +/** + * 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.spring.management; + +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import org.apache.camel.spring.SpringTestSupport; +import org.springframework.context.support.AbstractXmlApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * @version + */ +public class SpringJmxDumpCBRRoutesAsXmlTest extends SpringTestSupport { + + @Override + protected AbstractXmlApplicationContext createApplicationContext() { + return new ClassPathXmlApplicationContext("org/apache/camel/spring/management/SpringJmxDumpCBRRouteAsXmlTest.xml"); + } + + protected MBeanServer getMBeanServer() { + return context.getManagementStrategy().getManagementAgent().getMBeanServer(); + } + + public void testJmxDumpCBRRoutesAsXml() throws Exception { + MBeanServer mbeanServer = getMBeanServer(); + + ObjectName on = ObjectName.getInstance("org.apache.camel:context=camel-1,type=context,name=\"camel-1\""); + String xml = (String) mbeanServer.invoke(on, "dumpRoutesAsXml", null, null); + assertNotNull(xml); + log.info(xml); + + assertTrue(xml.contains("myRoute")); + assertTrue(xml.contains("<when id=\"when1\">")); + assertTrue(xml.contains("<otherwise id=\"otherwise1\">")); + assertTrue(xml.contains("<route customId=\"true\" id=\"myRoute\">") || xml.contains("<route id=\"myRoute\" customId=\"true\">")); + assertTrue(xml.contains("<choice customId=\"true\" id=\"myChoice\">") || xml.contains("<choice id=\"myChoice\" customId=\"true\">")); + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/4f393f31/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpCBRRouteAsXmlTest.xml ---------------------------------------------------------------------- diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpCBRRouteAsXmlTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpCBRRouteAsXmlTest.xml new file mode 100644 index 0000000..9272499 --- /dev/null +++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/management/SpringJmxDumpCBRRouteAsXmlTest.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <!-- enable JMX --> + <jmxAgent id="agent" disabled="false"/> + + <route id="myRoute"> + <from uri="seda:personnel.records"/> + <choice id="myChoice"> + <when> + <xpath>/person/city = 'London'</xpath> + <to uri="file:target/messages/uk"/> + </when> + <otherwise> + <to uri="file:target/messages/others"/> + </otherwise> + </choice> + </route> + </camelContext> + +</beans>