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:02:30 UTC

svn commit: r1374582 - in /camel/trunk/components/camel-spring/src: main/java/org/apache/camel/spring/remoting/ test/java/org/apache/camel/spring/produce/ test/java/org/apache/camel/spring/remoting/

Author: ningjiang
Date: Sat Aug 18 14:02:29 2012
New Revision: 1374582

URL: http://svn.apache.org/viewvc?rev=1374582&view=rev
Log:
CAMEL-5518 fix the issue that Camel Proxy,Export ignores camelContextId property in Spring configuration

Added:
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest.java
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingTwoCamelContextTest.java
Modified:
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java
    camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java?rev=1374582&r1=1374581&r2=1374582&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelProxyFactoryBean.java Sat Aug 18 14:02:29 2012
@@ -23,6 +23,7 @@ import org.apache.camel.FailedToCreatePr
 import org.apache.camel.Producer;
 import org.apache.camel.component.bean.ProxyHelper;
 import org.apache.camel.spring.util.CamelContextResolverHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.DisposableBean;
@@ -46,14 +47,13 @@ public class CamelProxyFactoryBean exten
     @Override
     public void afterPropertiesSet() {
         if (endpoint == null) {
-            if (camelContext == null && camelContextId != null) {
+            if (ObjectHelper.isNotEmpty(camelContextId)) {
                 camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
             }
-
             if (camelContext == null) {
                 throw new IllegalArgumentException("camelContext or camelContextId must be specified");
             }
-
+            
             if (getServiceUrl() == null && getServiceRef() == null) {
                 throw new IllegalArgumentException("serviceUrl or serviceRef must be specified.");
             }

Modified: camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java?rev=1374582&r1=1374581&r2=1374582&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java (original)
+++ camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/remoting/CamelServiceExporter.java Sat Aug 18 14:02:29 2012
@@ -23,6 +23,7 @@ import org.apache.camel.Endpoint;
 import org.apache.camel.component.bean.BeanProcessor;
 import org.apache.camel.spring.util.CamelContextResolverHelper;
 import org.apache.camel.util.CamelContextHelper;
+import org.apache.camel.util.ObjectHelper;
 import org.springframework.beans.BeansException;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.FactoryBean;
@@ -83,7 +84,8 @@ public class CamelServiceExporter extend
     public void afterPropertiesSet() throws Exception {
         // lets bind the URI to a pojo
         notNull(uri, "uri");
-        if (camelContext == null && camelContextId != null) {
+        // Always resolve the camel context by using the camelContextID
+        if (ObjectHelper.isNotEmpty(camelContextId)) {
             camelContext = CamelContextResolverHelper.getCamelContextWithId(applicationContext, camelContextId);
         }
         notNull(camelContext, "camelContext");

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest.java?rev=1374582&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/produce/ProduceTemplateWithTwoCamelContextTest.java Sat Aug 18 14:02:29 2012
@@ -0,0 +1,40 @@
+/**
+ * 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.produce;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+
+@ContextConfiguration
+public class ProduceTemplateWithTwoCamelContextTest extends AbstractJUnit38SpringContextTests {
+    @Autowired
+    protected ProducerTemplate producer;
+    
+    @EndpointInject(uri = "mock:result")
+    protected MockEndpoint result;
+
+    public void testProducerTemplate() throws Exception {
+        result.expectedBodiesReceived("hello");
+        // lets send a message
+        producer.sendBody("direct:start", "hello");
+        result.assertIsSatisfied();
+    }
+}

Added: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingTwoCamelContextTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingTwoCamelContextTest.java?rev=1374582&view=auto
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingTwoCamelContextTest.java (added)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/remoting/SpringRemotingTwoCamelContextTest.java Sat Aug 18 14:02:29 2012
@@ -0,0 +1,49 @@
+/**
+ * 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.remoting;
+
+import junit.framework.TestCase;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+public class SpringRemotingTwoCamelContextTest extends TestCase {
+    
+    public void testProxyWithTwoCamelContext() throws Exception {
+        AbstractXmlApplicationContext applicationContext = createApplicationContext();
+        CamelContext camelContext = SpringCamelContext.springCamelContext(applicationContext);
+        
+        ISay proxy = applicationContext.getBean("sayProxy1", ISay.class);
+        String rc = proxy.say();
+        assertEquals("context-1", rc);
+        
+        proxy = applicationContext.getBean("sayProxy2", ISay.class);
+        rc = proxy.say();
+        assertEquals("context-2", rc);
+       
+
+        camelContext.stop();
+        applicationContext.destroy();
+    }
+
+    protected AbstractXmlApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("org/apache/camel/spring/remoting/spring-with-two-camelcontext.xml");
+    }
+
+}