Author: ningjiang
Date: Mon Mar 21 08:10:35 2011
New Revision: 1083696
URL: http://svn.apache.org/viewvc?rev=1083696&view=rev
Log:
CAMEL-3791,CAMLE-3792 Fix some issues of ErrorHandler useOriginalMessage option
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java
(with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java?rev=1083696&r1=1083695&r2=1083696&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/RedeliveryErrorHandler.java
Mon Mar 21 08:10:35 2011
@@ -591,18 +591,23 @@ public abstract class RedeliveryErrorHan
// is the a failure processor to process the Exchange
if (processor != null) {
- // reset cached streams so they can be read again
- MessageHelper.resetStreamCache(exchange.getIn());
-
// prepare original IN body if it should be moved instead of
current body
if (data.useOriginalInMessage) {
if (log.isTraceEnabled()) {
log.trace("Using the original IN message instead of
current");
}
-
Message original =
exchange.getUnitOfWork().getOriginalInMessage();
exchange.setIn(original);
+ if (exchange.hasOut()) {
+ if (log.isTraceEnabled()) {
+ log.trace("Removing the out message to avoid some
uncertain behavior");
+ }
+ exchange.setOut(null);
+ }
}
+
+ // reset cached streams so they can be read again
+ MessageHelper.resetStreamCache(exchange.getIn());
if (log.isTraceEnabled()) {
log.trace("Failure processor " + processor + " is processing
Exchange: " + exchange);
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java?rev=1083696&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java
Mon Mar 21 08:10:35 2011
@@ -0,0 +1,100 @@
+/**
+ * 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.onexception;
+
+import java.io.File;
+import java.io.InputStream;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.converter.stream.FileInputStreamCache;
+
+/**
+ * @version
+ */
+public class OnExceptionUseOriginalMessageTest extends ContextTestSupport {
+
+ private static final String HELLO_WORLD = "Hello World";
+
+ private static final String TEST_FILE =
"src/test/resources/org/apache/camel/converter/stream/test.xml";
+
+ public void testOnExceptionError() throws Exception {
+ getMockEndpoint("mock:middle").expectedBodiesReceived(HELLO_WORLD);
+
getMockEndpoint("mock:middle").message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
+ getMockEndpoint("mock:end").expectedBodiesReceived(HELLO_WORLD);
+
getMockEndpoint("mock:end").message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
+
+ template.sendBody("direct:a", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ public void testOnExceptionStreamReset() throws Exception {
+
+ getMockEndpoint("mock:middle").expectedMessageCount(1);
+
getMockEndpoint("mock:middle").message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
+ getMockEndpoint("mock:end").expectedMessageCount(1);
+
getMockEndpoint("mock:end").message(0).property(Exchange.EXCEPTION_CAUGHT).isInstanceOf(IllegalArgumentException.class);
+
+ File file = new File(TEST_FILE).getAbsoluteFile();
+ FileInputStreamCache cache = new FileInputStreamCache(file);
+
+ template.sendBody("direct:a", cache);
+
+ assertMockEndpointsSatisfied();
+
+ // To make sure we can read something from the InputStream
+ String result =
getMockEndpoint("mock:end").getExchanges().get(0).getIn().getBody(String.class);
+ assertTrue(result.contains("<firstName>James</firstName>"));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+
+
onException(IllegalArgumentException.class).useOriginalMessage().handled(true).to("seda:test");
+
+ from("direct:a").inOut()
+ .process(new MyProcessor());
+
+ from("seda:test")
+ .to("mock:middle")
+ .to("mock:end");
+
+
+ }
+ };
+ }
+
+ public static class MyProcessor implements Processor {
+
+ @Override
+ public void process(Exchange exchange) throws Exception {
+ String request = exchange.getIn().getBody(String.class);
+ if (!request.equals(HELLO_WORLD)) {
+ exchange.getIn().setBody(HELLO_WORLD);
+ }
+ // set the out message
+ exchange.getOut().setBody("Error body");
+ throw new IllegalArgumentException("Get a wrong message");
+ }
+ }
+}
\ No newline at end of file
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionUseOriginalMessageTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date