camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r787558 - in /camel/branches/camel-1.x/components/camel-jms/src: main/java/org/apache/camel/component/jms/ test/java/org/apache/camel/component/jms/
Date Tue, 23 Jun 2009 05:47:24 GMT
Author: davsclaus
Date: Tue Jun 23 05:47:24 2009
New Revision: 787558

URL: http://svn.apache.org/viewvc?rev=787558&view=rev
Log:
CAMEL-1741: camel-jms is now compatible with spring 2.0.x again.

Added:
    camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
  (with props)
    camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
  (with props)
Modified:
    camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java

Modified: camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=787558&r1=787557&r2=787558&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
(original)
+++ camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
Tue Jun 23 05:47:24 2009
@@ -457,14 +457,17 @@
      * @return the queue browse strategy or null if it cannot be supported
      */
     protected static QueueBrowseStrategy tryCreateDefaultQueueBrowseStrategy() {
-        // lets try instantiate the default implementation
-        Class<?> type = ObjectHelper.loadClass(DEFAULT_QUEUE_BROWSE_STRATEGY, JmsComponent.class.getClassLoader());
-        if (type == null) {
-            LOG.warn("Could not load class: " + DEFAULT_QUEUE_BROWSE_STRATEGY
-                     + " maybe you are on Spring 2.0.x?");
+        if (JmsHelper.isSpring20x()) {
+            // not possible with spring 2.0.x
             return null;
         } else {
-            return (QueueBrowseStrategy)ObjectHelper.newInstance(type);
+            // lets try instantiate the default implementation
+            Class<?> type = ObjectHelper.loadClass(DEFAULT_QUEUE_BROWSE_STRATEGY, JmsComponent.class.getClassLoader());
+            if (type != null) {
+                return (QueueBrowseStrategy)ObjectHelper.newInstance(type);
+            } else {
+                return null;
+            }
         }
     }
 

Added: camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java?rev=787558&view=auto
==============================================================================
--- camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
(added)
+++ camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
Tue Jun 23 05:47:24 2009
@@ -0,0 +1,52 @@
+/**
+ * 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;
+
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * @version $Revision$
+ */
+public final class JmsHelper {
+
+    private static final String DEFAULT_QUEUE_BROWSE_STRATEGY = "org.apache.camel.component.jms.DefaultQueueBrowseStrategy";
+
+    private JmsHelper() {
+        // utility class
+    }
+
+    /**
+     * Is the spring version 2.0.x?
+     *
+     * @return <tt>true</tt> if 2.0.x or <tt>false</tt> if newer
such as 2.5.x
+     */
+    public static boolean isSpring20x() {
+        // this class is only possible to instantiate in 2.5.x or newer
+        Class<?> type = ObjectHelper.loadClass(DEFAULT_QUEUE_BROWSE_STRATEGY, JmsComponent.class.getClassLoader());
+        if (type != null) {
+            try {
+                ObjectHelper.newInstance(type);
+                return false;
+            } catch (NoClassDefFoundError e) {
+                return true;
+            }
+        } else {
+            return true;
+        }
+    }
+
+}

Propchange: camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java?rev=787558&r1=787557&r2=787558&view=diff
==============================================================================
--- camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
(original)
+++ camel/branches/camel-1.x/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
Tue Jun 23 05:47:24 2009
@@ -29,10 +29,12 @@
  */
 public class JmsPollingConsumer extends PollingConsumerSupport<JmsExchange> {
     private JmsOperations template;
+    private final boolean spring20x;
 
     public JmsPollingConsumer(JmsEndpoint endpoint, JmsOperations template) {
         super(endpoint);
         this.template = template;
+        this.spring20x = JmsHelper.isSpring20x();
     }
 
     @Override
@@ -41,11 +43,27 @@
     }
 
     public JmsExchange receiveNoWait() {
-        return receive(JmsTemplate.RECEIVE_TIMEOUT_NO_WAIT);
+        // spring have changed the sematic of the receive timeout mode
+        // so we need to deterime if running spring 2.0.x or 2.5.x or newer
+        if (spring20x) {
+            // spring 2.0.x
+            return receive(0L);
+        } else {
+            // spring 2.5.x
+            return receive(-1L);
+        }
     }
 
     public JmsExchange receive() {
-        return receive(JmsTemplate.RECEIVE_TIMEOUT_INDEFINITE_WAIT);
+        // spring have changed the sematic of the receive timeout mode
+        // so we need to deterime if running spring 2.0.x or 2.5.x or newer
+        if (spring20x) {
+            // spring 2.0.x
+            return receive(-1L);
+        } else {
+            // spring 2.5.x
+            return receive(0L);
+        }
     }
 
     public JmsExchange receive(long timeout) {

Added: camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java?rev=787558&view=auto
==============================================================================
--- camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
(added)
+++ camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
Tue Jun 23 05:47:24 2009
@@ -0,0 +1,86 @@
+/**
+ * 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;
+
+import java.util.concurrent.Executors;
+import javax.jms.ConnectionFactory;
+
+import org.apache.activemq.ActiveMQConnectionFactory;
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.PollingConsumer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import static org.apache.camel.component.jms.JmsComponent.jmsComponentClientAcknowledge;
+
+/**
+ * @version $Revision$
+ */
+public class JmsPollingConsumerTest extends ContextTestSupport {
+
+    public void testJmsPollingConsumer() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedBodiesReceived("Hello Claus");
+
+        // use another thread for polling consumer to demonstrate that we can wait before
+        // the message is sent to the quueue
+        Executors.newSingleThreadExecutor().execute(new Runnable() {
+            public void run() {
+                try {
+                    PollingConsumer consumer = context.getEndpoint("activemq:queue.start").createPollingConsumer();
+                    consumer.start();
+                    Exchange exchange = consumer.receive();
+                    String body = exchange.getIn().getBody(String.class);
+                    template.sendBody("activemq:queue.foo", body + " Claus");
+                    consumer.stop();
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        });
+
+        // wait a little to demonstrate we can start poll before we have a msg on the queue
+        Thread.sleep(50);
+
+        template.sendBody("direct:start", "Hello");
+
+        assertMockEndpointsSatisfied();
+    }
+
+
+    protected CamelContext createCamelContext() throws Exception {
+        CamelContext camelContext = super.createCamelContext();
+
+        ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
+        camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
+
+        return camelContext;
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("activemq:queue.start");
+
+                from("activemq:queue.foo").to("mock:result");
+            }
+        };
+    }
+
+}

Propchange: camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/branches/camel-1.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/JmsPollingConsumerTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message