camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r706689 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/model/ components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/ components/camel-spring/src/test/resources/org/apache/camel/spring/pro...
Date Tue, 21 Oct 2008 17:35:13 GMT
Author: davsclaus
Date: Tue Oct 21 10:35:10 2008
New Revision: 706689

URL: http://svn.apache.org/viewvc?rev=706689&view=rev
Log:
CAMEL-1001: onException now supports setting handled as a boolean

Added:
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java
  (contents, props changed)
      - copied, changed from r706635, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetBodyTest.java
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderFailedException.java
  (with props)
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderService.java
  (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
  (contents, props changed)
      - copied, changed from r706635, activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setBody.xml
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java?rev=706689&r1=706688&r2=706689&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ExceptionType.java
Tue Oct 21 10:35:10 2008
@@ -31,6 +31,7 @@
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.Route;
+import org.apache.camel.model.language.ExpressionType;
 import org.apache.camel.builder.ErrorHandlerBuilder;
 import org.apache.camel.language.constant.ConstantLanguage;
 import org.apache.camel.processor.CatchProcessor;
@@ -54,6 +55,8 @@
     private List<String> exceptions = new ArrayList<String>();
     @XmlElement(name = "redeliveryPolicy", required = false)
     private RedeliveryPolicyType redeliveryPolicy;
+    @XmlElement(name = "handled", required = false)
+    private Boolean handled;
     @XmlElementRef
     private List<ProcessorType<?>> outputs = new ArrayList<ProcessorType<?>>();
     @XmlTransient
@@ -220,6 +223,11 @@
     }
 
     public Predicate getHandledPolicy() {
+        if (handled != null && handledPolicy == null) {
+            // will set the handled policy using fluent builder with the boolean value from
handled that
+            // is from the spring DSL where we currently only support setting either true|false
as policy
+            handled(handled);
+        }
         return handledPolicy;
     }
 

Copied: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java
(from r706635, activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetBodyTest.java)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java?p2=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java&p1=activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetBodyTest.java&r1=706635&r2=706689&rev=706689&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringSetBodyTest.java
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java
Tue Oct 21 10:35:10 2008
@@ -14,7 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.spring.processor;
+package org.apache.camel.spring.processor.onexception;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
@@ -22,18 +22,40 @@
 
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
-public class SpringSetBodyTest extends ContextTestSupport {
+/**
+ * Unit test for onException with the spring DSL.
+ */
+public class DeadLetterChannelHandledExampleTest extends ContextTestSupport {
+
+    public void testOrderOK() throws Exception {
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedBodiesReceived("Order OK");
+        result.expectedHeaderReceived("orderid", "123");
+
+        MockEndpoint error = getMockEndpoint("mock:error");
+        error.expectedMessageCount(0);
+
+        Object out = template.requestBodyAndHeader("direct:start", "Order: MacBook Pro",
"customerid", "444");
+        assertEquals("Order OK", out);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testOrderERROR() throws Exception {
+        MockEndpoint error = getMockEndpoint("mock:error");
+        error.expectedBodiesReceived("Order ERROR");
+        error.expectedHeaderReceived("orderid", "failed");
 
-    public void testSendAMessageWhosInBodyIsTransformed() throws Exception {
-        MockEndpoint resultEndpoint = getMockEndpoint("mock:end");
-        resultEndpoint.expectedBodiesReceived("Hello World!");
+        MockEndpoint result = getMockEndpoint("mock:result");
+        result.expectedMessageCount(0);
 
-        sendBody("direct:start", "Hello");
+        Object out = template.requestBodyAndHeader("direct:start", "Order: kaboom", "customerid",
"555");
+        assertEquals("Order ERROR", out);
 
-        resultEndpoint.assertIsSatisfied();
+        assertMockEndpointsSatisfied();
     }
 
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/setBody.xml");
+        return createSpringCamelContext(this, "/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml");
     }
-}
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/DeadLetterChannelHandledExampleTest.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderFailedException.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderFailedException.java?rev=706689&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderFailedException.java
(added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderFailedException.java
Tue Oct 21 10:35:10 2008
@@ -0,0 +1,28 @@
+/**
+ * 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.spring.processor.onexception;
+
+/**
+ * Exception thrown if the order can not be processed
+ */
+public class OrderFailedException extends Exception {
+
+    public OrderFailedException(String message) {
+        super(message);
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderFailedException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderFailedException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderService.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderService.java?rev=706689&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderService.java
(added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderService.java
Tue Oct 21 10:35:10 2008
@@ -0,0 +1,62 @@
+/**
+ * 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.spring.processor.onexception;
+
+import org.apache.camel.Body;
+import org.apache.camel.Headers;
+import org.apache.camel.OutHeaders;
+
+import java.util.Map;
+
+/**
+ * Order service as a plain POJO class
+ */
+public class OrderService {
+
+     /**
+         * This method handle our order input and return the order
+         *
+         * @param in      the in headers
+         * @param payload the in payload
+         * @param out     the out headers
+         * @return the out payload
+         * @throws OrderFailedException is thrown if the order can not be processed
+         */
+        public Object handleOrder(@Headers Map in, @Body String payload, @OutHeaders Map
out)
+            throws OrderFailedException {
+            out.put("customerid", in.get("customerid"));
+            if ("Order: kaboom".equals(payload)) {
+                throw new OrderFailedException("Can not order: kaboom");
+            } else {
+                out.put("orderid", "123");
+                return "Order OK";
+            }
+        }
+
+        /**
+         * This method creates the response to the caller if the order could not be processed
+         * @param in      the in headers
+         * @param payload the in payload
+         * @param out     the out headers
+         * @return the out payload
+         */
+        public Object orderFailed(@Headers Map in, @Body String payload, @OutHeaders Map
out) {
+            out.put("customerid", in.get("customerid"));
+            out.put("orderid", "failed");
+            return "Order ERROR";
+        }
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/onexception/OrderService.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
(from r706635, activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setBody.xml)
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml?p2=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml&p1=activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setBody.xml&r1=706635&r2=706689&rev=706689&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/setBody.xml
(original)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
Tue Oct 21 10:35:10 2008
@@ -22,16 +22,42 @@
        http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
     ">
 
-  <!-- START SNIPPET: example -->
-  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
-    <route>
-      <from uri="direct:start"/>
-      <setBody>
-        <simple>${in.body} World!</simple>
-      </setBody>
-      <to uri="mock:end"/>
-    </route>
-  </camelContext>
-  <!-- END SNIPPET: example -->
+    <!-- START SNIPPET: e1 -->
+
+    <!-- this is our POJO bean with our business logic defined as a plain spring bean
-->
+    <bean id="orderService" class="org.apache.camel.spring.processor.onexception.OrderService"/>
+
+    <!-- this is the camel context where we define the routes -->
+    <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+
+        <route>
+            <!-- the route -->
+            <from uri="direct:start"/>
+
+            <!-- we must configure the on exception within the route, as opposed to Java
DSL where we can do this outside -->
+            <onException>
+                <!-- the exception is full qualified names as plain strings -->
+                <!-- there can be more just add a 2nd, 3rd exception element (unbounded)
-->
+                <exception>org.apache.camel.spring.processor.onexception.OrderFailedException</exception>
+                <!-- we can set the redelivery policy here as well -->
+                <redeliveryPolicy>
+                    <maximumRedeliveries>1</maximumRedeliveries>
+                </redeliveryPolicy>
+                <!-- mark this as handled. Spring DSL only support boolean types -->
+                <handled>true</handled>
+                <!-- let our order service handle this exception, call the orderFailed
method -->
+                <bean ref="orderService" method="orderFailed"/>
+                <!-- and since this is a unit test we use mock for assertions -->
+                <to uri="mock:error"/>
+            </onException>
+
+            <!-- in the normal route then route to our order service and call handleOrder
method -->
+            <bean ref="orderService" method="handleOrder"/>
+            <!-- and since this is a unit test we use mock for assertions -->
+            <to uri="mock:result"/>
+        </route>
+
+    </camelContext>
+    <!-- END SNIPPET: e1 -->
 
 </beans>

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
------------------------------------------------------------------------------
    svn:mergeinfo = 

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/deadLetterChannelHandledExampleTest.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message