You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-commits@axis.apache.org by ve...@apache.org on 2016/12/19 13:14:15 UTC

svn commit: r1775081 - in /axis/axis2/java/core/trunk/modules/transport/jms: pom.xml src/main/java/org/apache/axis2/transport/jms/JMSUtils.java src/test/java/org/apache/axis2/transport/jms/JMSUtilsTest.java

Author: veithen
Date: Mon Dec 19 13:14:15 2016
New Revision: 1775081

URL: http://svn.apache.org/viewvc?rev=1775081&view=rev
Log:
AXIS2-5825: Correctly handle JMS session instances that implement Session, but not QueueSession or TopicSession.

Added:
    axis/axis2/java/core/trunk/modules/transport/jms/src/test/java/org/apache/axis2/transport/jms/JMSUtilsTest.java
Modified:
    axis/axis2/java/core/trunk/modules/transport/jms/pom.xml
    axis/axis2/java/core/trunk/modules/transport/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java

Modified: axis/axis2/java/core/trunk/modules/transport/jms/pom.xml
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/jms/pom.xml?rev=1775081&r1=1775080&r2=1775081&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/jms/pom.xml (original)
+++ axis/axis2/java/core/trunk/modules/transport/jms/pom.xml Mon Dec 19 13:14:15 2016
@@ -167,6 +167,16 @@
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.google.truth</groupId>
+            <artifactId>truth</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
     
     <properties>

Modified: axis/axis2/java/core/trunk/modules/transport/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java?rev=1775081&r1=1775080&r2=1775081&view=diff
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java (original)
+++ axis/axis2/java/core/trunk/modules/transport/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java Mon Dec 19 13:14:15 2016
@@ -431,9 +431,17 @@ public class JMSUtils extends BaseUtils
         throws JMSException {
 
         if (dest instanceof Queue) {
-            return ((QueueSession) session).createReceiver((Queue) dest, messageSelector);
+            if (session instanceof QueueSession) {
+                return ((QueueSession) session).createReceiver((Queue) dest, messageSelector);
+            } else {
+                return session.createConsumer(dest, messageSelector);
+            }
         } else {
-            return ((TopicSession) session).createSubscriber((Topic) dest, messageSelector, false);
+            if (session instanceof TopicSession) {
+                return ((TopicSession) session).createSubscriber((Topic) dest, messageSelector, false);
+            } else {
+                return session.createConsumer(dest, messageSelector);
+            }
         }
     }
 

Added: axis/axis2/java/core/trunk/modules/transport/jms/src/test/java/org/apache/axis2/transport/jms/JMSUtilsTest.java
URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/transport/jms/src/test/java/org/apache/axis2/transport/jms/JMSUtilsTest.java?rev=1775081&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/transport/jms/src/test/java/org/apache/axis2/transport/jms/JMSUtilsTest.java (added)
+++ axis/axis2/java/core/trunk/modules/transport/jms/src/test/java/org/apache/axis2/transport/jms/JMSUtilsTest.java Mon Dec 19 13:14:15 2016
@@ -0,0 +1,40 @@
+/*
+ * 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.axis2.transport.jms;
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import javax.jms.MessageConsumer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.junit.Test;
+
+public class JMSUtilsTest {
+    @Test
+    public void testAxis2_5825() throws Exception {
+        Queue queue = mock(Queue.class);
+        Session session = mock(Session.class);
+        MessageConsumer consumer = mock(MessageConsumer.class);
+        when(session.createConsumer(queue, null)).thenReturn(consumer);
+        assertThat(JMSUtils.createConsumer(session, queue, null)).isSameAs(consumer);
+    }
+}