qpid-jms git commit: QPIDJMS-312 Add check for session mode range

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

qpid-jms git commit: QPIDJMS-312 Add check for session mode range

tabish
Repository: qpid-jms
Updated Branches:
  refs/heads/master b59477d34 -> d4d318d55


QPIDJMS-312 Add check for session mode range

Update JmsContext with missing check for session mode range

Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/d4d318d5
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/d4d318d5
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/d4d318d5

Branch: refs/heads/master
Commit: d4d318d5592d270282326a38a47b1e893dd44784
Parents: b59477d
Author: Timothy Bish <[hidden email]>
Authored: Wed Aug 9 09:56:54 2017 -0400
Committer: Timothy Bish <[hidden email]>
Committed: Wed Aug 9 09:56:54 2017 -0400

----------------------------------------------------------------------
 .../apache/qpid/jms/JmsConnectionFactory.java    | 15 +--------------
 .../java/org/apache/qpid/jms/JmsContext.java     |  2 ++
 .../java/org/apache/qpid/jms/JmsSession.java     | 14 ++++++++++++++
 .../java/org/apache/qpid/jms/JmsContextTest.java | 19 +++++++++++++++++++
 4 files changed, 36 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d4d318d5/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
index 41d2adc..91ee9ec 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsConnectionFactory.java
@@ -27,7 +27,6 @@ import javax.jms.ConnectionFactory;
 import javax.jms.ExceptionListener;
 import javax.jms.JMSContext;
 import javax.jms.JMSException;
-import javax.jms.JMSRuntimeException;
 import javax.jms.QueueConnection;
 import javax.jms.QueueConnectionFactory;
 import javax.jms.TopicConnection;
@@ -307,7 +306,7 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact
 
     @Override
     public JMSContext createContext(String username, String password, int sessionMode) {
-        validateSessionMode(sessionMode);
+        JmsSession.validateSessionMode(sessionMode);
         try {
             JmsConnection connection = (JmsConnection) createConnection(username, password);
             return new JmsContext(connection, sessionMode);
@@ -413,18 +412,6 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact
         }
     }
 
-    private static void validateSessionMode(int mode) {
-        switch (mode) {
-            case JMSContext.AUTO_ACKNOWLEDGE:
-            case JMSContext.CLIENT_ACKNOWLEDGE:
-            case JMSContext.DUPS_OK_ACKNOWLEDGE:
-            case JMSContext.SESSION_TRANSACTED:
-                return;
-            default:
-                throw new JMSRuntimeException("Invalid Session Mode: " + mode);
-        }
-    }
-
     /**
      * @return the user name used for connection authentication.
      */

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d4d318d5/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
index e5d0f18..37d7216 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsContext.java
@@ -278,6 +278,8 @@ public class JmsContext implements JMSContext, AutoCloseable {
             throw new IllegalStateRuntimeException("The Connection is closed");
         }
 
+        JmsSession.validateSessionMode(sessionMode);
+
         connectionRefCount.incrementAndGet();
 
         return new JmsContext(connection, sessionMode, connectionRefCount);

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d4d318d5/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
index bde6bd6..6654d70 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsSession.java
@@ -44,7 +44,9 @@ import javax.jms.Destination;
 import javax.jms.IllegalStateException;
 import javax.jms.InvalidDestinationException;
 import javax.jms.InvalidSelectorException;
+import javax.jms.JMSContext;
 import javax.jms.JMSException;
+import javax.jms.JMSRuntimeException;
 import javax.jms.MapMessage;
 import javax.jms.Message;
 import javax.jms.MessageConsumer;
@@ -1218,6 +1220,18 @@ public class JmsSession implements AutoCloseable, Session, QueueSession, TopicSe
         sessionRecovered = false;
     }
 
+    static void validateSessionMode(int mode) {
+        switch (mode) {
+            case JMSContext.AUTO_ACKNOWLEDGE:
+            case JMSContext.CLIENT_ACKNOWLEDGE:
+            case JMSContext.DUPS_OK_ACKNOWLEDGE:
+            case JMSContext.SESSION_TRANSACTED:
+                return;
+            default:
+                throw new JMSRuntimeException("Invalid Session Mode: " + mode);
+        }
+    }
+
     //----- Event handlers ---------------------------------------------------//
 
     @Override

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/d4d318d5/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java
index ba57e8d..21d5f50 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsContextTest.java
@@ -38,6 +38,7 @@ import javax.jms.IllegalStateException;
 import javax.jms.IllegalStateRuntimeException;
 import javax.jms.JMSContext;
 import javax.jms.JMSException;
+import javax.jms.JMSRuntimeException;
 import javax.jms.JMSSecurityException;
 import javax.jms.MapMessage;
 import javax.jms.Message;
@@ -122,6 +123,24 @@ public class JmsContextTest extends JmsConnectionTestSupport {
     }
 
     @Test
+    public void testCreateContextWithNegativeSessionModeThrowsJMSRE() {
+        try {
+            context.createContext(-1);
+            fail("Should throw JMSRuntimeException");
+        } catch (JMSRuntimeException jmsre) {
+        }
+    }
+
+    @Test
+    public void testCreateContextWithSessionModeOutOfRangeThrowsJMSRE() {
+        try {
+            context.createContext(4);
+            fail("Should throw JMSRuntimeException");
+        } catch (JMSRuntimeException jmsre) {
+        }
+    }
+
+    @Test
     public void testCreateTextMessage() throws JMSException {
         TextMessage message = context.createTextMessage();
         assertNotNull(message);


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Loading...