Author: hadrian
Date: Wed Mar 21 14:42:25 2012
New Revision: 1303408
URL: http://svn.apache.org/viewvc?rev=1303408&view=rev
Log:
CAMEL-5098. Fix value of FAILURE_ENDPOINT header
Added:
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelFailureEndpointTest.java
Modified:
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastNoStopOnExceptionTest.java
Modified:
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java?rev=1303408&r1=1303407&r2=1303408&view=diff
==============================================================================
---
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
(original)
+++
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/TryProcessor.java
Wed Mar 21 14:42:25 2012
@@ -285,7 +285,9 @@ public class TryProcessor extends Servic
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);
}
// store the last to endpoint as the failure endpoint
- exchange.setProperty(Exchange.FAILURE_ENDPOINT,
exchange.getProperty(Exchange.TO_ENDPOINT));
+ if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
+ exchange.setProperty(Exchange.FAILURE_ENDPOINT,
exchange.getProperty(Exchange.TO_ENDPOINT));
+ }
boolean sync = super.processNext(exchange, new AsyncCallback() {
public void done(boolean doneSync) {
@@ -294,8 +296,10 @@ public class TryProcessor extends Servic
return;
}
- // set exception back on exchange
- if (e != null) {
+ if (e == null) {
+ exchange.removeProperty(Exchange.FAILURE_ENDPOINT);
+ } else {
+ // set exception back on exchange
exchange.setException(e);
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);
}
@@ -308,8 +312,10 @@ public class TryProcessor extends Servic
});
if (sync) {
- // set exception back on exchange
- if (e != null) {
+ if (e == null) {
+ exchange.removeProperty(Exchange.FAILURE_ENDPOINT);
+ } else {
+ // set exception back on exchange
exchange.setException(e);
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, e);
}
@@ -348,7 +354,9 @@ public class TryProcessor extends Servic
}
// store the last to endpoint as the failure endpoint
- exchange.setProperty(Exchange.FAILURE_ENDPOINT,
exchange.getProperty(Exchange.TO_ENDPOINT));
+ if (exchange.getProperty(Exchange.FAILURE_ENDPOINT) == null) {
+ exchange.setProperty(Exchange.FAILURE_ENDPOINT,
exchange.getProperty(Exchange.TO_ENDPOINT));
+ }
// give the rest of the pipeline another chance
exchange.setProperty(Exchange.EXCEPTION_CAUGHT, caught);
exchange.setException(null);
Modified:
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java?rev=1303408&r1=1303407&r2=1303408&view=diff
==============================================================================
---
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
(original)
+++
camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/processor/aggregate/UseLatestAggregationStrategy.java
Wed Mar 21 14:42:25 2012
@@ -61,6 +61,7 @@ public class UseLatestAggregationStrateg
// propagate exception from old exchange if there isn't already an
exception
if (newExchange.getException() == null) {
newExchange.setException(oldExchange.getException());
+ newExchange.setProperty(Exchange.FAILURE_ENDPOINT,
oldExchange.getProperty(Exchange.FAILURE_ENDPOINT));
}
}
Modified:
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastNoStopOnExceptionTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastNoStopOnExceptionTest.java?rev=1303408&r1=1303407&r2=1303408&view=diff
==============================================================================
---
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastNoStopOnExceptionTest.java
(original)
+++
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastNoStopOnExceptionTest.java
Wed Mar 21 14:42:25 2012
@@ -47,7 +47,7 @@ public class MulticastNoStopOnExceptionT
try {
template.sendBody("direct:start", "Kaboom");
- fail("Should thrown an exception");
+ fail("Should have thrown an exception");
} catch (CamelExecutionException e) {
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Forced", e.getCause().getMessage());
Added:
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelFailureEndpointTest.java
URL:
http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelFailureEndpointTest.java?rev=1303408&view=auto
==============================================================================
---
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelFailureEndpointTest.java
(added)
+++
camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/processor/MulticastParallelFailureEndpointTest.java
Wed Mar 21 14:42:25 2012
@@ -0,0 +1,88 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.impl.DefaultExchange;
+
+/**
+ * @version
+ */
+public class MulticastParallelFailureEndpointTest extends ContextTestSupport {
+
+ public void testMulticastParallel() throws Exception {
+ Exchange result = runTest("direct:run");
+ assertNotNull(result);
+ assertEquals("direct://a",
result.getProperty(Exchange.FAILURE_ENDPOINT));
+ }
+
+ public void testMulticastParallelWithTryCatch() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Bye World");
+
+ Exchange result = runTest("direct:start");
+
+ // try..catch block should clear handled exceptions
+ assertNotNull(result);
+ assertEquals(null, result.getProperty(Exchange.FAILURE_ENDPOINT));
+ }
+
+ public Exchange runTest(String uri) throws Exception {
+ MockEndpoint mr = getMockEndpoint("mock:run");
+ MockEndpoint ma = getMockEndpoint("mock:a");
+ MockEndpoint mb = getMockEndpoint("mock:b");
+ mr.expectedMessageCount(0);
+ ma.expectedMessageCount(0);
+ mb.expectedMessageCount(1);
+
+ Exchange request = new DefaultExchange(context, ExchangePattern.InOut);
+ request.getIn().setBody("Hello World");
+ Exchange result = template.send(uri, request);
+
+ assertMockEndpointsSatisfied();
+ return result;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start")
+ .doTry()
+ .to("direct:run")
+ .doCatch(IllegalArgumentException.class)
+ // ignore
+ .end()
+ .to("mock:result");
+
+ from("direct:run")
+ .multicast().parallelProcessing()
+ .to("direct:a", "direct:b")
+ .end()
+ .to("mock:run");
+
+ from("direct:a").throwException(new
IllegalArgumentException("Oops...")).to("mock:a");
+ from("direct:b").setBody(constant("Bye World")).to("mock:b");
+ }
+ };
+ }
+}