camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r782046 - in /camel/branches/camel-1.x: ./ components/camel-spring/src/main/java/org/apache/camel/component/event/ components/camel-spring/src/main/java/org/apache/camel/spring/ components/camel-spring/src/main/java/org/apache/camel/spring/...
Date Fri, 05 Jun 2009 15:23:45 GMT
Author: davsclaus
Date: Fri Jun  5 15:23:44 2009
New Revision: 782046

URL: http://svn.apache.org/viewvc?rev=782046&view=rev
Log:
Merged revisions 781314,781349 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r781314 | davsclaus | 2009-06-03 11:24:30 +0200 (Wed, 03 Jun 2009) | 1 line
  
  CAMEL-1663: Fixed bug with using Camel and other annotations in same POJO and RouteBuilder
classes.
........
  r781349 | davsclaus | 2009-06-03 14:04:38 +0200 (Wed, 03 Jun 2009) | 1 line
  
  CAMEL-1663: Fixed bug with using Camel and other annotations in same POJO and RouteBuilder
classes.
........

Added:
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/
      - copied from r781349, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/CamelCustomPostProcessorOnRouteBuilderTest.java
      - copied unchanged from r781349, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/CamelCustomPostProcessorOnRouteBuilderTest.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/MagicAnnotation.java
      - copied unchanged from r781349, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/MagicAnnotation.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/MagicAnnotationPostProcessor.java
      - copied unchanged from r781349, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/MagicAnnotationPostProcessor.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/MyRouteBuilderWithAutowiredPojo.java
      - copied unchanged from r781349, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/MyRouteBuilderWithAutowiredPojo.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/PlainSpringCustomPostProcessorOnRouteBuilderTest.java
      - copied unchanged from r781349, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/PlainSpringCustomPostProcessorOnRouteBuilderTest.java
    camel/branches/camel-1.x/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/TestPojo.java
      - copied unchanged from r781349, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/postprocessor/TestPojo.java
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/
      - copied from r781349, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml
      - copied, changed from r781349, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml
    camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/plainSpringCustomPostProcessorOnRouteBuilderTest.xml
      - copied unchanged from r781349, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/plainSpringCustomPostProcessorOnRouteBuilderTest.xml
Modified:
    camel/branches/camel-1.x/   (props changed)
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
    camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jun  5 15:23:44 2009
@@ -1 +1 @@
-/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781775,781923,781974,781
 993
+/camel/trunk:736980,739733,739904,740251,740295,740306,740596,740663,741848,742231,742705,742739,742854,742856,742898,742906,743613,743762,743773,743920,743959-743960,744123,745105,745367,745541,745751,745826,745978,746269,746872,746895,746962,747258,747678-747704,748392,748436,748821,749563-749564,749574,749628-749629,749936,749956,750017,750334,750396,750761,750796,752068,752117,752418,752751-752755,752764-752773,752956,753087,753101,753175,755136,755487,756313,756348,756870,756939,757636,757693,757743,757865,758539,758563,758600,758617,758692,758990,759362,759453,759887,759931,760003,760890,760909,760937,761194,761536,761583,761607,762047,762633,762650,762935,763095,763484,763551,765154,765686,765729,765743,765824,766016,766289,766584,766588,766590,766602,766673,767403,767824,768342,769239,769346,769368,769434,770172,770906,771303,773193,773446,773781,774192,774383,774658-774659,776198,776289,776504,776975,778102,778689-778701,779121,779143,779489,781314-781349,781775,781
 923,781974,781993

Propchange: camel/branches/camel-1.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java?rev=782046&r1=782045&r2=782046&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/component/event/EventEndpoint.java
Fri Jun  5 15:23:44 2009
@@ -65,16 +65,17 @@
     }
 
     public Producer<Exchange> createProducer() throws Exception {
-        ObjectHelper.notNull(getApplicationContext(), "applicationContext");
+        ObjectHelper.notNull(applicationContext, "applicationContext");
         return new DefaultProducer<Exchange>(this) {
             public void process(Exchange exchange) throws Exception {
                 ApplicationEvent event = toApplicationEvent(exchange);
-                getApplicationContext().publishEvent(event);
+                applicationContext.publishEvent(event);
             }
         };
     }
 
     public EventConsumer createConsumer(Processor processor) throws Exception {
+        ObjectHelper.notNull(applicationContext, "applicationContext");
         return new EventConsumer(this, processor);
     }
 

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java?rev=782046&r1=782045&r2=782046&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelBeanPostProcessor.java
Fri Jun  5 15:23:44 2009
@@ -24,6 +24,7 @@
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.Endpoint;
 import org.apache.camel.EndpointInject;
@@ -67,11 +68,25 @@
     private ApplicationContext applicationContext;
     @XmlTransient
     private CamelPostProcessorHelper postProcessor;
+    @XmlTransient
+    private String camelId;
 
     public CamelBeanPostProcessor() {
     }
 
     public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException
{
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Camel bean processing before initialization for bean: " + beanName);
+        }
+
+        // some beans cannot be post processed at this given time, so we gotta check beforehand
+        if (!canPostProcessBean(bean, beanName)) {
+            return bean;
+        }
+
+        if (camelContext == null && applicationContext.containsBean(camelId)) {
+            setCamelContext((SpringCamelContext) applicationContext.getBean(camelId));
+        }
         injectFields(bean);
         injectMethods(bean);
         if (bean instanceof CamelContextAware) {
@@ -86,6 +101,15 @@
     }
 
     public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException
{
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Camel bean processing after initialization for bean: " + beanName);
+        }
+
+        // some beans cannot be post processed at this given time, so we gotta check beforehand
+        if (!canPostProcessBean(bean, beanName)) {
+            return bean;
+        }
+
         if (bean instanceof DefaultEndpoint) {
             DefaultEndpoint defaultEndpoint = (DefaultEndpoint) bean;
             defaultEndpoint.setEndpointUriIfNotSpecified(beanName);
@@ -114,10 +138,36 @@
         };
     }
 
+    public String getCamelId() {
+        return camelId;
+    }
+
+    public void setCamelId(String camelId) {
+        this.camelId = camelId;
+    }
+
     // Implementation methods
     // -------------------------------------------------------------------------
 
     /**
+     * Can we post process the given bean?
+     *
+     * @param bean the bean
+     * @param beanName the bean name
+     * @return true to process it
+     */
+    protected boolean canPostProcessBean(Object bean, String beanName) {
+        // the JMXAgent is a bit strange and causes Spring issues if we let it being
+        // post processed by this one. It does not need it anyway so we are good to go.
+        if (bean instanceof CamelJMXAgentType) {
+            return false;
+        }
+
+        // all other beans can of course be processed
+        return true;
+    }
+
+    /**
      * A strategy method to allow implementations to perform some custom JBI
      * based injection of the POJO
      *

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=782046&r1=782045&r2=782046&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
Fri Jun  5 15:23:44 2009
@@ -321,18 +321,23 @@
     }
 
     public void onApplicationEvent(ApplicationEvent event) {
-        if (LOG.isDebugEnabled()) {
-            LOG.debug("Publishing spring-event: " + event);
-        }
+        if (context != null) {
+            // let the spring camel context handle the events
+            context.onApplicationEvent(event);
+        } else {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Publishing spring-event: " + event);
+            }
 
-        if (event instanceof ContextRefreshedEvent) {
-            // now lets start the CamelContext so that all its possible
-            // dependencies are initialized
-            try {
-                LOG.debug("Starting the context now!");
-                getContext().start();
-            } catch (Exception e) {
-                throw wrapRuntimeCamelException(e);
+            if (event instanceof ContextRefreshedEvent) {
+                // now lets start the CamelContext so that all its possible
+                // dependencies are initialized
+                try {
+                    LOG.debug("Starting the context now!");
+                    getContext().start();
+                } catch (Exception e) {
+                    throw wrapRuntimeCamelException(e);
+                }
             }
         }
         /*
@@ -594,7 +599,7 @@
                         getContext().addRoutes(routes);
                     } else {
                         // Throw the exception that we can't find any build here
-                        throw new CamelException("Can't find any routes info with this RouteBuilderDefinition
" + builderRef);
+                        throw new CamelException("Cannot find any routes with this RouteBuilder
reference: " + builderRef);
                     }
                 }
             }

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java?rev=782046&r1=782045&r2=782046&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/SpringCamelContext.java
Fri Jun  5 15:23:44 2009
@@ -68,8 +68,7 @@
         setApplicationContext(applicationContext);
     }
 
-    public static SpringCamelContext springCamelContext(ApplicationContext applicationContext)
-        throws Exception {
+    public static SpringCamelContext springCamelContext(ApplicationContext applicationContext)
throws Exception {
         // lets try and look up a configured camel context in the context
         String[] names = applicationContext.getBeanNamesForType(SpringCamelContext.class);
         if (names.length == 1) {

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=782046&r1=782045&r2=782046&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
Fri Jun  5 15:23:44 2009
@@ -120,7 +120,10 @@
         String beanPostProcessorId = contextId + ":beanPostProcessor";
         childElement.setAttribute("id", beanPostProcessorId);
         BeanDefinition definition = beanPostProcessorParser.parse(childElement, parserContext);
-        definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
+        // only register to camel context id as a String. Then we can look it up later
+        // otherwise we get a circular reference in spring and it will not allow custom bean
post processing
+        // see more at CAMEL-1663
+        definition.getPropertyValues().addPropertyValue("camelId", contextId);
         parentBuilder.addPropertyReference("beanPostProcessor", beanPostProcessorId);
     }
 

Modified: camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java?rev=782046&r1=782045&r2=782046&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/main/java/org/apache/camel/spring/spi/SpringInjector.java
Fri Jun  5 15:23:44 2009
@@ -17,7 +17,6 @@
 package org.apache.camel.spring.spi;
 
 import org.apache.camel.spi.Injector;
-import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
 import org.springframework.context.ConfigurableApplicationContext;
 
 /**
@@ -27,32 +26,14 @@
  */
 public class SpringInjector implements Injector {
     private final ConfigurableApplicationContext applicationContext;
-    private int autowireMode = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;
-    private boolean dependencyCheck;
 
     public SpringInjector(ConfigurableApplicationContext applicationContext) {
         this.applicationContext = applicationContext;
     }
 
     public <T> T newInstance(Class<T> type) {
-        // TODO support annotations for mandatory injection points?
-        Object value = applicationContext.getBeanFactory().createBean(type, autowireMode,
dependencyCheck);
+        Object value = applicationContext.getBeanFactory().createBean(type);
         return type.cast(value);
     }
 
-    public int getAutowireMode() {
-        return autowireMode;
-    }
-
-    public void setAutowireMode(int autowireMode) {
-        this.autowireMode = autowireMode;
-    }
-
-    public boolean isDependencyCheck() {
-        return dependencyCheck;
-    }
-
-    public void setDependencyCheck(boolean dependencyCheck) {
-        this.dependencyCheck = dependencyCheck;
-    }
 }

Copied: camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml
(from r781349, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml)
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml?p2=camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml&r1=781349&r2=782046&rev=782046&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml
(original)
+++ camel/branches/camel-1.x/components/camel-spring/src/test/resources/org/apache/camel/spring/postprocessor/camelCustomPostProcessorOnRouteBuilderTest.xml
Fri Jun  5 15:23:44 2009
@@ -19,23 +19,14 @@
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:context="http://www.springframework.org/schema/context"
        xsi:schemaLocation="
-            http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+            http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
             http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
 
     <context:component-scan base-package="org.apache.camel.spring.postprocessor"/>
 
-    <!--<bean id="cbpp" class="org.apache.camel.spring.CamelBeanPostProcessor">-->
-        <!--<property name="camelContext" ref="camel"/>-->
-    <!--</bean>-->
-
-    <!--<bean id="dummy" class="org.apache.camel.spring.MyDummyCamelBeanPostProcessor"/>-->
-
-    <!--<bean id="myRoute" class="org.apache.camel.spring.postprocessor.MyRouteBuilderWithAutowiredPojo"/>-->
-
-    <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
+    <camelContext id="camel" xmlns="http://activemq.apache.org/camel/schema/spring">
         <package>org.apache.camel.spring.postprocessor</package>
-        <!--<routeBuilder ref="myRoute"/>-->
     </camelContext>
 
 </beans>
\ No newline at end of file



Mime
View raw message