You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2010/09/13 06:29:40 UTC
svn commit: r996415 - in /camel/trunk/components/camel-spring/src:
main/java/org/apache/camel/spring/handler/
test/java/org/apache/camel/spring/issues/
test/resources/org/apache/camel/spring/issues/
Author: ningjiang
Date: Mon Sep 13 04:29:39 2010
New Revision: 996415
URL: http://svn.apache.org/viewvc?rev=996415&view=rev
Log:
CAMEL-3118 fixed the issue of camel-spring causes wrong initialization-order of dependent beans
Added:
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingBean.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingRouteBuilder.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleRouteBuilderContainer.java (with props)
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringInitializationIssueTest.java (with props)
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml (with props)
Modified:
camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringPackageTest.xml
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=996415&r1=996414&r2=996415&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 Mon Sep 13 04:29:39 2010
@@ -17,6 +17,7 @@
package org.apache.camel.spring.handler;
import java.lang.reflect.Method;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -362,8 +363,18 @@ public class CamelNamespaceHandler exten
// set depends-on to the context for a routeBuilder bean
try {
BeanDefinition definition = parserContext.getRegistry().getBeanDefinition(routeBuilderName);
+ Method getDependsOn = definition.getClass().getMethod("getDependsOn", new Class[]{});
+ String[] dependsOn = (String[])getDependsOn.invoke(definition, new Object[]{});
+ if (dependsOn == null || dependsOn.length == 0) {
+ dependsOn = new String[]{contextId};
+ } else {
+ String[] temp = new String[dependsOn.length + 1];
+ System.arraycopy(dependsOn, 0, temp, 0, dependsOn.length);
+ temp[dependsOn.length] = contextId;
+ dependsOn = temp;
+ }
Method method = definition.getClass().getMethod("setDependsOn", String[].class);
- method.invoke(definition, (Object) new String[]{contextId});
+ method.invoke(definition, (Object)dependsOn);
} catch (Exception e) {
// Do nothing here
}
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingBean.java?rev=996415&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingBean.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingBean.java Mon Sep 13 04:29:39 2010
@@ -0,0 +1,41 @@
+/**
+ * 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.issues;
+
+import java.util.List;
+
+import org.springframework.beans.factory.InitializingBean;
+
+public class SampleInitializingBean implements InitializingBean {
+
+ private String name;
+
+ private List<String> entries;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setEntries(List<String> entries) {
+ this.entries = entries;
+ }
+
+ public void afterPropertiesSet() {
+ entries.add(name);
+ }
+
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingBean.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingBean.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingRouteBuilder.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingRouteBuilder.java?rev=996415&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingRouteBuilder.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingRouteBuilder.java Mon Sep 13 04:29:39 2010
@@ -0,0 +1,47 @@
+/**
+ * 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.issues;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.beans.factory.InitializingBean;
+
+public class SampleInitializingRouteBuilder extends RouteBuilder implements InitializingBean {
+
+ private String name;
+
+ private List<String> entries;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setEntries(List<String> entries) {
+ this.entries = entries;
+ }
+
+ public void afterPropertiesSet() {
+ entries.add(name);
+ }
+
+ @Override
+ public void configure() throws Exception {
+ entries.add("configured");
+ }
+
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingRouteBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleInitializingRouteBuilder.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleRouteBuilderContainer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleRouteBuilderContainer.java?rev=996415&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleRouteBuilderContainer.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleRouteBuilderContainer.java Mon Sep 13 04:29:39 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.issues;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.beans.factory.InitializingBean;
+
+public class SampleRouteBuilderContainer implements InitializingBean {
+
+ private RouteBuilder routeBuilder;
+
+ public void setRouteBuilder(RouteBuilder routeBuilder) {
+ this.routeBuilder = routeBuilder;
+ }
+
+ public void afterPropertiesSet() throws Exception {
+ routeBuilder.configure();
+ }
+
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleRouteBuilderContainer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SampleRouteBuilderContainer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringInitializationIssueTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringInitializationIssueTest.java?rev=996415&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringInitializationIssueTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringInitializationIssueTest.java Mon Sep 13 04:29:39 2010
@@ -0,0 +1,45 @@
+/**
+ * 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.issues;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.junit.Test;
+
+import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class SpringInitializationIssueTest extends ContextTestSupport {
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ return createSpringCamelContext(this, "org/apache/camel/spring/issues/SpringInitializationIssueTest.xml");
+ }
+
+ @Test
+ public void testTemp() {
+ assertEquals(Arrays.asList(new String[] {"test2a", "test2b", "configured"}), getNamesList("entries2"));
+ // Will fail because of wrong bean initialization order caused by SpringCamelContext
+ assertEquals(Arrays.asList(new String[] {"test1a", "test1b", "configured"}), getNamesList("entries1"));
+ }
+
+ private List<?> getNamesList(String beanName) {
+ return context.getRegistry().lookup(beanName, List.class);
+ }
+}
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringInitializationIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/issues/SpringInitializationIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml?rev=996415&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml Mon Sep 13 04:29:39 2010
@@ -0,0 +1,61 @@
+<?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.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+
+ <!-- Lists where beans store strings during initialization -->
+ <bean id="entries1" class="java.util.ArrayList"/>
+ <bean id="entries2" class="java.util.ArrayList"/>
+
+ <bean id="sampleBean1"
+ class="org.apache.camel.spring.issues.SampleInitializingBean">
+ <property name="name" value="test1a"/>
+ <property name="entries" ref="entries1"/>
+ </bean>
+
+ <bean id="sampleRouteBuilder1"
+ class="org.apache.camel.spring.issues.SampleInitializingRouteBuilder" depends-on="sampleBean1">
+ <property name="name" value="test1b"/>
+ <property name="entries" ref="entries1"/>
+ </bean>
+
+ <bean id="sampleBean2"
+ class="org.apache.camel.spring.issues.SampleInitializingBean">
+ <property name="name" value="test2a"/>
+ <property name="entries" ref="entries2"/>
+ </bean>
+
+ <bean id="sampleRouteBuilder2"
+ class="org.apache.camel.spring.issues.SampleInitializingRouteBuilder" depends-on="sampleBean2">
+ <property name="name" value="test2b"/>
+ <property name="entries" ref="entries2"/>
+ </bean>
+
+ <camelContext xmlns="http://camel.apache.org/schema/spring">
+ <routeBuilder ref="sampleRouteBuilder1"/>
+ </camelContext>
+
+ <bean id="sampleRouteBuilderContainer" class="org.apache.camel.spring.issues.SampleRouteBuilderContainer">
+ <property name="routeBuilder" ref="sampleRouteBuilder2"/>
+ </bean>
+
+</beans>
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringInitializationIssueTest.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringPackageTest.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringPackageTest.xml?rev=996415&r1=996414&r2=996415&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringPackageTest.xml (original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/issues/SpringPackageTest.xml Mon Sep 13 04:29:39 2010
@@ -26,6 +26,7 @@
<packageScan>
<package>org.apache.camel.spring.issues</package>
<excludes>**/*MyInjectionRouteBuilder*</excludes>
+ <excludes>**/*SampleInitializingRouteBuilder*</excludes>
<excludes>*contextscan*</excludes>
</packageScan>
</camelContext>