svn commit: r803062 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/handler/ test/java/org/apache/camel/spring/config/ test/resources/org/apache/camel/spring/config/

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r803062 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/handler/ test/java/org/apache/camel/spring/config/ test/resources/org/apache/camel/spring/config/

davsclaus-2
Author: davsclaus
Date: Tue Aug 11 11:10:48 2009
New Revision: 803062

URL: http://svn.apache.org/viewvc?rev=803062&view=rev
Log:
CAMEL-1899: Avoid creating auto templates if bean with same id already have been defined as a spring bean.

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest.java
      - copied, changed from r803028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest-context.xml
      - copied, changed from r803028, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest-context.xml
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=803062&r1=803061&r2=803062&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Tue Aug 11 11:10:48 2009
@@ -335,7 +335,12 @@
             }
         }
 
-        if (!template) {
+        // either we have not used templat before or we have auto registered it already and therefore we
+        // need it to allow to do it so it can remove the existing auto registered as there is now a clash id
+        // since we have multiple camel contexts
+        boolean canDoTemplate = autoRegisterMap.get("template") != null
+                || !parserContext.getRegistry().isBeanNameInUse("template");
+        if (!template && canDoTemplate) {
             String id = "template";
             // auto create a template
             Element templateElement = element.getOwnerDocument().createElement("template");
@@ -347,7 +352,12 @@
             autoRegisterBeanDefinition(id, definition, parserContext, contextId);
         }
 
-        if (!consumerTemplate) {
+        // either we have not used templat before or we have auto registered it already and therefore we
+        // need it to allow to do it so it can remove the existing auto registered as there is now a clash id
+        // since we have multiple camel contexts
+        boolean canDoConsumerTemplate = autoRegisterMap.get("consumerTemplate") != null
+                || !parserContext.getRegistry().isBeanNameInUse("consumerTemplate");
+        if (!consumerTemplate && canDoConsumerTemplate) {
             String id = "consumerTemplate";
             // auto create a template
             Element templateElement = element.getOwnerDocument().createElement("consumerTemplate");

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest.java (from r803028, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest.java&r1=803028&r2=803062&rev=803062&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest.java (original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest.java Tue Aug 11 11:10:48 2009
@@ -17,6 +17,7 @@
 package org.apache.camel.spring.config;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.ProducerTemplate;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,19 +28,20 @@
  * @version $Revision$
  */
 @ContextConfiguration
-public class ProducerTemplateAutoRegisterTest extends AbstractJUnit38SpringContextTests {
-
-    @Autowired
-    private ProducerTemplate template;
+public class ProducerTemplateAutoRegisterBeanIdExistsTest extends AbstractJUnit38SpringContextTests {
 
     @Autowired
     private CamelContext context;
 
     @Test
-    public void testHasTemplate() {
-        assertNotNull("Should have injected a producer template", template);
+    public void testHasNoTemplate() {
+        Object lookup = context.getRegistry().lookup("template");
+        assertFalse("Should not be a producer template", lookup instanceof ProducerTemplate);
+    }
 
-        ProducerTemplate lookup = context.getRegistry().lookup("template", ProducerTemplate.class);
-        assertNotNull("Should lookup producer template", lookup);
+    @Test
+    public void testHasConsumerTemplate() {
+        Object lookup = context.getRegistry().lookup("consumerTemplate");
+        assertTrue("Should be a consumer template", lookup instanceof ConsumerTemplate);
     }
-}
+}
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest-context.xml (from r803028, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest-context.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest-context.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest-context.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest-context.xml&r1=803028&r2=803062&rev=803062&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterTest-context.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/ProducerTemplateAutoRegisterBeanIdExistsTest-context.xml Tue Aug 11 11:10:48 2009
@@ -22,6 +22,9 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
+    <!-- define a bean with template id to clash with auto register -->
+    <bean id="template" class="org.apache.camel.spring.example.DummyBean"/>
+
     <camelContext xmlns="http://camel.apache.org/schema/spring">
     </camelContext>