Author: davsclaus
Date: Tue Sep 22 09:52:07 2009
New Revision: 817576
URL: http://svn.apache.org/viewvc?rev=817576&view=rev
Log:
CAMEL-2033: Fixed ConsumerTemplate being IoC using @EndpointInject.
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
(with props)
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BeanConsumerIssueTest.java
(with props)
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MyBeanConsumer.java
(with props)
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/BeanConsumerIssue.xml
- copied, changed from r817503,
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest-context.xml
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java?rev=817576&r1=817575&r2=817576&view=diff
==============================================================================
---
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
(original)
+++
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
Tue Sep 22 09:52:07 2009
@@ -30,6 +30,7 @@
import org.apache.camel.Producer;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.Service;
+import org.apache.camel.ConsumerTemplate;
import org.apache.camel.component.bean.BeanProcessor;
import org.apache.camel.component.bean.ProxyHelper;
import org.apache.camel.util.CamelContextHelper;
@@ -127,6 +128,8 @@
public Object getInjectionValue(Class<?> type, String endpointUri, String
endpointRef, String injectionPointName) {
if (type.isAssignableFrom(ProducerTemplate.class)) {
return createInjectionProducerTemplate(endpointUri, endpointRef,
injectionPointName);
+ } else if (type.isAssignableFrom(ConsumerTemplate.class)) {
+ return createInjectionConsumerTemplate(endpointUri, endpointRef,
injectionPointName);
} else {
Endpoint endpoint = getEndpointInjection(endpointUri, endpointRef,
injectionPointName, true);
if (endpoint != null) {
@@ -162,6 +165,13 @@
}
/**
+ * Factory method to create a {...@link org.apache.camel.ConsumerTemplate}
to be injected into a POJO
+ */
+ protected ConsumerTemplate createInjectionConsumerTemplate(String
endpointUri, String endpointRef, String injectionPointName) {
+ return new DefaultConsumerTemplate(getCamelContext());
+ }
+
+ /**
* Factory method to create a started {...@link
org.apache.camel.PollingConsumer} to be injected into a POJO
*/
protected PollingConsumer createInjectionPollingConsumer(Endpoint
endpoint) {
Added:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java?rev=817576&view=auto
==============================================================================
---
camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
(added)
+++
camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
Tue Sep 22 09:52:07 2009
@@ -0,0 +1,30 @@
+/**
+ * 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.util;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Revision$
+ */
+public class FileUtilTest extends TestCase {
+
+ public void testMe() {
+
+ }
+
+}
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/camel-core/src/test/java/org/apache/camel/util/FileUtilTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BeanConsumerIssueTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BeanConsumerIssueTest.java?rev=817576&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BeanConsumerIssueTest.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BeanConsumerIssueTest.java
Tue Sep 22 09:52:07 2009
@@ -0,0 +1,50 @@
+/**
+ * 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.component.jms.issues;
+
+import java.util.List;
+
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spring.SpringTestSupport;
+import org.springframework.context.support.AbstractXmlApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+
+/**
+ * @version $Revision$
+ */
+public class BeanConsumerIssueTest extends SpringTestSupport {
+
+ protected AbstractXmlApplicationContext createApplicationContext() {
+ return new
ClassPathXmlApplicationContext("org/apache/camel/component/jms/issues/BeanConsumerIssue.xml");
+ }
+
+ public void testCollectMessages() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+
+ template.sendBody("activemq:queue:foo", "Hello World");
+ template.sendBody("activemq:queue:foo", "Bye World");
+
+ assertMockEndpointsSatisfied();
+
+ List list =
mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertEquals(2, list.size());
+ assertEquals("Hello World", list.get(0));
+ assertEquals("Bye World", list.get(1));
+ }
+
+}
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BeanConsumerIssueTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/BeanConsumerIssueTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MyBeanConsumer.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MyBeanConsumer.java?rev=817576&view=auto
==============================================================================
---
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MyBeanConsumer.java
(added)
+++
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MyBeanConsumer.java
Tue Sep 22 09:52:07 2009
@@ -0,0 +1,48 @@
+/**
+ * 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.component.jms.issues;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.camel.ConsumerTemplate;
+import org.apache.camel.Endpoint;
+import org.apache.camel.EndpointInject;
+
+/**
+ * @version $Revision$
+ */
+public class MyBeanConsumer {
+
+ @EndpointInject()
+ private ConsumerTemplate consumer;
+
+ public List<String> collectMessages() {
+ List<String> answer = new ArrayList<String>();
+
+ String received;
+ do {
+ received = consumer.receiveBodyNoWait("activemq:queue:foo",
String.class);
+ if (received != null) {
+ answer.add(received);
+ }
+ } while (received != null);
+
+ return answer;
+ }
+
+}
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MyBeanConsumer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/issues/MyBeanConsumer.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied:
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/BeanConsumerIssue.xml
(from r817503,
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest-context.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/BeanConsumerIssue.xml?p2=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/BeanConsumerIssue.xml&p1=camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest-context.xml&r1=817503&r2=817576&rev=817576&view=diff
==============================================================================
---
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/JmsRedeliveryWithInitialRedeliveryDelayTest-context.xml
(original)
+++
camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/issues/BeanConsumerIssue.xml
Tue Sep 22 09:52:07 2009
@@ -22,35 +22,18 @@
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
- <route errorHandlerRef="myDeadLetterErrorHandler">
- <from uri="activemq:in"/>
- <process ref="myFailureProcessor"/>
+ <consumerTemplate id="consumer"/>
+ <route>
+ <from uri="timer://foo?delay=3000"/>
+ <bean ref="myConsumer" method="collectMessages"/>
<to uri="mock:result"/>
</route>
</camelContext>
- <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
- <property name="connectionFactory">
- <bean class="org.apache.activemq.ActiveMQConnectionFactory">
- <property name="brokerURL"
value="vm://localhost?broker.persistent=false"/>
- </bean>
- </property>
+ <bean id="activemq"
class="org.apache.activemq.camel.component.ActiveMQComponent">
+ <property name="brokerURL"
value="vm://localhost?broker.persistent=false"/>
</bean>
- <bean id="myDeadLetterErrorHandler"
class="org.apache.camel.builder.DeadLetterChannelBuilder">
- <property name="deadLetterUri" value="mock:dead"/>
- <property name="redeliveryPolicy" ref="myRedeliveryPolicyConfig"/>
- <!-- disable handled to allow unit test to look at the number of
redelivery attempts made -->
- <property name="handled" value="false"/>
- </bean>
-
- <bean id="myFailureProcessor"
class="org.apache.camel.spring.config.MyFailureProcessor"/>
-
- <bean id="myRedeliveryPolicyConfig"
class="org.apache.camel.processor.RedeliveryPolicy">
- <property name="maximumRedeliveries" value="4"/>
- <property name="redeliverDelay" value="50"/>
- <property name="useExponentialBackOff" value="true"/>
- <property name="backOffMultiplier" value="2"/>
- </bean>
+ <bean id="myConsumer"
class="org.apache.camel.component.jms.issues.MyBeanConsumer"/>
</beans>