You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by js...@apache.org on 2008/03/07 18:41:55 UTC

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

Author: jstrachan
Date: Fri Mar  7 09:41:48 2008
New Revision: 634754

URL: http://svn.apache.org/viewvc?rev=634754&view=rev
Log:
added fix for using CamelTemplate easier using the Spring 2 namespace and injecting it manually into beans: see http://www.nabble.com/spring-camel%3AcamelTemplate-question-tp15901023s22882p15901023.html

Added:
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/TemplateUsingBean.java   (with props)
    activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest-context.xml   (with props)
Modified:
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelTemplateFactoryBean.java
    activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java?rev=634754&r1=634753&r2=634754&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelContextFactoryBean.java Fri Mar  7 09:41:48 2008
@@ -71,6 +71,7 @@
     private String[] packages = {};
     @XmlElements({
         @XmlElement(name = "beanPostProcessor", type = CamelBeanPostProcessor.class, required = false), 
+        @XmlElement(name = "template", type = CamelTemplateFactoryBean.class, required = false), 
         @XmlElement(name = "proxy", type = CamelProxyFactoryType.class, required = false),
         @XmlElement(name = "export", type = CamelServiceExporterType.class, required = false), 
         @XmlElement(name = "jmxAgent", required = false)})

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelTemplateFactoryBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelTemplateFactoryBean.java?rev=634754&r1=634753&r2=634754&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelTemplateFactoryBean.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/CamelTemplateFactoryBean.java Fri Mar  7 09:41:48 2008
@@ -26,7 +26,7 @@
 import org.apache.camel.CamelContextAware;
 import org.apache.camel.CamelTemplate;
 import org.apache.camel.Endpoint;
-
+import org.apache.camel.model.IdentifiedType;
 import org.springframework.beans.factory.FactoryBean;
 import org.springframework.beans.factory.InitializingBean;
 
@@ -36,9 +36,9 @@
  * 
  * @version $Revision$
  */
-@XmlRootElement(name = "camelTemplate")
+@XmlRootElement(name = "template")
 @XmlAccessorType(XmlAccessType.FIELD)
-public class CamelTemplateFactoryBean implements FactoryBean, InitializingBean, CamelContextAware {
+public class CamelTemplateFactoryBean extends IdentifiedType implements FactoryBean, InitializingBean, CamelContextAware {
     @XmlAttribute(required = false)
     private String defaultEndpoint;
     @XmlTransient

Modified: activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java?rev=634754&r1=634753&r2=634754&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java (original)
+++ activemq/camel/trunk/components/camel-spring/src/main/java/org/apache/camel/spring/handler/CamelNamespaceHandler.java Fri Mar  7 09:41:48 2008
@@ -38,6 +38,7 @@
 import org.apache.camel.spring.CamelBeanPostProcessor;
 import org.apache.camel.spring.CamelContextFactoryBean;
 import org.apache.camel.spring.EndpointFactoryBean;
+import org.apache.camel.spring.CamelTemplateFactoryBean;
 import org.apache.camel.spring.remoting.CamelProxyFactoryBean;
 import org.apache.camel.spring.remoting.CamelServiceExporter;
 import org.apache.camel.util.ObjectHelper;
@@ -64,6 +65,7 @@
     public void init() {
         // remoting
         addBeanDefinitionParser("proxy", CamelProxyFactoryBean.class);
+        addBeanDefinitionParser("template", CamelTemplateFactoryBean.class);
         addBeanDefinitionParser("export", CamelServiceExporter.class);
 
         // data types

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest.java?rev=634754&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest.java Fri Mar  7 09:41:48 2008
@@ -0,0 +1,53 @@
+/**
+ *
+ * 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.config;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
+import org.apache.camel.CamelTemplate;
+import org.apache.camel.EndpointInject;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+@ContextConfiguration
+public class DependencyInjectCamelTemplateTest extends AbstractJUnit38SpringContextTests {
+
+    @Autowired
+    private TemplateUsingBean bean;
+
+    @EndpointInject(uri = "mock:results")
+    private MockEndpoint endpoint;
+
+    protected String body = "Hello";
+
+    public void testBeanHasCamelTemplateInjected() throws Exception {
+        assertNotNull("Bean should be injected", bean);
+        CamelTemplate template = bean.getTemplate();
+        assertNotNull("Bean should have a CamelTemplate", template);
+
+        endpoint.expectedBodiesReceived(body);
+
+        template.sendBody(body);
+
+        endpoint.assertIsSatisfied();
+    }
+
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/TemplateUsingBean.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/TemplateUsingBean.java?rev=634754&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/TemplateUsingBean.java (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/TemplateUsingBean.java Fri Mar  7 09:41:48 2008
@@ -0,0 +1,35 @@
+/**
+ *
+ * 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.config;
+
+import org.apache.camel.CamelTemplate;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class TemplateUsingBean {
+    private CamelTemplate template;
+
+    public CamelTemplate getTemplate() {
+        return template;
+    }
+
+    public void setTemplate(CamelTemplate template) {
+        this.template = template;
+    }
+}

Propchange: activemq/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/config/TemplateUsingBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest-context.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest-context.xml?rev=634754&view=auto
==============================================================================
--- activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest-context.xml (added)
+++ activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest-context.xml Fri Mar  7 09:41:48 2008
@@ -0,0 +1,34 @@
+<?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-2.0.xsd
+       http://activemq.apache.org/camel/schema/spring http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
+    ">
+
+
+
+  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+    <template id="myTemplate" defaultEndpoint="mock:results"/>
+  </camelContext>
+
+  <bean id="myBean" class="org.apache.camel.spring.config.TemplateUsingBean">
+    <property name="template" ref="myTemplate"/>
+  </bean>
+</beans>

Propchange: activemq/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/config/DependencyInjectCamelTemplateTest-context.xml
------------------------------------------------------------------------------
    svn:eol-style = native