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 2012/12/22 16:33:27 UTC
svn commit: r1425295 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/model/
camel-core/src/test/java/org/apache/camel/issues/
components/camel-test-spring/src/test/java/org/apache/camel/test/issues/
components/camel-test-spring/src/test/re...
Author: davsclaus
Date: Sat Dec 22 15:33:27 2012
New Revision: 1425295
URL: http://svn.apache.org/viewvc?rev=1425295&view=rev
Log:
CAMEL-5887: Fixed issue with context scoped onException and using advice with when advicing multiple routes.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionMultipleIssueTest.java (with props)
camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/
camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.java (with props)
camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/issues/
camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.xml
- copied, changed from r1424912, camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/patterns/ProduceBeanTest.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java?rev=1425295&r1=1425294&r2=1425295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/OnExceptionDefinition.java Sat Dec 22 15:33:27 2012
@@ -102,6 +102,10 @@ public class OnExceptionDefinition exten
exceptionClasses.add(exceptionType);
}
+ public void setRouteScoped(boolean routeScoped) {
+ this.routeScoped = routeScoped;
+ }
+
public boolean isRouteScoped() {
// is context scoped by default
return routeScoped != null ? routeScoped : false;
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=1425295&r1=1425294&r2=1425295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java Sat Dec 22 15:33:27 2012
@@ -2303,6 +2303,7 @@ public abstract class ProcessorDefinitio
*/
public OnExceptionDefinition onException(Class<? extends Throwable> exceptionType) {
OnExceptionDefinition answer = new OnExceptionDefinition(exceptionType);
+ answer.setRouteScoped(true);
addOutput(answer);
return answer;
}
@@ -2316,6 +2317,7 @@ public abstract class ProcessorDefinitio
*/
public OnExceptionDefinition onException(Class<? extends Throwable>... exceptions) {
OnExceptionDefinition answer = new OnExceptionDefinition(Arrays.asList(exceptions));
+ answer.setRouteScoped(true);
addOutput(answer);
return answer;
}
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java?rev=1425295&r1=1425294&r2=1425295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java Sat Dec 22 15:33:27 2012
@@ -243,7 +243,11 @@ public final class RouteDefinitionHelper
List<OnExceptionDefinition> onExceptions) {
// add global on exceptions if any
if (onExceptions != null && !onExceptions.isEmpty()) {
- abstracts.addAll(onExceptions);
+ for (OnExceptionDefinition output : onExceptions) {
+ // these are context scoped on exceptions so set this flag
+ output.setRouteScoped(false);
+ abstracts.add(output);
+ }
}
// now add onExceptions to the route
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java?rev=1425295&r1=1425294&r2=1425295&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RoutesDefinition.java Sat Dec 22 15:33:27 2012
@@ -266,6 +266,7 @@ public class RoutesDefinition extends Op
*/
public OnExceptionDefinition onException(Class<? extends Throwable> exception) {
OnExceptionDefinition answer = new OnExceptionDefinition(exception);
+ answer.setRouteScoped(false);
getOnExceptions().add(answer);
return answer;
}
Added: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionMultipleIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionMultipleIssueTest.java?rev=1425295&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionMultipleIssueTest.java (added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionMultipleIssueTest.java Sat Dec 22 15:33:27 2012
@@ -0,0 +1,125 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class AdviceWithOnExceptionMultipleIssueTest extends ContextTestSupport {
+
+ @Override
+ public boolean isUseRouteBuilder() {
+ return false;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ onException(Exception.class).handled(true).to("mock:error");
+
+ from("direct:startA").routeId("RouteA").to("mock:resultA");
+ from("direct:startB").routeId("RouteB").to("mock:resultB");
+ }
+ };
+ }
+
+ public void testSimpleMultipleAdvice() throws Exception {
+ context.addRoutes(createRouteBuilder());
+
+ context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("mock:resultA").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ }
+ });
+ }
+ });
+
+ context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ }
+ });
+
+ context.start();
+
+ getMockEndpoint("mock:resultA").expectedMessageCount(1);
+ template.sendBody("direct:startA", "a trigger");
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testMultipleAdviceWithExceptionThrown() throws Exception {
+ context.addRoutes(createRouteBuilder());
+
+ context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("mock:resultA").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ throw new Exception("my exception");
+ }
+ });
+ }
+ });
+
+ context.start();
+
+ getMockEndpoint("mock:resultA").expectedMessageCount(0);
+ template.sendBody("direct:startA", "a trigger");
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testMultipleAdvice() throws Exception {
+ context.addRoutes(createRouteBuilder());
+
+ context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("mock:resultA").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ throw new Exception("my exception");
+ }
+ });
+ }
+ });
+
+ context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ }
+ });
+
+ context.start();
+
+ getMockEndpoint("mock:resultA").expectedMessageCount(0);
+ template.sendBody("direct:startA", "a trigger");
+ assertMockEndpointsSatisfied();
+ }
+
+}
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionMultipleIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/issues/AdviceWithOnExceptionMultipleIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.java?rev=1425295&view=auto
==============================================================================
--- camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.java (added)
+++ camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.java Sat Dec 22 15:33:27 2012
@@ -0,0 +1,116 @@
+/**
+ * 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.test.issues;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.test.junit4.CamelSpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ *
+ */
+public class AdviceWithOnExceptionMultipleIssueTest extends CamelSpringTestSupport {
+
+ @Override
+ protected AbstractApplicationContext createApplicationContext() {
+ return new ClassPathXmlApplicationContext("org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.xml");
+ }
+
+ @Override
+ public boolean isUseAdviceWith() {
+ return true;
+ }
+
+ @Test
+ public void testSimpleMultipleAdvice() throws Exception {
+ context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("mock:resultA").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ }
+ });
+ }
+ });
+
+ context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ }
+ });
+
+ context.start();
+
+ getMockEndpoint("mock:resultA").expectedMessageCount(1);
+ template.sendBody("direct:startA", "a trigger");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testMultipleAdviceWithExceptionThrown() throws Exception {
+ context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("mock:resultA").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ throw new Exception("my exception");
+ }
+ });
+ }
+ });
+
+ context.start();
+
+ getMockEndpoint("mock:resultA").expectedMessageCount(0);
+ template.sendBody("direct:startA", "a trigger");
+ assertMockEndpointsSatisfied();
+ }
+
+ @Test
+ public void testMultipleAdvice() throws Exception {
+ context.getRouteDefinition("RouteA").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("mock:resultA").process(new Processor() {
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ throw new Exception("my exception");
+ }
+ });
+ }
+ });
+
+ context.getRouteDefinition("RouteB").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ }
+ });
+
+ context.start();
+
+ getMockEndpoint("mock:resultA").expectedMessageCount(0);
+ template.sendBody("direct:startA", "a trigger");
+ assertMockEndpointsSatisfied();
+ }
+
+}
Propchange: camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-test-spring/src/test/java/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied: camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.xml (from r1424912, camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/patterns/ProduceBeanTest.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.xml?p2=camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.xml&p1=camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/patterns/ProduceBeanTest.xml&r1=1424912&r2=1425295&rev=1425295&view=diff
==============================================================================
--- camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/patterns/ProduceBeanTest.xml (original)
+++ camel/trunk/components/camel-test-spring/src/test/resources/org/apache/camel/test/issues/AdviceWithOnExceptionMultipleIssueTest.xml Sat Dec 22 15:33:27 2012
@@ -22,12 +22,26 @@
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd ">
-<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
- <route>
- <from uri="direct:start"/>
- <bean beanType="org.apache.camel.test.patterns.MyProduceBean"/>
- </route>
- </camelContext>
+ <onException>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <to uri="mock:error"/>
+ </onException>
+
+ <route id="RouteA">
+ <from uri="direct:startA"/>
+ <to uri="mock:resultA"/>
+ </route>
+
+ <route id="RouteB">
+ <from uri="direct:startB"/>
+ <to uri="mock:resultB"/>
+ </route>
+
+ </camelContext>
</beans>
\ No newline at end of file