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/06/23 08:06:29 UTC

svn commit: r787559 - in /camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms: JmsComponent.java JmsHelper.java JmsPollingConsumer.java

Author: davsclaus
Date: Tue Jun 23 06:06:29 2009
New Revision: 787559

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

Added:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java   (with props)
Modified:
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
    camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java?rev=787559&r1=787558&r2=787559&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsComponent.java Tue Jun 23 06:06:29 2009
@@ -478,12 +478,17 @@
         // lets try instantiate the default implementation
         // use the class loading this class from camel-jms to work in OSGi environments as the camel-jms
         // should import the spring-jms jars.
-        Class<?> type = context.getClassResolver().resolveClass(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 ObjectHelper.newInstance(type, QueueBrowseStrategy.class);
+            // lets try instantiate the default implementation
+            Class<?> type = ObjectHelper.loadClass(DEFAULT_QUEUE_BROWSE_STRATEGY, JmsComponent.class.getClassLoader());
+            if (type != null) {
+                return ObjectHelper.newInstance(type, QueueBrowseStrategy.class);
+            } else {
+                return null;
+            }
         }
     }
 

Added: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java?rev=787559&view=auto
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java (added)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java Tue Jun 23 06:06:29 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/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java?rev=787559&r1=787558&r2=787559&view=diff
==============================================================================
--- camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java (original)
+++ camel/trunk/components/camel-jms/src/main/java/org/apache/camel/component/jms/JmsPollingConsumer.java Tue Jun 23 06:06:29 2009
@@ -20,7 +20,6 @@
 
 import org.apache.camel.Exchange;
 import org.apache.camel.impl.PollingConsumerSupport;
-
 import org.springframework.jms.core.JmsOperations;
 import org.springframework.jms.core.JmsTemplate;
 
@@ -29,10 +28,12 @@
  */
 public class JmsPollingConsumer extends PollingConsumerSupport {
     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 +42,27 @@
     }
 
     public Exchange 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 Exchange 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 Exchange receive(long timeout) {