Author: davsclaus
Date: Sun Mar 11 17:22:08 2012
New Revision: 1299399

URL: http://svn.apache.org/viewvc?rev=1299399&view=rev
Log:
CAMEL-5007: Fixed using redelivery policy in OSGi blueprint XML DSL.

Added:
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint6Test.java
      - copied, changed from r1299380, 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint5Test.java
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint7Test.java
    
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MyErrorBean.java
    
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-24.xml
      - copied, changed from r1299380, 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-23.xml
    
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-25.xml
Modified:
    
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
    
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
    
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
    
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/cheese.properties

Modified: 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java?rev=1299399&r1=1299398&r2=1299399&view=diff
==============================================================================
--- 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
 (original)
+++ 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelContextFactoryBean.java
 Sun Mar 11 17:22:08 2012
@@ -101,7 +101,7 @@ public class CamelContextFactoryBean ext
     private ShutdownRunningTask shutdownRunningTask;
     @XmlAttribute(required = false)
     @Deprecated
-    private Boolean lazyLoadTypeConverters = Boolean.FALSE;
+    private Boolean lazyLoadTypeConverters;
     @XmlElement(name = "properties", required = false)
     private PropertiesDefinition properties;
     @XmlElement(name = "propertyPlaceholder", type = 
CamelPropertyPlaceholderDefinition.class, required = false)
@@ -320,7 +320,8 @@ public class CamelContextFactoryBean ext
 
     @Deprecated
     public Boolean getLazyLoadTypeConverters() {
-        return lazyLoadTypeConverters;
+        // use false by default
+        return lazyLoadTypeConverters != null ? lazyLoadTypeConverters : 
Boolean.FALSE;
     }
 
     @Deprecated

Modified: 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java?rev=1299399&r1=1299398&r2=1299399&view=diff
==============================================================================
--- 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
 (original)
+++ 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/CamelErrorHandlerFactoryBean.java
 Sun Mar 11 17:22:08 2012
@@ -32,9 +32,7 @@ import org.apache.camel.builder.LoggingE
 import org.apache.camel.core.xml.AbstractCamelFactoryBean;
 import org.apache.camel.model.RedeliveryPolicyDefinition;
 import org.apache.camel.processor.RedeliveryPolicy;
-import org.apache.camel.util.CamelContextHelper;
 import org.osgi.service.blueprint.container.BlueprintContainer;
-import org.osgi.service.blueprint.container.NoSuchComponentException;
 
 @XmlRootElement(name = "errorHandler")
 @XmlAccessorType(XmlAccessType.FIELD)
@@ -78,9 +76,7 @@ public class CamelErrorHandlerFactoryBea
                 
handler.setRedeliveryPolicy(redeliveryPolicy.createRedeliveryPolicy(getCamelContext(),
 null));
             }
             if (redeliveryPolicyRef != null) {
-                // lookup redelivery
-                RedeliveryPolicy policy = 
CamelContextHelper.mandatoryLookup(getCamelContext(), redeliveryPolicyRef, 
RedeliveryPolicy.class);
-                handler.setRedeliveryPolicy(policy);
+                handler.setRedeliveryPolicy(lookup(redeliveryPolicyRef, 
RedeliveryPolicy.class));
             }
             if (onRedeliveryRef != null) {
                 handler.setOnRedelivery(lookup(onRedeliveryRef, 
Processor.class));
@@ -120,11 +116,7 @@ public class CamelErrorHandlerFactoryBea
     }
 
     protected <T> T lookup(String name, Class<T> type) {
-        try {
-            return type.cast(blueprintContainer.getComponentInstance(name));
-        } catch (NoSuchComponentException e) {
-            return null;
-        }
+        return type.cast(blueprintContainer.getComponentInstance(name));
     }
 
 }

Modified: 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java?rev=1299399&r1=1299398&r2=1299399&view=diff
==============================================================================
--- 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
 (original)
+++ 
camel/trunk/components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/CamelNamespaceHandler.java
 Sun Mar 11 17:22:08 2012
@@ -203,9 +203,10 @@ public class CamelNamespaceHandler imple
         ctx.setInitMethod("init");
         ctx.setDestroyMethod("destroy");
 
-        // Register objects
-        registerBeans(context, contextId, ccfb.getEndpoints());
+        // Register factory beans
         registerBeans(context, contextId, ccfb.getThreadPools());
+        registerBeans(context, contextId, ccfb.getEndpoints());
+        registerBeans(context, contextId, ccfb.getRedeliveryPolicies());
         registerBeans(context, contextId, ccfb.getBeans());
 
         // Register processors

Copied: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint6Test.java
 (from r1299380, 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint5Test.java)
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint6Test.java?p2=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint6Test.java&p1=camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint5Test.java&r1=1299380&r2=1299399&rev=1299399&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint5Test.java
 (original)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint6Test.java
 Sun Mar 11 17:22:08 2012
@@ -34,26 +34,21 @@ import static org.ops4j.pax.swissbox.tin
  * @version 
  */
 @RunWith(JUnit4TestRunner.class)
-public class CamelBlueprint5Test extends OSGiBlueprintTestSupport {
+public class CamelBlueprint6Test extends OSGiBlueprintTestSupport {
 
     @Test
-    public void testTryCatch() throws Exception {
-        getInstalledBundle("CamelBlueprintTestBundle23").start();
-        CamelContext ctx = getOsgiService(CamelContext.class, 
"(camel.context.symbolicname=CamelBlueprintTestBundle23)", 10000);
+    public void testErrorHandler() throws Exception {
+        getInstalledBundle("CamelBlueprintTestBundle24").start();
+        CamelContext ctx = getOsgiService(CamelContext.class, 
"(camel.context.symbolicname=CamelBlueprintTestBundle24)", 10000);
 
         ProducerTemplate template = ctx.createProducerTemplate();
 
-        MockEndpoint mock = ctx.getEndpoint("mock:result", MockEndpoint.class);
+        MockEndpoint mock = ctx.getEndpoint("mock:dead", MockEndpoint.class);
         mock.expectedMessageCount(1);
 
-        MockEndpoint error = ctx.getEndpoint("mock:error", MockEndpoint.class);
-        error.expectedMessageCount(1);
-
         template.sendBody("direct:start", "Hello World");
-        template.sendBody("direct:start", "Kaboom");
 
         mock.assertIsSatisfied();
-        error.assertIsSatisfied();
         template.stop();
     }
 
@@ -64,9 +59,10 @@ public class CamelBlueprint5Test extends
                 getDefaultCamelKarafOptions(),
 
                 bundle(newBundle()
-                        .add("OSGI-INF/blueprint/test.xml", 
OSGiBlueprintTestSupport.class.getResource("blueprint-23.xml"))
-                        .set(Constants.BUNDLE_SYMBOLICNAME, 
"CamelBlueprintTestBundle23")
-                        .add(MyException.class)
+                        .add("OSGI-INF/blueprint/test.xml", 
OSGiBlueprintTestSupport.class.getResource("blueprint-24.xml"))
+                        .set(Constants.BUNDLE_SYMBOLICNAME, 
"CamelBlueprintTestBundle24")
+                        
.add("org/apache/camel/component/properties/cheese.properties", 
OSGiBlueprintTestSupport.class.getResource("cheese.properties"))
+                        .add(MyErrorBean.class)
                         .build()).noStart(),
 
                 // using the features to install the camel components

Added: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint7Test.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint7Test.java?rev=1299399&view=auto
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint7Test.java
 (added)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/CamelBlueprint7Test.java
 Sun Mar 11 17:22:08 2012
@@ -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.itest.osgi.blueprint;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.ops4j.pax.exam.Option;
+import org.ops4j.pax.exam.junit.Configuration;
+import org.ops4j.pax.exam.junit.JUnit4TestRunner;
+import org.osgi.framework.Constants;
+
+import static org.ops4j.pax.exam.OptionUtils.combine;
+import static org.ops4j.pax.exam.container.def.PaxRunnerOptions.scanFeatures;
+import static org.ops4j.pax.swissbox.tinybundles.core.TinyBundles.newBundle;
+
+/**
+ * @version 
+ */
+@RunWith(JUnit4TestRunner.class)
+public class CamelBlueprint7Test extends OSGiBlueprintTestSupport {
+
+    @Test
+    public void testErrorHandler() throws Exception {
+        getInstalledBundle("CamelBlueprintTestBundle25").start();
+        CamelContext ctx = getOsgiService(CamelContext.class, 
"(camel.context.symbolicname=CamelBlueprintTestBundle25)", 10000);
+
+        ProducerTemplate template = ctx.createProducerTemplate();
+
+        MockEndpoint mock = ctx.getEndpoint("mock:dead", MockEndpoint.class);
+        mock.expectedMessageCount(1);
+
+        template.sendBody("direct:start", "Hello World");
+
+        mock.assertIsSatisfied();
+        template.stop();
+    }
+
+    @Configuration
+    public static Option[] configure() throws Exception {
+
+        Option[] options = combine(
+                getDefaultCamelKarafOptions(),
+
+                bundle(newBundle()
+                        .add("OSGI-INF/blueprint/test.xml", 
OSGiBlueprintTestSupport.class.getResource("blueprint-25.xml"))
+                        .set(Constants.BUNDLE_SYMBOLICNAME, 
"CamelBlueprintTestBundle25")
+                        
.add("org/apache/camel/component/properties/cheese.properties", 
OSGiBlueprintTestSupport.class.getResource("cheese.properties"))
+                        .add(MyErrorBean.class)
+                        .build()).noStart(),
+
+                // using the features to install the camel components
+                scanFeatures(getCamelKarafFeatureUrl(),
+                        "camel-blueprint"));
+
+        return options;
+    }
+
+}

Added: 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MyErrorBean.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MyErrorBean.java?rev=1299399&view=auto
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MyErrorBean.java
 (added)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/blueprint/MyErrorBean.java
 Sun Mar 11 17:22:08 2012
@@ -0,0 +1,35 @@
+/**
+ * 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.itest.osgi.blueprint;
+
+/**
+ *
+ */
+public class MyErrorBean {
+
+    private int counter;
+
+    public void doSomething(String body) {
+        counter++;
+        throw new IllegalArgumentException("Damn");
+    }
+
+    public int getCounter() {
+        return counter;
+    }
+
+}

Copied: 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-24.xml
 (from r1299380, 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-23.xml)
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-24.xml?p2=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-24.xml&p1=camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-23.xml&r1=1299380&r2=1299399&rev=1299399&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-23.xml
 (original)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-24.xml
 Sun Mar 11 17:22:08 2012
@@ -17,26 +17,19 @@
 -->
 <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>
 
-  <bean id="damn" class="org.apache.camel.itest.osgi.blueprint.MyException"/>
+  <bean id="errorBean" 
class="org.apache.camel.itest.osgi.blueprint.MyErrorBean"/>
+
+  <camelContext errorHandlerRef="dlc" 
xmlns="http://camel.apache.org/schema/blueprint";>
+    <propertyPlaceholder id="properties"
+                         
location="classpath:org/apache/camel/component/properties/cheese.properties"/>
+
+    <errorHandler id="dlc" deadLetterUri="mock:dead" type="DeadLetterChannel" 
redeliveryPolicyRef="myRedelivery"/>
+
+    <redeliveryPolicyProfile id="myRedelivery" maximumRedeliveries="{{max}}" 
redeliveryDelay="0"/>
 
-  <camelContext xmlns="http://camel.apache.org/schema/blueprint";>
     <route>
       <from uri="direct:start"/>
-      <doTry>
-        <choice>
-          <when>
-            <simple>${body} == 'Kaboom'</simple>
-            <throwException ref="damn"/>
-          </when>
-          <otherwise>
-            <to uri="mock:result"/>
-          </otherwise>
-        </choice>
-        <doCatch>
-          
<exception>org.apache.camel.itest.osgi.blueprint.MyException</exception>
-          <to uri="mock:error"/>
-        </doCatch>
-      </doTry>
+      <bean ref="errorBean"/>
     </route>
   </camelContext>
 

Added: 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-25.xml
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-25.xml?rev=1299399&view=auto
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-25.xml
 (added)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/blueprint-25.xml
 Sun Mar 11 17:22:08 2012
@@ -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.
+-->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>
+
+  <bean id="errorBean" 
class="org.apache.camel.itest.osgi.blueprint.MyErrorBean"/>
+
+  <camelContext errorHandlerRef="dlc" 
xmlns="http://camel.apache.org/schema/blueprint";>
+    <propertyPlaceholder id="properties"
+                         
location="classpath:org/apache/camel/component/properties/cheese.properties"/>
+
+    <errorHandler id="dlc" deadLetterUri="mock:dead" type="DeadLetterChannel">
+      <redeliveryPolicy maximumRedeliveries="{{max}}" redeliveryDelay="0"/>
+    </errorHandler>
+
+    <route>
+      <from uri="direct:start"/>
+      <bean ref="errorBean"/>
+    </route>
+  </camelContext>
+
+</blueprint>

Modified: 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/cheese.properties
URL: 
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/cheese.properties?rev=1299399&r1=1299398&r2=1299399&view=diff
==============================================================================
--- 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/cheese.properties
 (original)
+++ 
camel/trunk/tests/camel-itest-osgi/src/test/resources/org/apache/camel/itest/osgi/blueprint/cheese.properties
 Sun Mar 11 17:22:08 2012
@@ -1,3 +1,20 @@
-input=direct:start
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
 
+input=direct:start
+max=3
 


Reply via email to