Author: davsclaus
Date: Mon Nov 23 07:43:06 2009
New Revision: 883262
URL: http://svn.apache.org/viewvc?rev=883262&view=rev
Log:
CAMEL-2212: InterceptSendToEndpoint does not send to intended endpoint in case
of exception or failure. Help simulate errors.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToExceptionTest.java
(with props)
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToFaultTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java?rev=883262&r1=883261&r2=883262&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/InterceptSendToEndpoint.java
Mon Nov 23 07:43:06 2009
@@ -116,16 +116,24 @@
exchange.getIn().setHeader(Exchange.INTERCEPTED_ENDPOINT,
delegate.getEndpointUri());
detour.process(exchange);
- // copy OUT to IN
- if (exchange.hasOut()) {
- // replace OUT with IN as detour changed something
- exchange.setIn(exchange.getOut());
- exchange.setOut(null);
- }
if (!skip) {
- // route to original destination
- producer.process(exchange);
+ if (!exchange.isFailed()) {
+ if (exchange.hasOut()) {
+ // replace OUT with IN as detour changed something
+ exchange.setIn(exchange.getOut());
+ exchange.setOut(null);
+ }
+
+ // route to original destination
+ producer.process(exchange);
+ } else {
+ // exception is failed so do not route to original
destination as we can use this to simulate errors
+ // caused from the intended destination
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Exchange has failed so skip sending to
original intended destination: " + getEndpointUri() + " for exchange: " +
exchange);
+ }
+ }
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Stop() means skip sending exchange to
original intended destination: " + getEndpointUri() + " for exchange: " +
exchange);
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToExceptionTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToExceptionTest.java?rev=883262&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToExceptionTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToExceptionTest.java
Mon Nov 23 07:43:06 2009
@@ -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.processor.intercept;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class InterceptSendToExceptionTest extends ContextTestSupport {
+
+ public void testInterceptSendToException() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ try {
+ template.sendBody("direct:start", "Hello World");
+ fail("Should have thrown an exception");
+ } catch (CamelExecutionException e) {
+ IllegalArgumentException cause =
assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
+ assertEquals("Damn", cause.getMessage());
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ interceptSendToEndpoint("mock:foo").throwException(new
IllegalArgumentException("Damn"));
+
+ from("direct:start").to("mock:foo").to("mock:result");
+ }
+ };
+ }
+}
+
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToExceptionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToExceptionTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToFaultTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToFaultTest.java?rev=883262&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToFaultTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToFaultTest.java
Mon Nov 23 07:43:06 2009
@@ -0,0 +1,48 @@
+/**
+ * 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.intercept;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class InterceptSendToFaultTest extends ContextTestSupport {
+
+ public void testInterceptSendToFault() throws Exception {
+ getMockEndpoint("mock:foo").expectedMessageCount(0);
+ getMockEndpoint("mock:result").expectedMessageCount(0);
+
+ String out = template.requestBody("direct:start", "Hello World",
String.class);
+ assertEquals("Damn", out);
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
interceptSendToEndpoint("mock:foo").setFaultBody(constant("Damn"));
+
+ from("direct:start").to("mock:foo").transform(constant("Bye
World")).to("mock:result");
+ }
+ };
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToFaultTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/intercept/InterceptSendToFaultTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date