Author: ningjiang
Date: Sun Dec 21 23:48:41 2008
New Revision: 728624
URL: http://svn.apache.org/viewvc?rev=728624&view=rev
Log:
CAMEL-372 create a JMSTransactionMananger if there is none transaction manager
is injected into the JMSEndpoint when the transacted option is true.
Added:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionWithoutDefineTransactionManagerTest.java
(with props)
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml
(with props)
Modified:
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionTest.java
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/nonTxInOutJmsTest.xml
Modified:
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?rev=728624&r1=728623&r2=728624&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
(original)
+++
activemq/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
Sun Dec 21 23:48:41 2008
@@ -34,6 +34,7 @@
import org.springframework.core.task.TaskExecutor;
import org.springframework.jms.JmsException;
import org.springframework.jms.connection.JmsResourceHolder;
+import org.springframework.jms.connection.JmsTransactionManager;
import org.springframework.jms.core.JmsOperations;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.JmsTemplate102;
@@ -111,6 +112,7 @@
// Transaction related configuration
private boolean transacted;
private boolean transactedInOut;
+ private boolean lazyCreateTransactionManager = true;
private PlatformTransactionManager transactionManager;
private String transactionName;
private int transactionTimeout = -1;
@@ -576,6 +578,9 @@
}
public PlatformTransactionManager getTransactionManager() {
+ if (transactionManager == null && isTransacted() &&
isLazyCreateTransactionManager()) {
+ transactionManager = createTransactionManager();
+ }
return transactionManager;
}
@@ -719,6 +724,14 @@
public void setTransactedInOut(boolean transactedInOut) {
this.transactedInOut = transactedInOut;
}
+
+ public boolean isLazyCreateTransactionManager() {
+ return lazyCreateTransactionManager;
+ }
+
+ public void setLazyCreateTransactionManager(boolean lazyCreating) {
+ this.lazyCreateTransactionManager = lazyCreating;
+ }
public boolean isEagerLoadingOfProperties() {
return eagerLoadingOfProperties;
@@ -863,8 +876,8 @@
container.setAcceptMessagesWhileStopping(acceptMessagesWhileStopping);
container.setExposeListenerSession(exposeListenerSession);
- container.setSessionTransacted(transacted && transactedInOut);
- if (transacted && transactedInOut) {
+ container.setSessionTransacted(transacted);
+ if (transacted) {
container.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED);
} else {
if (acknowledgementMode >= 0) {
@@ -913,9 +926,9 @@
listenerContainer.setTaskExecutor(taskExecutor);
}
PlatformTransactionManager tm = getTransactionManager();
- if (tm != null && (transacted && transactedInOut)) {
+ if (tm != null && transacted) {
listenerContainer.setTransactionManager(tm);
- } else if (transacted && transactedInOut) {
+ } else if (transacted) {
throw new IllegalArgumentException("Property transacted is
enabled but a transactionManager was not injected!");
}
if (transactionName != null) {
@@ -1025,6 +1038,16 @@
protected ConnectionFactory createTemplateConnectionFactory() {
return getConnectionFactory();
}
+
+ /**
+ * Factory method which which allows derived classes to customize the lazy
+ * transcationManager creation
+ */
+ protected PlatformTransactionManager createTransactionManager() {
+ JmsTransactionManager answer = new JmsTransactionManager();
+ answer.setConnectionFactory(getConnectionFactory());
+ return answer;
+ }
public boolean isPreserveMessageQos() {
return preserveMessageQos;
Modified:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionTest.java?rev=728624&r1=728623&r2=728624&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionTest.java
(original)
+++
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionTest.java
Sun Dec 21 23:48:41 2008
@@ -45,8 +45,8 @@
public void configure() throws Exception {
Policy required = bean(SpringTransactionPolicy.class,
"PROPAGATION_REQUIRED_POLICY");
- from("activemq:queue:foo").policy(required).process(new
ConditionalExceptionProcessor())
- .to("activemq:queue:bar");
+
from("activemq:queue:foo?transacted=true").policy(required).process(new
ConditionalExceptionProcessor())
+ .to("activemq:queue:bar?transacted=true");
}
});
Added:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionWithoutDefineTransactionManagerTest.java
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionWithoutDefineTransactionManagerTest.java?rev=728624&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionWithoutDefineTransactionManagerTest.java
(added)
+++
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionWithoutDefineTransactionManagerTest.java
Sun Dec 21 23:48:41 2008
@@ -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.tx;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.spring.SpringRouteBuilder;
+import org.apache.log4j.Logger;
+import static
org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
+
+public class QueueToQueueTransactionWithoutDefineTransactionManagerTest
extends AbstractTransactionTest {
+
+ private Logger log = Logger.getLogger(getClass());
+
+ protected CamelContext createCamelContext() throws Exception {
+
+ return createSpringCamelContext(this,
"org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml");
+ }
+
+ public void testRollbackUsingXmlQueueToQueue() throws Exception {
+
+ // configure routes and add to camel context
+ context.addRoutes(new SpringRouteBuilder() {
+
+ @Override
+ public void configure() throws Exception {
+
+ from("activemq:queue:foo").process(new
ConditionalExceptionProcessor())
+ .to("activemq:queue:bar");
+ }
+ });
+
+ assertResult();
+ }
+}
Propchange:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionWithoutDefineTransactionManagerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/tx/QueueToQueueTransactionWithoutDefineTransactionManagerTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added:
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml?rev=728624&view=auto
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml
(added)
+++
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml
Sun Dec 21 23:48:41 2008
@@ -0,0 +1,39 @@
+<?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.5.xsd
+ http://activemq.apache.org/camel/schema/spring
+ http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
+
+ <bean id="jmsConnectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
+ <property name="brokerURL"
value="vm://localhost?broker.persistent=false&broker.useJmx=false"/>
+ </bean>
+
+ <bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
+ <property name="connectionFactory" ref="jmsConnectionFactory"/>
+ <property name="transacted" value="true"/>
+ <property name="transactedInOut" value="true"/>
+ <property name="concurrentConsumers" value="1"/>
+ </bean>
+
+ <bean id="activemq" class="org.apache.camel.component.jms.JmsComponent">
+ <property name="configuration" ref="jmsConfig"/>
+ </bean>
+
+</beans>
Propchange:
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/ActiveMQWithoutTransactionManager.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Modified:
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/nonTxInOutJmsTest.xml
URL:
http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/nonTxInOutJmsTest.xml?rev=728624&r1=728623&r2=728624&view=diff
==============================================================================
---
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/nonTxInOutJmsTest.xml
(original)
+++
activemq/camel/trunk/components/camel-jms/src/test/resources/org/apache/camel/component/jms/tx/nonTxInOutJmsTest.xml
Sun Dec 21 23:48:41 2008
@@ -14,7 +14,7 @@
<bean id="jmsConfig"
class="org.apache.camel.component.jms.JmsConfiguration">
<property name="connectionFactory" ref="jmsConnectionFactory"/>
<property name="transactionManager" ref="jmsTransactionManager"/>
- <property name="transacted" value="true"/>
+ <property name="transacted" value="false"/>
<property name="transactedInOut" value="false" />
</bean>