camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1187893 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/language/bean/BeanExpression.java test/java/org/apache/camel/processor/onexception/OnExceptionWhenSimpleOgnlTest.java
Date Sun, 23 Oct 2011 14:22:35 GMT
Author: davsclaus
Date: Sun Oct 23 14:22:34 2011
New Revision: 1187893

URL: http://svn.apache.org/viewvc?rev=1187893&view=rev
Log:
CAMEL-4513: Fixed simple ognl on exception function.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWhenSimpleOgnlTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java?rev=1187893&r1=1187892&r2=1187893&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/bean/BeanExpression.java
Sun Oct 23 14:22:34 2011
@@ -154,6 +154,9 @@ public class BeanExpression implements E
             try {
                 // copy the original exchange to avoid side effects on it
                 Exchange resultExchange = exchange.copy();
+                // remove any existing exception in case we do OGNL on the exception
+                resultExchange.setException(null);
+
                 // force to use InOut to retrieve the result on the OUT message
                 resultExchange.setPattern(ExchangePattern.InOut);
                 processor.process(resultExchange);
@@ -195,6 +198,8 @@ public class BeanExpression implements E
         public void process(Exchange exchange) throws Exception {
             // copy the original exchange to avoid side effects on it
             Exchange resultExchange = exchange.copy();
+            // remove any existing exception in case we do OGNL on the exception
+            resultExchange.setException(null);
             // force to use InOut to retrieve the result on the OUT message
             resultExchange.setPattern(ExchangePattern.InOut);
             // do not propagate any method name when using OGNL, as with OGNL we

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWhenSimpleOgnlTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWhenSimpleOgnlTest.java?rev=1187893&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWhenSimpleOgnlTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/onexception/OnExceptionWhenSimpleOgnlTest.java
Sun Oct 23 14:22:34 2011
@@ -0,0 +1,75 @@
+/**
+ * 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 org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ *
+ */
+public class OnExceptionWhenSimpleOgnlTest extends ContextTestSupport {
+
+    public void testOnExceptionWhenSimpleOgnl() throws Exception {
+        getMockEndpoint("mock:three").expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                onException(MyException.class)
+                    // OGNL on the exception function in the simple language
+                    .onWhen(simple("${exception.info.state} == 3"))
+                        .handled(true)
+                        .to("mock:three");
+
+                from("direct:start")
+                    .throwException(new MyException(3));
+            }
+        };
+    }
+
+    public static final class MyException extends Exception {
+        private final MyExceptionInfo info;
+
+        public MyException(int state) {
+            this.info = new MyExceptionInfo(state);
+        }
+
+        public MyExceptionInfo getInfo() {
+            return info;
+        }
+    }
+
+    public static final class MyExceptionInfo {
+        private final int state;
+
+        public MyExceptionInfo(int state) {
+            this.state = state;
+        }
+
+        public int getState() {
+            return state;
+        }
+    }
+}



Mime
View raw message