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 2012/08/18 16:03:33 UTC
svn commit: r1374583 - in /camel/trunk/components:
camel-core-xml/src/main/java/org/apache/camel/core/xml/
camel-spring/src/test/resources/org/apache/camel/spring/produce/
camel-spring/src/test/resources/org/apache/camel/spring/remoting/
Author: ningjiang
Date: Sat Aug 18 14:03:32 2012
New Revision: 1374583
URL: http://svn.apache.org/viewvc?rev=1374583&view=rev
Log:
CAMEL-5519 fix the issue that camel template, endpoint etc ignore camelContextId property
Added:
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest-context.xml
camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml
Modified:
camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelFactoryBean.java
Modified: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelFactoryBean.java?rev=1374583&r1=1374582&r2=1374583&view=diff
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelFactoryBean.java (original)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelFactoryBean.java Sat Aug 18 14:03:32 2012
@@ -24,6 +24,7 @@ import javax.xml.bind.annotation.XmlTran
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.model.IdentifiedType;
+import org.apache.camel.util.ObjectHelper;
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class AbstractCamelFactoryBean<T> extends IdentifiedType implements CamelContextAware {
@@ -46,13 +47,8 @@ public abstract class AbstractCamelFacto
}
public void afterPropertiesSet() throws Exception {
- }
-
- public void destroy() throws Exception {
- }
-
- public CamelContext getCamelContext() {
- if (camelContext == null && camelContextId != null) {
+ // Always try to resolved the camel context by using the camelContextId
+ if (ObjectHelper.isNotEmpty(camelContextId)) {
camelContext = getCamelContextWithId(camelContextId);
if (camelContext == null) {
throw new IllegalStateException("Cannot find CamelContext with id: " + camelContextId);
@@ -61,6 +57,12 @@ public abstract class AbstractCamelFacto
if (camelContext == null) {
camelContext = discoverDefaultCamelContext();
}
+ }
+
+ public void destroy() throws Exception {
+ }
+
+ public CamelContext getCamelContext() {
return camelContext;
}
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest-context.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest-context.xml?rev=1374583&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest-context.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest-context.xml Sat Aug 18 14:03:32 2012
@@ -0,0 +1,41 @@
+<?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.
+-->
+<!-- START SNIPPET: example -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
+ http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
+ ">
+ <template id="camelTemplate" camelContextId="camelContext2" xmlns="http://camel.apache.org/schema/spring"/>
+
+ <camelContext id="camelContext1" xmlns="http://camel.apache.org/schema/spring"/>
+
+ <camelContext id="camelContext2" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:start"/>
+ <to uri="mock:result"/>
+ </route>
+ </camelContext>
+
+
+
+</beans>
+<!-- END SNIPPET: example -->
Added: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml?rev=1374583&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml (added)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml Sat Aug 18 14:03:32 2012
@@ -0,0 +1,65 @@
+<?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"
+ xmlns:camel="http://camel.apache.org/schema/spring"
+ 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
+ ">
+
+ <camelContext id="context-1" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:foo"/>
+ <to uri="direct:sayImpl"/>
+ </route>
+ </camelContext>
+ <camelContext id="context-2" xmlns="http://camel.apache.org/schema/spring">
+ <route>
+ <from uri="direct:foo"/>
+ <to uri="direct:sayImpl"/>
+ </route>
+ </camelContext>
+
+ <camel:proxy id="sayProxy1"
+ serviceInterface="org.apache.camel.spring.remoting.ISay"
+ serviceUrl="direct:foo"
+ camelContextId="context-1"/>
+
+ <camel:proxy id="sayProxy2"
+ serviceInterface="org.apache.camel.spring.remoting.ISay"
+ serviceUrl="direct:foo"
+ camelContextId="context-2"/>
+
+ <bean id="sayService1" class="org.apache.camel.spring.remoting.SayService">
+ <property name="message" value="context-1" />
+ </bean>
+
+ <bean id="sayService2" class="org.apache.camel.spring.remoting.SayService">
+ <property name="message" value="context-2" />
+ </bean>
+
+ <camel:export id="say1" uri="direct:sayImpl" serviceRef="sayService1"
+ serviceInterface="org.apache.camel.spring.remoting.ISay"
+ camelContextId="context-1"/>
+
+ <camel:export id="say2" uri="direct:sayImpl" serviceRef="sayService2"
+ serviceInterface="org.apache.camel.spring.remoting.ISay"
+ camelContextId="context-2"/>
+
+</beans>