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/03/14 16:45:47 UTC
qpid-jms git commit: https://issues.apache.org/jira/browse/QPIDJMS-155
Repository: qpid-jms
Updated Branches:
refs/heads/master 9f2f7c59f -> 7ff492048
https://issues.apache.org/jira/browse/QPIDJMS-155
Allow for more information to be present when creating the exception
from a given error condition. Throw a JMSException when the connection
sees that amqp:not-found error during an open attempt.
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/7ff49204
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/7ff49204
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/7ff49204
Branch: refs/heads/master
Commit: 7ff4920483c011824b9ad71930c081916d07b6b2
Parents: 9f2f7c5
Author: Timothy Bish <ta...@gmail.com>
Authored: Mon Mar 14 11:42:10 2016 -0400
Committer: Timothy Bish <ta...@gmail.com>
Committed: Mon Mar 14 11:42:10 2016 -0400
----------------------------------------------------------------------
.../qpid/jms/JmsResourceNotFoundException.java | 37 ++++++++++++++++++++
.../jms/provider/amqp/AmqpAbstractResource.java | 2 +-
.../jms/provider/amqp/AmqpFixedProducer.java | 4 +--
.../qpid/jms/provider/amqp/AmqpSupport.java | 13 +++++--
.../amqp/AmqpTransactionCoordinator.java | 4 +--
.../amqp/builders/AmqpResourceBuilder.java | 2 +-
.../FailedConnectionsIntegrationTest.java | 25 +++++++++++++
7 files changed, 79 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7ff49204/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsResourceNotFoundException.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsResourceNotFoundException.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsResourceNotFoundException.java
new file mode 100644
index 0000000..3597833
--- /dev/null
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsResourceNotFoundException.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+import javax.jms.JMSException;
+
+/**
+ * Thrown when the remote peer return amqp:not-found for instances other
+ * than those that would generate an InvalidDestinationException or some
+ * other more situation appropriate JMSException instance.
+ */
+public class JmsResourceNotFoundException extends JMSException {
+
+ private static final long serialVersionUID = -4811726481264524424L;
+
+ public JmsResourceNotFoundException(String reason) {
+ super(reason);
+ }
+
+ public JmsResourceNotFoundException(String reason, String errorCode) {
+ super(reason, errorCode);
+ }
+}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7ff49204/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
index b9111e8..a075900 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpAbstractResource.java
@@ -112,7 +112,7 @@ public abstract class AmqpAbstractResource<R extends JmsResource, E extends Endp
}
public void remotelyClosed(AmqpProvider provider) {
- Exception error = AmqpSupport.convertToException(getEndpoint().getRemoteCondition());
+ Exception error = AmqpSupport.convertToException(getEndpoint(), getEndpoint().getRemoteCondition());
if (parent != null) {
parent.removeChildResource(this);
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7ff49204/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpFixedProducer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpFixedProducer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpFixedProducer.java
index 27eb286..1282138 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpFixedProducer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpFixedProducer.java
@@ -229,7 +229,7 @@ public class AmqpFixedProducer extends AmqpProducer {
remoteError = getEndpoint().getRemoteCondition();
}
- deliveryError = AmqpSupport.convertToException(remoteError);
+ deliveryError = AmqpSupport.convertToException(getEndpoint(), remoteError);
} else if (outcome instanceof Released) {
LOG.trace("Outcome of delivery was released: {}", delivery);
deliveryError = new JMSException("Delivery failed: released by receiver");
@@ -295,7 +295,7 @@ public class AmqpFixedProducer extends AmqpProducer {
public void remotelyClosed(AmqpProvider provider) {
super.remotelyClosed(provider);
- Exception ex = AmqpSupport.convertToException(getEndpoint().getRemoteCondition());
+ Exception ex = AmqpSupport.convertToException(getEndpoint(), getEndpoint().getRemoteCondition());
if (ex == null) {
// TODO: create/use a more specific/appropriate exception type?
ex = new JMSException("Producer closed remotely before message transfer result was notified");
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7ff49204/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 8522fa2..ecbe8fc 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
@@ -26,6 +26,7 @@ import javax.jms.JMSSecurityException;
import javax.jms.ResourceAllocationException;
import javax.jms.TransactionRolledBackException;
+import org.apache.qpid.jms.JmsResourceNotFoundException;
import org.apache.qpid.jms.provider.ProviderRedirectedException;
import org.apache.qpid.proton.amqp.Symbol;
import org.apache.qpid.proton.amqp.messaging.Modified;
@@ -34,6 +35,8 @@ import org.apache.qpid.proton.amqp.transaction.TransactionErrors;
import org.apache.qpid.proton.amqp.transport.AmqpError;
import org.apache.qpid.proton.amqp.transport.ConnectionError;
import org.apache.qpid.proton.amqp.transport.ErrorCondition;
+import org.apache.qpid.proton.engine.Connection;
+import org.apache.qpid.proton.engine.Endpoint;
public class AmqpSupport {
@@ -89,12 +92,14 @@ public class AmqpSupport {
* Given an ErrorCondition instance create a new Exception that best matches
* the error type.
*
+ * @param endpoint
+ * The target of the error.
* @param errorCondition
* The ErrorCondition returned from the remote peer.
*
* @return a new Exception instance that best matches the ErrorCondition value.
*/
- public static Exception convertToException(ErrorCondition errorCondition) {
+ public static Exception convertToException(Endpoint endpoint, ErrorCondition errorCondition) {
Exception remoteError = null;
if (errorCondition != null && errorCondition.getCondition() != null) {
@@ -106,7 +111,11 @@ public class AmqpSupport {
} else if (error.equals(AmqpError.RESOURCE_LIMIT_EXCEEDED)) {
remoteError = new ResourceAllocationException(message);
} else if (error.equals(AmqpError.NOT_FOUND)) {
- remoteError = new InvalidDestinationException(message);
+ if (endpoint instanceof Connection) {
+ remoteError = new JmsResourceNotFoundException(message);
+ } else {
+ remoteError = new InvalidDestinationException(message);
+ }
} else if (error.equals(TransactionErrors.TRANSACTION_ROLLBACK)) {
remoteError = new TransactionRolledBackException(message);
} else if (error.equals(ConnectionError.REDIRECT)) {
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7ff49204/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpTransactionCoordinator.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpTransactionCoordinator.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpTransactionCoordinator.java
index 12e824a..b06f686 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpTransactionCoordinator.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/AmqpTransactionCoordinator.java
@@ -76,7 +76,7 @@ public class AmqpTransactionCoordinator extends AmqpAbstractResource<JmsSessionI
} else if (state instanceof Rejected) {
LOG.debug("Last TX request failed: {}", txId);
Rejected rejected = (Rejected) state;
- Exception cause = AmqpSupport.convertToException(rejected.getError());
+ Exception cause = AmqpSupport.convertToException(getEndpoint(), rejected.getError());
JMSException failureCause = null;
if (txId.getProviderContext() == COMMIT_MARKER) {
failureCause = new TransactionRolledBackException(cause.getMessage());
@@ -162,7 +162,7 @@ public class AmqpTransactionCoordinator extends AmqpAbstractResource<JmsSessionI
@Override
public void remotelyClosed(AmqpProvider provider) {
- Exception txnError = AmqpSupport.convertToException(getEndpoint().getRemoteCondition());
+ Exception txnError = AmqpSupport.convertToException(getEndpoint(), getEndpoint().getRemoteCondition());
// Alert any pending operation that the link failed to complete the pending
// begin / commit / rollback operation.
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7ff49204/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/builders/AmqpResourceBuilder.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/builders/AmqpResourceBuilder.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/builders/AmqpResourceBuilder.java
index 3164fab..c2353e8 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/builders/AmqpResourceBuilder.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/provider/amqp/builders/AmqpResourceBuilder.java
@@ -164,7 +164,7 @@ public abstract class AmqpResourceBuilder<TARGET extends AmqpResource, PARENT ex
Exception openError;
if (hasRemoteError()) {
- openError = AmqpSupport.convertToException(getEndpoint().getRemoteCondition());
+ openError = AmqpSupport.convertToException(getEndpoint(), getEndpoint().getRemoteCondition());
} else {
openError = getOpenAbortException();
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/7ff49204/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
index 4fb4e28..b9c44af 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/integration/FailedConnectionsIntegrationTest.java
@@ -30,6 +30,7 @@ import java.util.Map;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.InvalidClientIDException;
+import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
import org.apache.qpid.jms.JmsConnectionFactory;
@@ -41,6 +42,8 @@ import org.apache.qpid.jms.test.testpeer.basictypes.AmqpError;
import org.apache.qpid.jms.test.testpeer.basictypes.ConnectionError;
import org.apache.qpid.proton.amqp.Symbol;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Test the handling of various error on connection that should return
@@ -48,6 +51,8 @@ import org.junit.Test;
*/
public class FailedConnectionsIntegrationTest extends QpidJmsTestCase {
+ private static final Logger LOG = LoggerFactory.getLogger(FailedConnectionsIntegrationTest.class);
+
@Test(timeout = 20000)
public void testConnectWithInvalidClientIdThrowsJMSEWhenInvalidContainerHintNotPresent() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
@@ -66,6 +71,26 @@ public class FailedConnectionsIntegrationTest extends QpidJmsTestCase {
}
@Test(timeout = 20000)
+ public void testConnectWithNotFoundErrorThrowsJMSEWhenInvalidContainerHintNotPresent() throws Exception {
+ try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
+ testPeer.rejectConnect(AmqpError.NOT_FOUND, "Virtual Host does not exist", null);
+ try {
+ establishAnonymousConnecton(testPeer, true);
+ fail("Should have thrown JMSException");
+ } catch (InvalidDestinationException destEx) {
+ fail("Should not convert to destination exception for this case.");
+ } catch (JMSException jmsEx) {
+ LOG.info("Caught expected Exception: {}", jmsEx.getMessage(), jmsEx);
+ // Expected
+ } catch (Exception ex) {
+ fail("Should have thrown JMSException: " + ex);
+ }
+
+ testPeer.waitForAllHandlersToComplete(1000);
+ }
+ }
+
+ @Test(timeout = 20000)
public void testConnectWithInvalidClientIdThrowsICIDEWhenInvalidContainerHintPresent() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
final String remoteURI = "amqp://localhost:" + testPeer.getServerPort();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org