CAMEL-6793: Fixed eips that create sub routes to also add route context advice 
so we can keep trrack of current route on exchange uow which is needed by error 
handler to pick correct route scoped onException. This fixes that WARN logging 
you may otherwise see.


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

Branch: refs/heads/camel-2.12.x
Commit: a53180622124456f953834f9afdcd2cd33d89353
Parents: e275b51
Author: Claus Ibsen <davscl...@apache.org>
Authored: Thu Oct 17 15:33:20 2013 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Thu Oct 17 16:05:21 2013 +0200

----------------------------------------------------------------------
 .../apache/camel/model/AggregateDefinition.java |  1 +
 .../camel/model/OnCompletionDefinition.java     |  1 +
 .../camel/model/ResequenceDefinition.java       |  2 +
 .../camel/processor/MulticastProcessor.java     |  6 ++
 ...gSplitterDetermineErrorHandlerIssueTest.java | 40 +++++++++
 ...ngSplitterDetermineErrorHandlerIssueTest.xml | 95 ++++++++++++++++++++
 6 files changed, 145 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a5318062/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
index 0af2206..0f41f25 100644
--- a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
@@ -169,6 +169,7 @@ public class AggregateDefinition extends 
ProcessorDefinition<AggregateDefinition
         // wrap the aggregate route in a unit of work processor
         CamelInternalProcessor internal = new 
CamelInternalProcessor(childProcessor);
         internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.RouteContextAdvice(routeContext));
 
         Expression correlation = 
getExpression().createExpression(routeContext);
         AggregationStrategy strategy = createAggregationStrategy(routeContext);

http://git-wip-us.apache.org/repos/asf/camel/blob/a5318062/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
index d850941..001c0fe 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
@@ -128,6 +128,7 @@ public class OnCompletionDefinition extends 
ProcessorDefinition<OnCompletionDefi
         // wrap the on completion route in a unit of work processor
         CamelInternalProcessor internal = new 
CamelInternalProcessor(childProcessor);
         internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.RouteContextAdvice(routeContext));
 
         onCompletions.put(routeId, internal);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a5318062/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
index 1520905..faae5a9 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
@@ -351,6 +351,7 @@ public class ResequenceDefinition extends 
ProcessorDefinition<ResequenceDefiniti
         String routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
         CamelInternalProcessor internal = new 
CamelInternalProcessor(processor);
         internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.RouteContextAdvice(routeContext));
 
         ObjectHelper.notNull(config, "config", this);
         ObjectHelper.notNull(expression, "expression", this);
@@ -382,6 +383,7 @@ public class ResequenceDefinition extends 
ProcessorDefinition<ResequenceDefiniti
         String routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
         CamelInternalProcessor internal = new 
CamelInternalProcessor(processor);
         internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.RouteContextAdvice(routeContext));
 
         ObjectHelper.notNull(config, "config", this);
         ObjectHelper.notNull(expression, "expression", this);

http://git-wip-us.apache.org/repos/asf/camel/blob/a5318062/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java 
b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
index 7584adf..be1772f 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
@@ -939,12 +939,18 @@ public class MulticastProcessor extends ServiceSupport 
implements AsyncProcessor
         String routeId = routeContext != null ? 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory())
 : null;
         CamelInternalProcessor internal = new 
CamelInternalProcessor(processor);
 
+        // and wrap it in a unit of work so the UoW is on the top, so the 
entire route will be in the same UoW
         UnitOfWork parent = exchange.getProperty(Exchange.PARENT_UNIT_OF_WORK, 
UnitOfWork.class);
         if (parent != null) {
             internal.addAdvice(new 
CamelInternalProcessor.ChildUnitOfWorkProcessorAdvice(routeId, parent));
         } else {
             internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
         }
+
+        // and then in route context so we can keep track which route this is 
at runtime
+        if (routeContext != null) {
+            internal.addAdvice(new 
CamelInternalProcessor.RouteContextAdvice(routeContext));
+        }
         return internal;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/a5318062/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.java
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.java
 
b/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.java
new file mode 100644
index 0000000..b64f2d5
--- /dev/null
+++ 
b/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.java
@@ -0,0 +1,40 @@
+/**
+ * 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.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ */
+public class SpringSplitterDetermineErrorHandlerIssueTest extends 
SpringTestSupport {
+
+    @Override
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.xml");
+    }
+
+    public void testSplitter() throws Exception {
+        getMockEndpoint("mock:handled").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello,World");
+
+        assertMockEndpointsSatisfied();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/a5318062/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.xml
----------------------------------------------------------------------
diff --git 
a/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.xml
 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.xml
new file mode 100644
index 0000000..607541e
--- /dev/null
+++ 
b/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringSplitterDetermineErrorHandlerIssueTest.xml
@@ -0,0 +1,95 @@
+<?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";>
+
+  <!-- custom exceptions -->
+  <bean id="demoIllegalStateException" class="java.lang.IllegalStateException">
+    <constructor-arg index="0" value="Forced Exception" 
type="java.lang.String"/>
+  </bean>
+
+  <!-- this is the camel route which proxy the web service and forward it to 
the real web service -->
+  <camelContext id="camelCtx" xmlns="http://camel.apache.org/schema/spring"; 
errorHandlerRef="defaultErrorHandler"
+                trace="false"
+                messageHistory="true">
+
+    <errorHandler id="defaultErrorHandler" type="DefaultErrorHandler">
+      <redeliveryPolicy logExhausted="true"/>
+    </errorHandler>
+
+    <errorHandler id="noErrorHandler" type="NoErrorHandler"/>
+
+    <route id="Start" autoStartup="true" trace="false" 
errorHandlerRef="defaultErrorHandler"
+           startupOrder="900">
+      <from uri="direct:start"/>
+      <setBody>
+        <simple>Some Test Message</simple>
+      </setBody>
+      <to uri="direct:Process"/>
+    </route>
+
+    <route id="Process" autoStartup="true" trace="false" 
errorHandlerRef="defaultErrorHandler"
+           startupOrder="800">
+      <from uri="direct:Process"/>
+
+      <onException>
+        <exception>java.lang.ArithmeticException</exception>
+        <handled>
+          <constant>true</constant>
+        </handled>
+        <to uri="direct:HandleException"/>
+      </onException>
+
+      <!-- now delegate the processing of the body with all the selected 
transfers -->
+      <to uri="direct:Process2"/>
+    </route>
+
+
+    <route id="Process2" autoStartup="true" trace="false" 
errorHandlerRef="defaultErrorHandler"
+           startupOrder="30">
+      <from uri="direct:Process2"/>
+
+      <onException>
+        <exception>java.lang.IllegalStateException</exception>
+        <handled>
+          <constant>true</constant>
+        </handled>
+        <to uri="direct:HandleException"/>
+      </onException>
+
+      <split stopOnException="true" streaming="false" 
parallelProcessing="false">
+        <simple>${body}</simple>
+
+        <throwException ref="demoIllegalStateException"/>
+      </split>
+    </route>
+
+    <route id="HandleException" autoStartup="true" trace="false"
+           errorHandlerRef="noErrorHandler"
+           startupOrder="13">
+      <from uri="direct:HandleException"/>
+
+      <log loggingLevel="INFO" message="[${property.LogPrefix}] EXCEPTION 
message: ${exception}"/>
+      <log loggingLevel="DEBUG" message="[${property.LogPrefix}] EXCEPTION 
stacktrace: ${exception.stacktrace}"/>
+      <to uri="mock:handled"/>
+      <stop/>
+    </route>
+  </camelContext>
+</beans>
\ No newline at end of file

Reply via email to