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 2015/06/02 00:40:16 UTC
qpid-jms git commit: https://issues.apache.org/jira/browse/QPIDJMS-64
Repository: qpid-jms
Updated Branches:
refs/heads/master 74acf459f -> 6bd44c040
https://issues.apache.org/jira/browse/QPIDJMS-64
Throw a more consistent error when connections fail to be created,
cleans up the exception support class a bit.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/6bd44c04
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/6bd44c04
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/6bd44c04
Branch: refs/heads/master
Commit: 6bd44c040f9f4625aae0eb6a57cd01f0995be3b7
Parents: 74acf45
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Jun 1 18:40:07 2015 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Jun 1 18:40:07 2015 -0400
----------------------------------------------------------------------
.../apache/qpid/jms/JmsConnectionFactory.java | 2 +-
.../jms/exceptions/JmsExceptionSupport.java | 129 ++++++++++++-------
.../qpid/jms/JmsConnectionFactoryTest.java | 25 ++++
3 files changed, 112 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6bd44c04/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 86fa364..47a936f 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
@@ -180,7 +180,7 @@ public class JmsConnectionFactory extends JNDIStorable implements ConnectionFact
JmsConnection result = new JmsConnection(connectionId, provider, getClientIdGenerator());
return configureConnection(result, username, password);
} catch (Exception e) {
- throw JmsExceptionSupport.create(e);
+ throw JmsExceptionSupport.create("Failed to create connection to: " + getRemoteURI(), e);
}
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6bd44c04/qpid-jms-client/src/main/java/org/apache/qpid/jms/exceptions/JmsExceptionSupport.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/exceptions/JmsExceptionSupport.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/exceptions/JmsExceptionSupport.java
index 81f9ca8..4440219 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/exceptions/JmsExceptionSupport.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/exceptions/JmsExceptionSupport.java
@@ -32,71 +32,114 @@ public final class JmsExceptionSupport {
private JmsExceptionSupport() {}
- public static JMSException create(String msg, Throwable cause) {
- JMSException exception = new JMSException(msg);
- exception.initCause(cause);
- return exception;
- }
-
- public static JMSException create(String msg, Exception cause) {
- JMSException exception = new JMSException(msg);
- exception.setLinkedException(cause);
- exception.initCause(cause);
- return exception;
- }
-
- public static JMSException create(Throwable cause) {
+ /**
+ * Creates or passes through a JMSException to be thrown to the client.
+ *
+ * In the event that the exception passed to this method is already a
+ * JMSException it is passed through unmodified, otherwise a new JMSException
+ * is created with the given message and the cause is set to the given
+ * cause Throwable instance.
+ *
+ * @param message
+ * The message value to set when a new JMSException is created.
+ * @param cause
+ * The exception that caused this error state.
+ *
+ * @return a JMSException instance.
+ */
+ public static JMSException create(String message, Throwable cause) {
if (cause instanceof JMSException) {
return (JMSException) cause;
}
+
if (cause.getCause() instanceof JMSException) {
return (JMSException) cause.getCause();
}
- String msg = cause.getMessage();
- if (msg == null || msg.length() == 0) {
- msg = cause.toString();
+ if (message == null || message.isEmpty()) {
+ message = cause.getMessage();
+ if (message == null || message.isEmpty()) {
+ message = cause.toString();
+ }
+ }
+
+ JMSException exception = new JMSException(message);
+ if (cause instanceof Exception) {
+ exception.setLinkedException((Exception) cause);
}
- JMSException exception = new JMSException(msg);
exception.initCause(cause);
return exception;
}
- public static JMSException create(Exception cause) {
- if (cause instanceof JMSException) {
- return (JMSException) cause;
- }
- if (cause.getCause() instanceof JMSException) {
- return (JMSException) cause.getCause();
- }
+ /**
+ * Creates or passes through a JMSException to be thrown to the client.
+ *
+ * In the event that the exception passed to this method is already a
+ * JMSException it is passed through unmodified, otherwise a new JMSException
+ * is created using the error message taken from the given Throwable value
+ * and the cause value is set to the given Throwable instance.
+ *
+ * @param cause
+ * The exception that caused this error state.
+ *
+ * @return a JMSException instance.
+ */
+ public static JMSException create(Throwable cause) {
+ return create(null, cause);
+ }
- String msg = cause.getMessage();
- if (msg == null || msg.length() == 0) {
- msg = cause.toString();
+ /**
+ * Creates or passes through a MessageEOFException to be thrown to the client.
+ *
+ * In the event that the exception passed to this method is already a
+ * MessageEOFException it is passed through unmodified, otherwise a new
+ * MessageEOFException is created using the error message taken from the
+ * given Throwable value and the cause value is set to the given Throwable
+ * instance.
+ *
+ * @param cause
+ * The exception that caused this error state.
+ *
+ * @return a MessageEOFException instance.
+ */
+ public static MessageEOFException createMessageEOFException(Throwable cause) {
+ String message = cause.getMessage();
+ if (message == null || message.length() == 0) {
+ message = cause.toString();
}
- JMSException exception = new JMSException(msg);
- exception.setLinkedException(cause);
- exception.initCause(cause);
- return exception;
- }
- public static MessageEOFException createMessageEOFException(Exception cause) {
- String msg = cause.getMessage();
- if (msg == null || msg.length() == 0) {
- msg = cause.toString();
+ MessageEOFException exception = new MessageEOFException(message);
+ if (cause instanceof Exception) {
+ exception.setLinkedException((Exception) cause);
}
- MessageEOFException exception = new MessageEOFException(msg);
- exception.setLinkedException(cause);
exception.initCause(cause);
return exception;
}
+ /**
+ * Creates or passes through a MessageFormatException to be thrown to the client.
+ *
+ * In the event that the exception passed to this method is already a
+ * MessageFormatException it is passed through unmodified, otherwise a new
+ * MessageFormatException is created using the error message taken from the
+ * given Throwable value and the cause value is set to the given Throwable
+ * instance.
+ *
+ * @param cause
+ * The exception that caused this error state.
+ *
+ * @return a MessageEOFException instance.
+ */
public static MessageFormatException createMessageFormatException(Throwable cause) {
- String msg = cause.getMessage();
- if (msg == null || msg.length() == 0) {
- msg = cause.toString();
+ String message = cause.getMessage();
+ if (message == null || message.length() == 0) {
+ message = cause.toString();
+ }
+
+ MessageFormatException exception = new MessageFormatException(message);
+ if (cause instanceof Exception) {
+ exception.setLinkedException((Exception) cause);
}
- MessageFormatException exception = new MessageFormatException(msg);
exception.initCause(cause);
return exception;
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/6bd44c04/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
index 3527db2..c645920 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/JmsConnectionFactoryTest.java
@@ -40,9 +40,13 @@ import javax.jms.JMSException;
import org.apache.qpid.jms.test.QpidJmsTestCase;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class JmsConnectionFactoryTest extends QpidJmsTestCase {
+ private static final Logger LOG = LoggerFactory.getLogger(JmsConnectionFactoryTest.class);
+
private static final String CLIENT_ID_PROP = "clientID";
private static final String QUEUE_PREFIX_PROP = "queuePrefix";
private static final String TOPIC_PREFIX_PROP = "topicPrefix";
@@ -398,4 +402,25 @@ public class JmsConnectionFactoryTest extends QpidJmsTestCase {
assertFalse("Properties map should not contain ExceptionListener", props.containsKey("exceptionListener"));
assertEquals("Properties were not equal", props, props2);
}
+
+ @Test(timeout = 5000)
+ public void testCreateConnectionWithPortOutOfRange() throws Exception {
+ JmsConnectionFactory factory = new JmsConnectionFactory("amqp://127.0.0.1:567564562");
+
+ try {
+ factory.createConnection();
+ fail("Should have thrown exception");
+ } catch (JMSException jmse) {
+ LOG.debug("Caught Ex -> ", jmse);
+ }
+
+ factory = new JmsConnectionFactory("amqp://127.0.0.1:5675645622");
+
+ try {
+ factory.createConnection();
+ fail("Should have thrown exception");
+ } catch (JMSException jmse) {
+ LOG.debug("Caught Ex -> ", jmse);
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org