Author: davsclaus
Date: Thu Nov 19 13:31:34 2009
New Revision: 882139

URL: http://svn.apache.org/viewvc?rev=882139&view=rev
Log:
CAMEL-2063: DeadLetterEndpointUri is validate before starting to prevent 
endpoint failure at runtime.

Added:
    
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelBuilderWithInvalidDeadLetterUriTest.java
   (with props)
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java
      - copied, changed from r882120, 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.java
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
   (with props)
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.xml
      - copied, changed from r882120, 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.xml
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.xml
   (with props)
Modified:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
    
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java?rev=882139&r1=882138&r2=882139&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/BuilderSupport.java
 Thu Nov 19 13:31:34 2009
@@ -328,7 +328,7 @@
 
     /**
      * <a href="http://camel.apache.org/dead-letter-channel.html";>Dead Letter 
Channel EIP:</a>
-     * is a error handler for handling messages that could not be delivered to 
it's intented destination.
+     * is a error handler for handling messages that could not be delivered to 
it's intended destination.
      *
      * @param deadLetterUri  uri to the dead letter endpoint storing dead 
messages
      * @return the builder
@@ -339,7 +339,7 @@
 
     /**
      * <a href="http://camel.apache.org/dead-letter-channel.html";>Dead Letter 
Channel EIP:</a>
-     * is a error handler for handling messages that could not be delivered to 
it's intented destination.
+     * is a error handler for handling messages that could not be delivered to 
it's intended destination.
      *
      * @param deadLetterEndpoint  dead letter endpoint storing dead messages
      * @return the builder

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java?rev=882139&r1=882138&r2=882139&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/builder/DeadLetterChannelBuilder.java
 Thu Nov 19 13:31:34 2009
@@ -17,17 +17,16 @@
 package org.apache.camel.builder;
 
 import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.Expression;
 import org.apache.camel.LoggingLevel;
+import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.processor.DeadLetterChannel;
 import org.apache.camel.processor.Logger;
-import org.apache.camel.processor.RecipientList;
 import org.apache.camel.processor.RedeliveryPolicy;
 import org.apache.camel.processor.SendProcessor;
 import org.apache.camel.spi.RouteContext;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.commons.logging.LogFactory;
 
 /**
@@ -52,6 +51,8 @@
     }
 
     public Processor createErrorHandler(RouteContext routeContext, Processor 
processor) throws Exception {
+        validateDeadLetterUri(routeContext);
+
         DeadLetterChannel answer = new DeadLetterChannel(processor, 
getLogger(), getOnRedelivery(), getRedeliveryPolicy(),
                 getHandledPolicy(), getExceptionPolicyStrategy(), 
getFailureProcessor(), getDeadLetterUri(),
                 isUseOriginalMessage());
@@ -69,20 +70,21 @@
 
     public Processor getFailureProcessor() {
         if (failureProcessor == null) {
-            if (deadLetter != null) {
-                failureProcessor = new SendProcessor(deadLetter);
-            } else {
-                // use a recipient list since we only have an uri for the 
endpoint
-                failureProcessor = new RecipientList(new Expression() {
-                    public <T> T evaluate(Exchange exchange, Class<T> type) {
-                        return 
exchange.getContext().getTypeConverter().convertTo(type, deadLetterUri);
-                    }
-                });
-            }
+            failureProcessor = new SendProcessor(deadLetter);
         }
         return failureProcessor;
     }
 
+    protected void validateDeadLetterUri(RouteContext routeContext) {
+        if (deadLetter == null) {
+            ObjectHelper.notEmpty(deadLetterUri, "deadLetterUri", this);
+            deadLetter = 
routeContext.getCamelContext().getEndpoint(deadLetterUri);
+            if (deadLetter == null) {
+                throw new NoSuchEndpointException(deadLetterUri);
+            }
+        }
+    }
+
     protected Predicate createHandledPolicy() {
         // should be handled by default for dead letter channel
         return 
PredicateBuilder.toPredicate(ExpressionBuilder.constantExpression(true));

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelBuilderWithInvalidDeadLetterUriTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelBuilderWithInvalidDeadLetterUriTest.java?rev=882139&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelBuilderWithInvalidDeadLetterUriTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelBuilderWithInvalidDeadLetterUriTest.java
 Thu Nov 19 13:31:34 2009
@@ -0,0 +1,67 @@
+/**
+ * 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.NoSuchEndpointException;
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision$
+ */
+public class DeadLetterChannelBuilderWithInvalidDeadLetterUriTest extends 
ContextTestSupport {
+
+    public void testInvalidUri() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    errorHandler(deadLetterChannel("xxx"));
+
+                    from("direct:start").to("mock:foo");
+                }
+            });
+
+            fail("Should have thrown an exception");
+        } catch (NoSuchEndpointException e) {
+            assertEquals("No endpoint could be found for: xxx, please check 
your classpath contains the needed camel component jar.", e.getMessage());
+        }
+    }
+
+    public void testInvalidOption() throws Exception {
+        try {
+            context.addRoutes(new RouteBuilder() {
+                @Override
+                public void configure() throws Exception {
+                    errorHandler(deadLetterChannel("mock:error?foo=bar"));
+
+                    from("direct:start").to("mock:foo");
+                }
+            });
+
+            fail("Should have thrown an exception");
+        } catch (ResolveEndpointFailedException e) {
+            assertTrue(e.getMessage().endsWith("Unknown 
parameters=[{foo=bar}]"));
+        }
+    }
+
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
+}

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelBuilderWithInvalidDeadLetterUriTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/processor/DeadLetterChannelBuilderWithInvalidDeadLetterUriTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java
 (from r882120, 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.java&r1=882120&r2=882139&rev=882139&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.java
 Thu Nov 19 13:31:34 2009
@@ -16,26 +16,34 @@
  */
 package org.apache.camel.spring.processor;
 
+import org.apache.camel.NoSuchEndpointException;
 import org.apache.camel.spring.SpringTestSupport;
+import org.junit.Test;
 import org.springframework.context.support.AbstractXmlApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
 /**
  * @version $Revision$
  */
-public class SpringDeadLetterChannelHandledPolicyTest extends 
SpringTestSupport {
+public class SpringDeadLetterChannelInvalidDeadLetterUriTest extends 
SpringTestSupport {
 
     protected AbstractXmlApplicationContext createApplicationContext() {
-        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.xml");
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.xml");
     }
 
-    public void testHandled() throws Exception {
-        getMockEndpoint("mock:dead").expectedBodiesReceived("Hello World");
-
-        template.sendBody("direct:start", "Hello World");
+    @Override
+    protected void setUp() throws Exception {
+        try {
+            super.setUp();
+            fail("Should have thrown an exception");
+        } catch (NoSuchEndpointException e) {
+            assertEquals("No endpoint could be found for: xxx, please check 
your classpath contains the needed camel component jar.", e.getMessage());
+        }
+    }
 
-        // as its handled no exception is thrown to the client
-        assertMockEndpointsSatisfied();
+    @Test
+    public void testInvalidUri() throws Exception {
+        // noop
     }
 
-}
+}
\ No newline at end of file

Added: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java?rev=882139&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.java
 Thu Nov 19 13:31:34 2009
@@ -0,0 +1,49 @@
+/**
+ * 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;
+
+import org.apache.camel.ResolveEndpointFailedException;
+import org.apache.camel.spring.SpringTestSupport;
+import org.junit.Test;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class SpringDeadLetterChannelInvalidOptionDeadLetterUriTest extends 
SpringTestSupport {
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new 
ClassPathXmlApplicationContext("org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.xml");
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        try {
+            super.setUp();
+            fail("Should have thrown an exception");
+        } catch (ResolveEndpointFailedException e) {
+            assertTrue(e.getMessage().endsWith("Unknown 
parameters=[{foo=bar}]"));
+        }
+    }
+
+    @Test
+    public void testInvalidOptionUri() throws Exception {
+        // noop
+    }
+
+}
\ No newline at end of file

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

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

Copied: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.xml
 (from r882120, 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.xml)
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.xml&r1=882120&r2=882139&rev=882139&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelHandledPolicyTest.xml
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidDeadLetterUriTest.xml
 Thu Nov 19 13:31:34 2009
@@ -22,29 +22,15 @@
        http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <!-- START SNIPPET: e1 -->
     <bean id="myDLC" class="org.apache.camel.builder.DeadLetterChannelBuilder">
-        <!-- move failed messages to the mock:dead dead letter queue -->
-        <property name="deadLetterUri" value="mock:dead"/>
-        <!-- we mark all exchanges as handled when they are moved to the dead 
letter queue, so the client
-             does not receive an exception -->
-        <property name="handled" value="true"/>
-        <property name="redeliveryPolicy" ref="myRedelivery"/>
+        <!-- invalid uri -->
+        <property name="deadLetterUri" value="xxx"/>
     </bean>
 
-    <bean id="myRedelivery" 
class="org.apache.camel.processor.RedeliveryPolicy">
-        <property name="maximumRedeliveries" value="2"/>
-        <property name="redeliverDelay" value="0"/>
-        <property name="logStackTrace" value="false"/>
-    </bean>
-    <!-- END SNIPPET: e1 -->
-
-    <bean id="myThrowProcessor" 
class="org.apache.camel.processor.DeadLetterChannelHandledPolicyTest$MyThrowExceptionProcessor"/>
-
     <camelContext id="camel" errorHandlerRef="myDLC" 
xmlns="http://camel.apache.org/schema/spring";>
         <route>
             <from uri="direct:start"/>
-            <process ref="myThrowProcessor"/>
+            <to uri="mock:result"/>
         </route>
     </camelContext>
 </beans>

Added: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.xml?rev=882139&view=auto
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.xml
 (added)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/SpringDeadLetterChannelInvalidOptionDeadLetterUriTest.xml
 Thu Nov 19 13:31:34 2009
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans";
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+       xsi:schemaLocation="
+       http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       http://camel.apache.org/schema/spring 
http://camel.apache.org/schema/spring/camel-spring.xsd
+    ">
+
+    <bean id="myDLC" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+        <!-- invalid option in mock uri -->
+        <property name="deadLetterUri" value="mock:error?foo=bar"/>
+    </bean>
+
+    <camelContext id="camel" errorHandlerRef="myDLC" 
xmlns="http://camel.apache.org/schema/spring";>
+        <route>
+            <from uri="direct:start"/>
+            <to uri="mock:result"/>
+        </route>
+    </camelContext>
+</beans>

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

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

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

Modified: 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml?rev=882139&r1=882138&r2=882139&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/onexception/exceptionBuilderWithRetryLoggingLevelSet.xml
 Thu Nov 19 13:31:34 2009
@@ -32,6 +32,7 @@
       class="org.apache.camel.builder.MyExceptionThrowingProcessor" />
 
     <bean id="dlc" class="org.apache.camel.builder.DeadLetterChannelBuilder">
+      <property name="deadLetterUri" value="mock:dead" />
       <property name="logger" ref="theCustomLogger" />
     </bean>
 


Reply via email to