You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ro...@apache.org on 2016/11/10 12:18:40 UTC
qpid-jms git commit: QPIDJMS-207: throw InvalidDestinationException
not UOE when invalid null dest is provided on send for producers with
explicit destinations
Repository: qpid-jms
Updated Branches:
refs/heads/master 28b3810a1 -> e2be3757c
QPIDJMS-207: throw InvalidDestinationException not UOE when invalid null dest is provided on send for producers with explicit destinations
Project: http://git-wip-us.apache.org/repos/asf/qpid-jms/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-jms/commit/e2be3757
Tree: http://git-wip-us.apache.org/repos/asf/qpid-jms/tree/e2be3757
Diff: http://git-wip-us.apache.org/repos/asf/qpid-jms/diff/e2be3757
Branch: refs/heads/master
Commit: e2be3757c41a622485822cc30e9831abd821a5a8
Parents: 28b3810
Author: Robert Gemmell <ro...@apache.org>
Authored: Thu Nov 10 12:17:00 2016 +0000
Committer: Robert Gemmell <ro...@apache.org>
Committed: Thu Nov 10 12:17:00 2016 +0000
----------------------------------------------------------------------
.../org/apache/qpid/jms/JmsMessageProducer.java | 11 +++++
.../jms/producer/JmsMessageProducerTest.java | 45 ++++++++++++++++++++
2 files changed, 56 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e2be3757/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
index 63fd513..4b574fb 100644
--- a/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
+++ b/qpid-jms-client/src/main/java/org/apache/qpid/jms/JmsMessageProducer.java
@@ -24,6 +24,7 @@ import javax.jms.CompletionListener;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.IllegalStateException;
+import javax.jms.InvalidDestinationException;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageProducer;
@@ -178,6 +179,8 @@ public class JmsMessageProducer implements AutoCloseable, MessageProducer {
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException {
checkClosed();
+ checkDestinationNotInvalid(destination);
+
if (!anonymousProducer) {
throw new UnsupportedOperationException("Using this method is not supported on producers created with an explicit Destination.");
}
@@ -214,6 +217,8 @@ public class JmsMessageProducer implements AutoCloseable, MessageProducer {
public void send(Destination destination, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener listener) throws JMSException {
checkClosed();
+ checkDestinationNotInvalid(destination);
+
if (!anonymousProducer) {
throw new UnsupportedOperationException("Using this method is not supported on producers created with an explicit Destination.");
}
@@ -225,6 +230,12 @@ public class JmsMessageProducer implements AutoCloseable, MessageProducer {
sendMessage(destination, message, deliveryMode, priority, timeToLive, listener);
}
+ private void checkDestinationNotInvalid(Destination destination) throws InvalidDestinationException {
+ if (destination == null) {
+ throw new InvalidDestinationException("Destination must not be null");
+ }
+ }
+
private void sendMessage(Destination destination, Message message, int deliveryMode, int priority, long timeToLive, CompletionListener listener) throws JMSException {
this.session.send(this, destination, message, deliveryMode, priority, timeToLive, disableMessageId, disableTimestamp, deliveryDelay, listener);
}
http://git-wip-us.apache.org/repos/asf/qpid-jms/blob/e2be3757/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
----------------------------------------------------------------------
diff --git a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
index c0c92c3..cec267e 100644
--- a/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
+++ b/qpid-jms-client/src/test/java/org/apache/qpid/jms/producer/JmsMessageProducerTest.java
@@ -46,6 +46,7 @@ import org.apache.qpid.jms.JmsDestination;
import org.apache.qpid.jms.JmsMessageProducer;
import org.apache.qpid.jms.JmsQueue;
import org.apache.qpid.jms.JmsSession;
+import org.apache.qpid.jms.JmsTopic;
import org.apache.qpid.jms.message.JmsOutboundMessageDispatch;
import org.apache.qpid.jms.provider.mock.MockRemotePeer;
import org.apache.qpid.jms.test.Wait;
@@ -217,6 +218,50 @@ public class JmsMessageProducerTest extends JmsConnectionTestSupport {
}
@Test(timeout = 10000)
+ public void testExplicitQueueProducerThrowsIDEWhenNullDestinationIsProvidedOnSend() throws Exception {
+ doExplicitProducerThrowsIDEWhenNullDestinationIsProvidedOnSendTestImpl(new JmsQueue("explicitQueueDest"));
+ }
+
+ @Test(timeout = 10000)
+ public void testExplicitTopicProducerThrowsIDEWhenInvalidDestinationIsProvidedOnSend() throws Exception {
+ doExplicitProducerThrowsIDEWhenNullDestinationIsProvidedOnSendTestImpl(new JmsTopic("explicitTopicDest"));
+ }
+
+ private void doExplicitProducerThrowsIDEWhenNullDestinationIsProvidedOnSendTestImpl(JmsDestination explicitDest) throws JMSException {
+ JmsDestination invalildNullDest = null;
+ JmsMessageProducer producer = (JmsMessageProducer) session.createProducer(explicitDest);
+
+ Message message = Mockito.mock(Message.class);
+ try {
+ producer.send(invalildNullDest, message);
+ fail("Expected exception to be thrown");
+ } catch (InvalidDestinationException ide) {
+ // expected
+ }
+
+ try {
+ producer.send(invalildNullDest, message, completionListener);
+ fail("Expected exception to be thrown");
+ } catch (InvalidDestinationException ide) {
+ // expected
+ }
+
+ try {
+ producer.send(invalildNullDest, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ fail("Expected exception to be thrown");
+ } catch (InvalidDestinationException ide) {
+ // expected
+ }
+
+ try {
+ producer.send(invalildNullDest, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE, completionListener);
+ fail("Expected exception to be thrown");
+ } catch (InvalidDestinationException ide) {
+ // expected
+ }
+ }
+
+ @Test(timeout = 10000)
public void testExplicitProducerThrowsUOEWhenExplictDestinationIsProvided() throws Exception {
JmsDestination dest = new JmsQueue("explicitDestination");
JmsMessageProducer producer = (JmsMessageProducer) session.createProducer(dest);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org