You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ta...@apache.org on 2016/11/16 23:48:48 UTC

qpid-jms git commit: QPIDJMS-223 Fix handling of redirect exception

Repository: qpid-jms
Updated Branches:
  refs/heads/master 9864e8e01 -> 529ca03c1


QPIDJMS-223 Fix handling of redirect exception

Handle cases where the info in the ErrorCondition is incorrect.

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

Branch: refs/heads/master
Commit: 529ca03c14b680e6cb1a308747975f4f1b57c5bd
Parents: 9864e8e
Author: Timothy Bish <ta...@gmail.com>
Authored: Wed Nov 16 18:48:41 2016 -0500
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Nov 16 18:48:41 2016 -0500

----------------------------------------------------------------------
 .../qpid/jms/provider/amqp/AmqpSupport.java     |  17 ++-
 .../qpid/jms/provider/amqp/AmqpSupportTest.java | 146 +++++++++++++++++++
 2 files changed, 156 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/529ca03c/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
index adac112..7af1de4 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpSupport.java
@@ -213,18 +213,21 @@ public class AmqpSupport {
             String scheme = (String) info.get(SCHEME);
 
             String networkHost = (String) info.get(NETWORK_HOST);
+            int port = 0;
+
             if (networkHost == null || networkHost.isEmpty()) {
                 result = new IOException(message + " : Redirection information not set.");
+            } else {
+                try {
+                    port = Integer.parseInt(info.get(PORT).toString());
+                } catch (Exception ex) {
+                    result = new IOException(message + " : Redirection information not set.");
+                }
             }
 
-            int port = 0;
-            try {
-                port = Integer.parseInt(info.get(PORT).toString());
-            } catch (Exception ex) {
-                result = new IOException(message + " : Redirection information not set.");
+            if (result == null) {
+                result = new ProviderRedirectedException(message, scheme, hostname, networkHost, port, path);
             }
-
-            result = new ProviderRedirectedException(message, scheme, hostname, networkHost, port, path);
         }
 
         return result;

http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/529ca03c/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSupportTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSupportTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSupportTest.java
new file mode 100644
index 0000000..70ebd11
--- /dev/null
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/provider/amqp/AmqpSupportTest.java
@@ -0,0 +1,146 @@
+/*
+ * 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.qpid.jms.provider.amqp;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.qpid.jms.provider.ProviderRedirectedException;
+import org.apache.qpid.proton.amqp.Symbol;
+import org.apache.qpid.proton.amqp.transport.AmqpError;
+import org.apache.qpid.proton.amqp.transport.ErrorCondition;
+import org.junit.Test;
+
+public class AmqpSupportTest {
+
+    @Test
+    public void testCreateRedirectionException() {
+        ErrorCondition condition = new ErrorCondition();
+
+        Map<Symbol, Object> info = new HashMap<>();
+        info.put(AmqpSupport.PORT, "5672");
+        info.put(AmqpSupport.OPEN_HOSTNAME, "localhost.localdomain");
+        info.put(AmqpSupport.NETWORK_HOST, "localhost");
+        info.put(AmqpSupport.SCHEME, "amqp");
+        info.put(AmqpSupport.PATH, "websocket");
+
+        condition.setInfo(info);
+
+        Symbol error = AmqpError.INTERNAL_ERROR;
+        String message = "Failed to connect";
+
+        Exception result = AmqpSupport.createRedirectException(error, message, condition);
+
+        assertNotNull(result);
+        assertTrue(result instanceof ProviderRedirectedException);
+
+        ProviderRedirectedException pre = (ProviderRedirectedException) result;
+
+        assertEquals(5672, pre.getPort());
+        assertEquals("localhost.localdomain", pre.getHostname());
+        assertEquals("localhost", pre.getNetworkHost());
+        assertEquals("amqp", pre.getScheme());
+        assertEquals("websocket", pre.getPath());
+    }
+
+    @Test
+    public void testCreateRedirectionExceptionWithNoRedirectInfo() {
+        ErrorCondition condition = new ErrorCondition();
+        Symbol error = AmqpError.INTERNAL_ERROR;
+        String message = "Failed to connect";
+
+        Exception result = AmqpSupport.createRedirectException(error, message, condition);
+
+        assertNotNull(result);
+        assertFalse(result instanceof ProviderRedirectedException);
+        assertTrue(result instanceof IOException);
+    }
+
+    @Test
+    public void testCreateRedirectionExceptionWithNoNetworkHost() {
+        ErrorCondition condition = new ErrorCondition();
+
+        Map<Symbol, Object> info = new HashMap<>();
+        info.put(AmqpSupport.PORT, "5672");
+        info.put(AmqpSupport.OPEN_HOSTNAME, "localhost");
+        info.put(AmqpSupport.SCHEME, "amqp");
+        info.put(AmqpSupport.PATH, "websocket");
+
+        condition.setInfo(info);
+
+        Symbol error = AmqpError.INTERNAL_ERROR;
+        String message = "Failed to connect";
+
+        Exception result = AmqpSupport.createRedirectException(error, message, condition);
+
+        assertNotNull(result);
+        assertFalse(result instanceof ProviderRedirectedException);
+        assertTrue(result instanceof IOException);
+    }
+
+    @Test
+    public void testCreateRedirectionExceptionWithEmptyNetworkHost() {
+        ErrorCondition condition = new ErrorCondition();
+
+        Map<Symbol, Object> info = new HashMap<>();
+        info.put(AmqpSupport.PORT, "5672");
+        info.put(AmqpSupport.NETWORK_HOST, "");
+        info.put(AmqpSupport.OPEN_HOSTNAME, "localhost");
+        info.put(AmqpSupport.SCHEME, "amqp");
+        info.put(AmqpSupport.PATH, "websocket");
+
+        condition.setInfo(info);
+
+        Symbol error = AmqpError.INTERNAL_ERROR;
+        String message = "Failed to connect";
+
+        Exception result = AmqpSupport.createRedirectException(error, message, condition);
+
+        assertNotNull(result);
+        assertFalse(result instanceof ProviderRedirectedException);
+        assertTrue(result instanceof IOException);
+    }
+
+    @Test
+    public void testCreateRedirectionExceptionWithInvalidPort() {
+        ErrorCondition condition = new ErrorCondition();
+
+        Map<Symbol, Object> info = new HashMap<>();
+        info.put(AmqpSupport.PORT, "L5672");
+        info.put(AmqpSupport.OPEN_HOSTNAME, "localhost");
+        info.put(AmqpSupport.NETWORK_HOST, "localhost");
+        info.put(AmqpSupport.SCHEME, "amqp");
+        info.put(AmqpSupport.PATH, "websocket");
+
+        condition.setInfo(info);
+
+        Symbol error = AmqpError.INTERNAL_ERROR;
+        String message = "Failed to connect";
+
+        Exception result = AmqpSupport.createRedirectException(error, message, condition);
+
+        assertNotNull(result);
+        assertFalse(result instanceof ProviderRedirectedException);
+        assertTrue(result instanceof IOException);
+    }
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org