You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/03/24 09:33:32 UTC

svn commit: r757686 - in /camel/trunk/components/camel-jms/src: main/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/

Author: davsclaus
Date: Tue Mar 24 08:33:30 2009
New Revision: 757686

URL: http://svn.apache.org/viewvc?rev=757686&view=rev
Log:
CAMEL-1480: Jms producer now works with the old 1.0.2 JMS API

Added:
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java
      - copied, changed from r757674, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java
Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
    camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsTransferExceptionTest.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java?rev=757686&r1=757685&r2=757686&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsConfiguration.java Tue Mar 24 08:33:30 2009
@@ -253,33 +253,48 @@
             execute(new SessionCallback() {
                 public Object doInJms(Session session) throws JMSException {
                     Destination destination = resolveDestinationName(session, destinationName);
-                    Assert.notNull(messageCreator, "MessageCreator must not be null");
-                    MessageProducer producer = createProducer(session, destination);
-                    Message message = null;
-                    try {
-                        message = messageCreator.createMessage(session);
-                        if (logger.isDebugEnabled()) {
-                            logger.debug("Sending created message: " + message);
-                        }
-                        doSend(producer, message);
-                        // Check commit - avoid commit call within a JTA
-                        // transaction.
-                        if (session.getTransacted() && isSessionLocallyTransacted(session)) {
-                            // Transacted session created by this template ->
-                            // commit.
-                            JmsUtils.commitIfNecessary(session);
-                        }
-                    } finally {
-                        JmsUtils.closeMessageProducer(producer);
-                    }
-                    if (message != null && callback != null) {
-                        callback.sent(message);
-                    }
-                    return null;
+                    return doSendToDestination(destination, messageCreator, callback, session);
+                }
+            }, false);
+        }
+
+        public void send(final Destination destination,
+                         final MessageCreator messageCreator,
+                         final MessageSentCallback callback) throws JmsException {
+            execute(new SessionCallback() {
+                public Object doInJms(Session session) throws JMSException {
+                    return doSendToDestination(destination, messageCreator, callback, session);
                 }
             }, false);
         }
 
+        private Object doSendToDestination(final Destination destination,
+                                           final MessageCreator messageCreator,
+                                           final MessageSentCallback callback,
+                                           final Session session) throws JMSException {
+            Assert.notNull(messageCreator, "MessageCreator must not be null");
+            MessageProducer producer = createProducer(session, destination);
+            Message message = null;
+            try {
+                message = messageCreator.createMessage(session);
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Sending created message: " + message);
+                }
+                doSend(producer, message);
+                // Check commit - avoid commit call within a JTA transaction.
+                if (session.getTransacted() && isSessionLocallyTransacted(session)) {
+                    // Transacted session created by this template -> commit.
+                    JmsUtils.commitIfNecessary(session);
+                }
+            } finally {
+                JmsUtils.closeMessageProducer(producer);
+            }
+            if (message != null && callback != null) {
+                callback.sent(message);
+            }
+            return null;
+        }
+
         /**
          * Override so we can support preserving the Qos settings that have
          * been set on the message.

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java?rev=757686&r1=757685&r2=757686&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsProducer.java Tue Mar 24 08:33:30 2009
@@ -31,6 +31,7 @@
 import org.apache.camel.FailedToCreateProducerException;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.component.jms.JmsConfiguration.CamelJmsTeemplate102;
 import org.apache.camel.component.jms.JmsConfiguration.CamelJmsTemplate;
 import org.apache.camel.component.jms.requestor.DeferredRequestReplyMap;
 import org.apache.camel.component.jms.requestor.DeferredRequestReplyMap.DeferredMessageSentCallback;
@@ -170,7 +171,6 @@
             final ValueHolder<FutureTask> futureHolder = new ValueHolder<FutureTask>();
             final DeferredMessageSentCallback callback = msgIdAsCorrId ? deferredRequestReplyMap.createDeferredMessageSentCallback() : null;
 
-            final CamelJmsTemplate template = (CamelJmsTemplate)getInOutTemplate();
             MessageCreator messageCreator = new MessageCreator() {
                 public Message createMessage(Session session) throws JMSException {
                     Message message = endpoint.getBinding().makeJmsMessage(exchange, in, session, null);
@@ -191,10 +191,29 @@
                 }
             };
 
+            CamelJmsTemplate template = null;
+            CamelJmsTeemplate102 template102 = null;
+            if (endpoint.isUseVersion102()) {
+                template102 = (CamelJmsTeemplate102)getInOutTemplate();
+            } else {
+                template = (CamelJmsTemplate)getInOutTemplate();
+            }
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Using JMS API " + (endpoint.isUseVersion102() ? "v1.0.2" : "v1.1"));
+            }
+
             if (destinationName != null) {
-                template.send(destinationName, messageCreator, callback);
+                if (template != null) {
+                    template.send(destinationName, messageCreator, callback);
+                } else {
+                    template102.send(destinationName, messageCreator, callback);
+                }
             } else if (destination != null) {
-                template.send(destination, messageCreator, callback);
+                if (template != null) {
+                    template.send(destination, messageCreator, callback);
+                } else {
+                    template102.send(destination, messageCreator, callback);
+                }
             } else {
                 throw new IllegalArgumentException("Neither destination nor destinationName is specified on this endpoint: " + endpoint);
             }

Copied: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java (from r757674, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java?p2=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java&p1=camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java&r1=757674&r2=757686&rev=757686&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReplyTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsSimpleRequestReply102Test.java Tue Mar 24 08:33:30 2009
@@ -29,17 +29,17 @@
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 
 /**
- * A simple requesr / reply test
+ * A simple requesr / reply test using the 1.0.2 JMS API
  */
-public class JmsSimpleRequestReplyTest extends ContextTestSupport {
+public class JmsSimpleRequestReply102Test extends ContextTestSupport {
 
     protected String componentName = "activemq";
 
-    public void testRequetReply() throws Exception {
+    public void testRequetReply102() throws Exception {
         MockEndpoint result = getMockEndpoint("mock:result");
         result.expectedMessageCount(1);
 
-        Exchange out = template.send("activemq:queue:hello", ExchangePattern.InOut, new Processor() {
+        Exchange out = template.send("activemq:queue:hello?useVersion102=true", ExchangePattern.InOut, new Processor() {
             public void process(Exchange exchange) throws Exception {
                 exchange.getIn().setBody("Hello World");
                 exchange.getIn().setHeader("foo", 123);
@@ -66,7 +66,7 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from("activemq:queue:hello").process(new Processor() {
+                from("activemq:queue:hello?useVersion102=true").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
                         exchange.getIn().setBody("Bye World");
                         // the reply destination is set as a property on the exchange while we process it

Modified: camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsTransferExceptionTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsTransferExceptionTest.java?rev=757686&r1=757685&r2=757686&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsTransferExceptionTest.java (original)
+++ camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsTransferExceptionTest.java Tue Mar 24 08:33:30 2009
@@ -25,8 +25,8 @@
 import org.apache.camel.Processor;
 import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.builder.RouteBuilder;
-import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
 
 /**
  * @version $Revision$