You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/07/02 09:36:26 UTC
[1/2] git commit: CAMEL-7560: Fixed advice with when using transacted
in the XML routes.
Repository: camel
Updated Branches:
refs/heads/camel-2.13.x 31d4262d4 -> 04a7feb9a
CAMEL-7560: Fixed advice with when using transacted in the XML routes.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/57563356
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/57563356
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/57563356
Branch: refs/heads/camel-2.13.x
Commit: 57563356c73bc048105203d2601b38c8dde40760
Parents: 31d4262
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 30 21:12:56 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 2 09:36:00 2014 +0200
----------------------------------------------------------------------
.../apache/camel/builder/AdviceWithTasks.java | 65 ++++++++++------
.../camel/model/ProcessorDefinitionHelper.java | 10 +++
.../camel/issues/AdviceWithPolicyTest.java | 78 ++++++++++++++++++++
.../issues/AdviceWithTransactionIssueTest.java | 76 +++++++++++++++++++
.../issues/AdviceWithTransactionIssueTest.xml | 35 +++++++++
.../jms/AdviceWithTransactionIssueTest.java | 76 +++++++++++++++++++
.../jms/AdviceWithTransactionIssueTest.xml | 58 +++++++++++++++
7 files changed, 377 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/57563356/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java b/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
index b827f8f..69f5a0a 100644
--- a/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
+++ b/camel-core/src/main/java/org/apache/camel/builder/AdviceWithTasks.java
@@ -143,13 +143,13 @@ public final class AdviceWithTasks {
while (it.hasNext()) {
ProcessorDefinition<?> output = it.next();
if (matchBy.match(output)) {
- ProcessorDefinition<?> parent = output.getParent();
- if (parent != null) {
- int index = parent.getOutputs().indexOf(output);
+ List<ProcessorDefinition> outputs = getParentOutputs(output.getParent());
+ if (outputs != null) {
+ int index = outputs.indexOf(output);
if (index != -1) {
match = true;
- parent.getOutputs().add(index + 1, replace);
- Object old = parent.getOutputs().remove(index);
+ outputs.add(index + 1, replace);
+ Object old = outputs.remove(index);
LOG.info("AdviceWith (" + matchBy.getId() + ") : [" + old + "] --> replace [" + replace + "]");
}
}
@@ -192,12 +192,12 @@ public final class AdviceWithTasks {
while (it.hasNext()) {
ProcessorDefinition<?> output = it.next();
if (matchBy.match(output)) {
- ProcessorDefinition<?> parent = output.getParent();
- if (parent != null) {
- int index = parent.getOutputs().indexOf(output);
+ List<ProcessorDefinition> outputs = getParentOutputs(output.getParent());
+ if (outputs != null) {
+ int index = outputs.indexOf(output);
if (index != -1) {
match = true;
- Object old = parent.getOutputs().remove(index);
+ Object old = outputs.remove(index);
LOG.info("AdviceWith (" + matchBy.getId() + ") : [" + old + "] --> remove");
}
}
@@ -240,13 +240,13 @@ public final class AdviceWithTasks {
while (it.hasNext()) {
ProcessorDefinition<?> output = it.next();
if (matchBy.match(output)) {
- ProcessorDefinition<?> parent = output.getParent();
- if (parent != null) {
- int index = parent.getOutputs().indexOf(output);
+ List<ProcessorDefinition> outputs = getParentOutputs(output.getParent());
+ if (outputs != null) {
+ int index = outputs.indexOf(output);
if (index != -1) {
match = true;
- Object existing = parent.getOutputs().get(index);
- parent.getOutputs().add(index, before);
+ Object existing = outputs.get(index);
+ outputs.add(index, before);
LOG.info("AdviceWith (" + matchBy.getId() + ") : [" + existing + "] --> before [" + before + "]");
}
}
@@ -289,14 +289,13 @@ public final class AdviceWithTasks {
while (it.hasNext()) {
ProcessorDefinition<?> output = it.next();
if (matchBy.match(output)) {
-
- ProcessorDefinition<?> parent = output.getParent();
- if (parent != null) {
- int index = parent.getOutputs().indexOf(output);
+ List<ProcessorDefinition> outputs = getParentOutputs(output.getParent());
+ if (outputs != null) {
+ int index = outputs.indexOf(output);
if (index != -1) {
match = true;
- Object existing = parent.getOutputs().get(index);
- parent.getOutputs().add(index + 1, after);
+ Object existing = outputs.get(index);
+ outputs.add(index + 1, after);
LOG.info("AdviceWith (" + matchBy.getId() + ") : [" + existing + "] --> after [" + after + "]");
}
}
@@ -310,6 +309,30 @@ public final class AdviceWithTasks {
};
}
+ /**
+ * Gets the outputs from the given parent.
+ * <p/>
+ * This implementation deals with that outputs can be abstract and retrieves the correct non-nested output.
+ *
+ * @param parent the parent
+ * @return <tt>null</tt> if no parent
+ */
+ @SuppressWarnings("unchecked")
+ private static List<ProcessorDefinition> getParentOutputs(ProcessorDefinition parent) {
+ if (parent == null) {
+ return null;
+ }
+ List<ProcessorDefinition> outputs = parent.getOutputs();
+ if (outputs.size() >= 1) {
+ // if the 1st output is abstract, then its onException,transacted,intercept etc so we should
+ // get the 'actual' outputs from that
+ if (outputs.get(0).isAbstract()) {
+ outputs = outputs.get(0).getOutputs();
+ }
+ }
+ return outputs;
+ }
+
public static AdviceWithTask replaceFromWith(final RouteDefinition route, final String uri) {
return new AdviceWithTask() {
public void task() throws Exception {
@@ -367,7 +390,7 @@ public final class AdviceWithTasks {
}
private static Iterator<ProcessorDefinition<?>> createSelectorIterator(final List<ProcessorDefinition<?>> list, final boolean selectFirst,
- final boolean selectLast, final int selectFrom, final int selectTo) {
+ final boolean selectLast, final int selectFrom, final int selectTo) {
return new Iterator<ProcessorDefinition<?>>() {
private int current;
private boolean done;
http://git-wip-us.apache.org/repos/asf/camel/blob/57563356/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 6395ec6..5575d36 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -243,6 +243,16 @@ public final class ProcessorDefinitionHelper {
continue;
}
+ // special for some types which has special outputs
+ if (out instanceof OutputDefinition) {
+ OutputDefinition outDef = (OutputDefinition) out;
+ List<ProcessorDefinition<?>> outDefOut = outDef.getOutputs();
+ doFindType(outDefOut, type, found);
+
+ // do not check children as we already did that
+ continue;
+ }
+
// try children as well
List<ProcessorDefinition<?>> children = out.getOutputs();
doFindType(children, type, found);
http://git-wip-us.apache.org/repos/asf/camel/blob/57563356/camel-core/src/test/java/org/apache/camel/issues/AdviceWithPolicyTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/AdviceWithPolicyTest.java b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithPolicyTest.java
new file mode 100644
index 0000000..c4a3416
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithPolicyTest.java
@@ -0,0 +1,78 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.RouteDefinition;
+import org.apache.camel.spi.Policy;
+import org.apache.camel.spi.RouteContext;
+
+/**
+ * @version
+ */
+public class AdviceWithPolicyTest extends ContextTestSupport {
+
+ public void testAdviceWithPolicy() throws Exception {
+ RouteDefinition route = context.getRouteDefinitions().get(0);
+ route.adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ weaveById("b").after().to("mock:result");
+ }
+ });
+ context.start();
+
+ getMockEndpoint("mock:a").expectedMessageCount(1);
+ getMockEndpoint("mock:b").expectedMessageCount(1);
+ getMockEndpoint("mock:result").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .policy(new MyPolicy())
+ .to("mock:a").id("a")
+ .to("mock:b").id("b");
+ }
+ };
+ }
+
+ private static final class MyPolicy implements Policy {
+
+ @Override
+ public void beforeWrap(RouteContext routeContext, ProcessorDefinition<?> definition) {
+ // noop
+ }
+
+ @Override
+ public Processor wrap(RouteContext routeContext, Processor processor) {
+ return processor;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/57563356/components/camel-spring/src/test/java/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/java/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.java b/components/camel-spring/src/test/java/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.java
new file mode 100644
index 0000000..89d6067
--- /dev/null
+++ b/components/camel-spring/src/test/java/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.java
@@ -0,0 +1,76 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class AdviceWithTransactionIssueTest extends SpringTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml");
+ }
+
+ @Test
+ public void testAdviceWithWeaveById() throws Exception {
+ context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ weaveById("mock-b*").after().to("mock:last");
+ }
+ });
+ context.start();
+
+ MockEndpoint mockLast = getMockEndpoint("mock:last");
+ mockLast.expectedBodiesReceived("bar");
+ mockLast.setExpectedMessageCount(1);
+
+ template.sendBody("seda:start", "bar");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testAdviceWithAddLast() throws Exception {
+ context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ weaveAddLast().to("mock:last");
+ }
+ });
+ context.start();
+
+ MockEndpoint mockLast = getMockEndpoint("mock:last");
+ mockLast.expectedBodiesReceived("bar");
+ mockLast.setExpectedMessageCount(1);
+
+ template.sendBody("seda:start", "bar");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/57563356/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
----------------------------------------------------------------------
diff --git a/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
new file mode 100644
index 0000000..1d4bcb2
--- /dev/null
+++ b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/AdviceWithTransactionIssueTest.xml
@@ -0,0 +1,35 @@
+<?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
+ ">
+
+ <import resource="../interceptor/transactionalClientDataSource.xml"/>
+
+ <camelContext id="myCamelContext" xmlns="http://camel.apache.org/schema/spring">
+ <route id="route1">
+ <from uri="seda:start"/>
+ <transacted/>
+ <to id="mock-a" uri="mock:a"/>
+ <to id="mock-b" uri="mock:b"/>
+ </route>
+ </camelContext>
+</beans>
http://git-wip-us.apache.org/repos/asf/camel/blob/57563356/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.java b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.java
new file mode 100644
index 0000000..73163d9
--- /dev/null
+++ b/tests/camel-itest/src/test/java/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.java
@@ -0,0 +1,76 @@
+/**
+ * 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.itest.jms;
+
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.spring.CamelSpringTestSupport;
+import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+
+public class AdviceWithTransactionIssueTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml");
+ }
+
+ @Override
+ public boolean isUseAdviceWith() {
+ return true;
+ }
+
+ @Test
+ public void testAdviceWithWeaveById() throws Exception {
+ context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ weaveById("mock-b*").after().to("mock:last");
+ }
+ });
+ context.start();
+
+ MockEndpoint mockLast = getMockEndpoint("mock:last");
+ mockLast.expectedBodiesReceived("bar");
+ mockLast.setExpectedMessageCount(1);
+
+ template.sendBody("activemq:queue:start", "bar");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testAdviceWithAddLast() throws Exception {
+ context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ weaveAddLast().to("mock:last");
+ }
+ });
+ context.start();
+
+ MockEndpoint mockLast = getMockEndpoint("mock:last");
+ mockLast.expectedBodiesReceived("bar");
+ mockLast.setExpectedMessageCount(1);
+
+ template.sendBody("activemq:queue:start", "bar");
+
+ assertMockEndpointsSatisfied();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/57563356/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml
----------------------------------------------------------------------
diff --git a/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml b/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml
new file mode 100644
index 0000000..8f145ff
--- /dev/null
+++ b/tests/camel-itest/src/test/resources/org/apache/camel/itest/jms/AdviceWithTransactionIssueTest.xml
@@ -0,0 +1,58 @@
+<?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">
+
+ <bean id="poolConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory">
+ <property name="maxConnections" value="8"/>
+ <property name="connectionFactory" ref="jmsConnectionFactory"/>
+ </bean>
+
+ <bean id="jmsConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL" value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
+ </bean>
+
+ <bean id="jmsTransactionManager" class="org.springframework.jms.connection.JmsTransactionManager">
+ <property name="connectionFactory" ref="poolConnectionFactory"/>
+ </bean>
+
+ <bean id="activemq" class="org.apache.activemq.camel.component.ActiveMQComponent">
+ <property name="connectionFactory" ref="poolConnectionFactory"/>
+ <property name="transacted" value="true"/>
+ <property name="transactionManager" ref="jmsTransactionManager"/>
+ <!-- we do not want any exceptions to be logged -->
+ <property name="errorHandlerLoggingLevel" value="OFF"/>
+ <property name="errorHandlerLogStackTrace" value="false"/>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+
+ <route id="route1">
+ <from uri="activemq:queue:start"/>
+ <transacted/>
+ <to id="mock-a" uri="mock:a"/>
+ <to id="mock-b" uri="mock:b"/>
+ </route>
+
+ </camelContext>
+
+
+</beans>
[2/2] git commit: CAMEL-7562: Fixed advice with when using CBR may
add twice to when clauses in the CBR.
Posted by da...@apache.org.
CAMEL-7562: Fixed advice with when using CBR may add twice to when clauses in the CBR.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/04a7feb9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/04a7feb9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/04a7feb9
Branch: refs/heads/camel-2.13.x
Commit: 04a7feb9aeda9c6b09f0cfdd48b741e50d64cf35
Parents: 5756335
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Jun 30 21:34:58 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Jul 2 09:36:05 2014 +0200
----------------------------------------------------------------------
.../camel/model/ProcessorDefinitionHelper.java | 10 ++-
.../apache/camel/issues/AdviceWithCBRTest.java | 67 ++++++++++++++++++++
.../model/ProcessorDefinitionHelperTest.java | 53 ++++++++++++++++
3 files changed, 127 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/04a7feb9/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 5575d36..2ae283b 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -198,9 +198,6 @@ public final class ProcessorDefinitionHelper {
}
for (ProcessorDefinition out : outputs) {
- if (type.isInstance(out)) {
- found.add((T)out);
- }
// send is much common
if (out instanceof SendDefinition) {
@@ -222,6 +219,9 @@ public final class ProcessorDefinitionHelper {
List<ProcessorDefinition<?>> children = choice.getOtherwise().getOutputs();
doFindType(children, type, found);
}
+
+ // do not check children as we already did that
+ continue;
}
// special for try ... catch ... finally
@@ -253,6 +253,10 @@ public final class ProcessorDefinitionHelper {
continue;
}
+ if (type.isInstance(out)) {
+ found.add((T)out);
+ }
+
// try children as well
List<ProcessorDefinition<?>> children = out.getOutputs();
doFindType(children, type, found);
http://git-wip-us.apache.org/repos/asf/camel/blob/04a7feb9/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java
new file mode 100644
index 0000000..83965ba
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/issues/AdviceWithCBRTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.RouteDefinition;
+
+/**
+ * @version
+ */
+public class AdviceWithCBRTest extends ContextTestSupport {
+
+ public void testAdviceCBR() throws Exception {
+ RouteDefinition route = context.getRouteDefinitions().get(0);
+ route.adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ weaveById("foo").after().to("mock:foo2");
+ weaveById("bar").after().to("mock:bar2");
+ }
+ });
+
+ getMockEndpoint("mock:foo").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:foo2").expectedBodiesReceived("Hello World");
+ getMockEndpoint("mock:bar").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:bar2").expectedBodiesReceived("Bye World");
+ getMockEndpoint("mock:baz").expectedBodiesReceived("Hi World");
+
+ template.sendBodyAndHeader("direct:start", "Hello World", "foo", "123");
+ template.sendBodyAndHeader("direct:start", "Bye World", "bar", "123");
+ template.sendBody("direct:start", "Hi World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when(header("foo")).to("mock:foo").id("foo")
+ .when(header("bar")).to("mock:bar").id("bar")
+ .otherwise()
+ .to("mock:baz").id("baz");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/04a7feb9/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java b/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
new file mode 100644
index 0000000..4aa1d7e
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/model/ProcessorDefinitionHelperTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.model;
+
+import java.util.Iterator;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+public class ProcessorDefinitionHelperTest extends ContextTestSupport {
+
+ public void testFilterTypeInOutputs() throws Exception {
+ RouteDefinition route = context.getRouteDefinitions().get(0);
+
+ Iterator<ProcessorDefinition> it = ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(), ProcessorDefinition.class);
+ assertNotNull(it);
+
+ assertEquals("foo", it.next().getId());
+ assertEquals("bar", it.next().getId());
+ assertEquals("baz", it.next().getId());
+ assertFalse(it.hasNext());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .choice()
+ .when(header("foo")).to("mock:foo").id("foo")
+ .when(header("bar")).to("mock:bar").id("bar")
+ .otherwise()
+ .to("mock:baz").id("baz");
+ }
+ };
+ }
+
+}