[1/2] activemq-artemis git commit: This closes #2442

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[1/2] activemq-artemis git commit: This closes #2442

jbertram
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 0acd70698 -> 552b7793d


This closes #2442


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/552b7793
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/552b7793
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/552b7793

Branch: refs/heads/master
Commit: 552b7793d30a902015ab31fc611b9c9a69d4eccc
Parents: 0acd706 672f536
Author: Justin Bertram <[hidden email]>
Authored: Fri Dec 14 15:20:34 2018 -0600
Committer: Justin Bertram <[hidden email]>
Committed: Fri Dec 14 15:20:34 2018 -0600

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQDestination.java | 37 ++++++++++++++-
 .../artemis/jms/client/ActiveMQMessage.java     | 25 ++++++----
 .../artemis/jms/client/ActiveMQSession.java     |  4 +-
 .../ActiveMQBytesCompatibleMessage.java         |  4 ++
 .../compatible1X/ActiveMQCompatibleMessage.java | 49 +++++++++++++++++++-
 .../ActiveMQMapCompatibleMessage.java           |  5 ++
 .../ActiveMQObjectCompatibleMessage.java        |  4 ++
 .../ActiveMQStreamCompatibleMessage.java        |  4 ++
 .../ActiveMQTextCompabileMessage.java           |  4 ++
 .../resources/ReplyToTest/replyToReceive.groovy |  2 +-
 .../tests/compatibility/ReplyToTest.java        |  5 +-
 11 files changed, 125 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


Reply | Threaded
Open this post in threaded view
|

[2/2] activemq-artemis git commit: ARTEMIS-2139 Fix setJMSReplyTo for 1.x clients with enable1xPrefixes

jbertram
ARTEMIS-2139 Fix setJMSReplyTo for 1.x clients with enable1xPrefixes


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/672f5362
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/672f5362
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/672f5362

Branch: refs/heads/master
Commit: 672f5362228b9550c883d389ac6acceaad593451
Parents: 0acd706
Author: Francesco Nigro <[hidden email]>
Authored: Thu Nov 22 16:12:59 2018 +0100
Committer: Justin Bertram <[hidden email]>
Committed: Fri Dec 14 15:20:34 2018 -0600

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQDestination.java | 37 ++++++++++++++-
 .../artemis/jms/client/ActiveMQMessage.java     | 25 ++++++----
 .../artemis/jms/client/ActiveMQSession.java     |  4 +-
 .../ActiveMQBytesCompatibleMessage.java         |  4 ++
 .../compatible1X/ActiveMQCompatibleMessage.java | 49 +++++++++++++++++++-
 .../ActiveMQMapCompatibleMessage.java           |  5 ++
 .../ActiveMQObjectCompatibleMessage.java        |  4 ++
 .../ActiveMQStreamCompatibleMessage.java        |  4 ++
 .../ActiveMQTextCompabileMessage.java           |  4 ++
 .../resources/ReplyToTest/replyToReceive.groovy |  2 +-
 .../tests/compatibility/ReplyToTest.java        |  5 +-
 11 files changed, 125 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
index 54178c0..9bdc486 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQDestination.java
@@ -24,10 +24,11 @@ import java.util.Properties;
 import java.util.UUID;
 
 import org.apache.activemq.artemis.api.core.Pair;
+import org.apache.activemq.artemis.api.core.ParameterisedAddress;
 import org.apache.activemq.artemis.api.core.QueueAttributes;
 import org.apache.activemq.artemis.api.core.SimpleString;
+import org.apache.activemq.artemis.core.protocol.core.impl.PacketImpl;
 import org.apache.activemq.artemis.jndi.JNDIStorable;
-import org.apache.activemq.artemis.api.core.ParameterisedAddress;
 
 /**
  * ActiveMQ Artemis implementation of a JMS Destination.
@@ -127,6 +128,40 @@ public class ActiveMQDestination extends JNDIStorable implements Destination, Se
       return destination;
    }
 
+   public static Destination fromPrefixed1XName(final String addr, final String name) {
+      ActiveMQDestination destination;
+      if (addr.startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())) {
+         destination = createQueue(addr);
+      } else if (addr.startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())) {
+         destination = createTopic(addr);
+      } else if (addr.startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())) {
+         destination = new ActiveMQTemporaryQueue(addr, null);
+      } else if (addr.startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())) {
+         destination = new ActiveMQTemporaryTopic(addr, null);
+      } else {
+         destination = new ActiveMQDestination(addr, TYPE.DESTINATION, null);
+      }
+
+      String unprefixedName = name;
+
+      if (name.startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())) {
+         unprefixedName = name.substring(PacketImpl.OLD_QUEUE_PREFIX.length());
+      } else if (name.startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())) {
+         unprefixedName = name.substring(PacketImpl.OLD_TOPIC_PREFIX.length());
+      } else if (name.startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())) {
+         unprefixedName = name.substring(PacketImpl.OLD_TEMP_QUEUE_PREFIX.length());
+      } else if (name.startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())) {
+         unprefixedName = name.substring(PacketImpl.OLD_TEMP_TOPIC_PREFIX.length());
+      }
+
+      destination.setName(unprefixedName);
+
+      return destination;
+   }
+
+
+
+
    public static SimpleString createQueueNameForSubscription(final boolean isDurable,
                                                        final String clientID,
                                                        final String subscriptionName) {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
index af74a3e..bb210de 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQMessage.java
@@ -385,16 +385,7 @@ public class ActiveMQMessage implements javax.jms.Message {
             throw new InvalidDestinationException("Foreign destination " + dest);
          }
 
-         String prefix = "";
-         if (dest instanceof ActiveMQTemporaryQueue) {
-            prefix = TEMP_QUEUE_QUALIFED_PREFIX;
-         } else if (dest instanceof ActiveMQQueue) {
-            prefix = QUEUE_QUALIFIED_PREFIX;
-         } else if (dest instanceof ActiveMQTemporaryTopic) {
-            prefix = TEMP_TOPIC_QUALIFED_PREFIX;
-         } else if (dest instanceof ActiveMQTopic) {
-            prefix = TOPIC_QUALIFIED_PREFIX;
-         }
+         String prefix = prefixOf(dest);
          ActiveMQDestination jbd = (ActiveMQDestination) dest;
 
          MessageUtil.setJMSReplyTo(message, prefix + jbd.getAddress());
@@ -403,6 +394,20 @@ public class ActiveMQMessage implements javax.jms.Message {
       }
    }
 
+   protected static String prefixOf(Destination dest) {
+      String prefix = "";
+      if (dest instanceof ActiveMQTemporaryQueue) {
+         prefix = TEMP_QUEUE_QUALIFED_PREFIX;
+      } else if (dest instanceof ActiveMQQueue) {
+         prefix = QUEUE_QUALIFIED_PREFIX;
+      } else if (dest instanceof ActiveMQTemporaryTopic) {
+         prefix = TEMP_TOPIC_QUALIFED_PREFIX;
+      } else if (dest instanceof ActiveMQTopic) {
+         prefix = TOPIC_QUALIFIED_PREFIX;
+      }
+      return prefix;
+   }
+
    protected SimpleString checkPrefix(SimpleString address) {
       return address;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
index ae68283..693ab84 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
@@ -219,9 +219,9 @@ public class ActiveMQSession implements QueueSession, TopicSession {
 
       ActiveMQStreamMessage message;
       if (enable1xPrefixes) {
-         message = new ActiveMQStreamMessage(session);
-      } else {
          message = new ActiveMQStreamCompatibleMessage(session);
+      } else {
+         message = new ActiveMQStreamMessage(session);
       }
       return message;
    }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQBytesCompatibleMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQBytesCompatibleMessage.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQBytesCompatibleMessage.java
index 626b5a5..a52d0d8 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQBytesCompatibleMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQBytesCompatibleMessage.java
@@ -33,6 +33,10 @@ public class ActiveMQBytesCompatibleMessage extends ActiveMQBytesMessage {
       return ActiveMQCompatibleMessage.checkPrefix1X(address);
    }
 
+   @Override
+   public void setJMSReplyTo(Destination dest) throws JMSException {
+      replyTo = ActiveMQCompatibleMessage.setCompatibleReplyTo(dest, message);
+   }
 
    @Override
    public Destination getJMSReplyTo() throws JMSException {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQCompatibleMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQCompatibleMessage.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQCompatibleMessage.java
index 1b21cbf..ec4e720 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQCompatibleMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQCompatibleMessage.java
@@ -18,6 +18,7 @@
 package org.apache.activemq.artemis.jms.client.compatible1X;
 
 import javax.jms.Destination;
+import javax.jms.InvalidDestinationException;
 import javax.jms.JMSException;
 import javax.jms.JMSRuntimeException;
 import javax.jms.Message;
@@ -69,11 +70,39 @@ public class ActiveMQCompatibleMessage extends ActiveMQMessage {
       return replyTo;
    }
 
-   public static Destination findCompatibleReplyTo(ClientMessage message) {
+   @Override
+   public void setJMSReplyTo(Destination dest) throws JMSException {
+      replyTo = setCompatibleReplyTo(dest, message);
+   }
+
+   static Destination setCompatibleReplyTo(Destination dest, ClientMessage message) throws InvalidDestinationException {
+      if (dest == null) {
+         MessageUtil.setJMSReplyTo(message, (String) null);
+         return null;
+      } else {
+         if (dest instanceof ActiveMQDestination == false) {
+            throw new InvalidDestinationException("Foreign destination " + dest);
+         }
+         ActiveMQDestination jbd = (ActiveMQDestination) dest;
+         final String address = jbd.getAddress();
+         if (hasPrefix1X(address)) {
+            MessageUtil.setJMSReplyTo(message, jbd.getAddress());
+         } else {
+            String prefix = prefixOf(dest);
+            MessageUtil.setJMSReplyTo(message, prefix + jbd.getAddress());
+         }
+         return jbd;
+      }
+   }
+
+   static Destination findCompatibleReplyTo(ClientMessage message) {
       SimpleString address = MessageUtil.getJMSReplyTo(message);
       if (address != null) {
+         final SimpleString checkedAddress = checkPrefix1X(address);
+         if (checkedAddress != null) {
+            return ActiveMQDestination.fromPrefixed1XName(address.toString(), checkedAddress.toString());
+         }
          String name = address.toString();
-
          // swap the old prefixes for the new ones so the proper destination type gets created
          if (address.startsWith(OLD_QUEUE_QUALIFIED_PREFIX)) {
             name = address.subSeq(OLD_QUEUE_QUALIFIED_PREFIX.length(), address.length()).toString();
@@ -95,6 +124,22 @@ public class ActiveMQCompatibleMessage extends ActiveMQMessage {
       return checkPrefix1X(address);
    }
 
+   private static boolean hasPrefix1X(String address) {
+      if (address != null) {
+         if (address.startsWith(PacketImpl.OLD_QUEUE_PREFIX.toString())) {
+            return true;
+         } else if (address.startsWith(PacketImpl.OLD_TEMP_QUEUE_PREFIX.toString())) {
+            return true;
+         } else if (address.startsWith(PacketImpl.OLD_TOPIC_PREFIX.toString())) {
+            return true;
+         } else if (address.startsWith(PacketImpl.OLD_TEMP_TOPIC_PREFIX.toString())) {
+            return true;
+         }
+      }
+
+      return false;
+   }
+
    protected static SimpleString checkPrefix1X(SimpleString address) {
       if (address != null) {
          if (address.startsWith(PacketImpl.OLD_QUEUE_PREFIX)) {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQMapCompatibleMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQMapCompatibleMessage.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQMapCompatibleMessage.java
index 2d6e576..1fd2cae 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQMapCompatibleMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQMapCompatibleMessage.java
@@ -34,6 +34,11 @@ public class ActiveMQMapCompatibleMessage extends ActiveMQMapMessage {
    }
 
    @Override
+   public void setJMSReplyTo(Destination dest) throws JMSException {
+      replyTo = ActiveMQCompatibleMessage.setCompatibleReplyTo(dest, message);
+   }
+
+   @Override
    public Destination getJMSReplyTo() throws JMSException {
       if (replyTo == null) {
          replyTo = ActiveMQCompatibleMessage.findCompatibleReplyTo(message);

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQObjectCompatibleMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQObjectCompatibleMessage.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQObjectCompatibleMessage.java
index 13a9d7d..0a1a802 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQObjectCompatibleMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQObjectCompatibleMessage.java
@@ -34,6 +34,10 @@ public class ActiveMQObjectCompatibleMessage extends ActiveMQObjectMessage {
       return ActiveMQCompatibleMessage.checkPrefix1X(address);
    }
 
+   @Override
+   public void setJMSReplyTo(Destination dest) throws JMSException {
+      replyTo = ActiveMQCompatibleMessage.setCompatibleReplyTo(dest, message);
+   }
 
    @Override
    public Destination getJMSReplyTo() throws JMSException {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQStreamCompatibleMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQStreamCompatibleMessage.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQStreamCompatibleMessage.java
index bb2fda6..3b176cf 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQStreamCompatibleMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQStreamCompatibleMessage.java
@@ -33,6 +33,10 @@ public class ActiveMQStreamCompatibleMessage extends ActiveMQStreamMessage {
       return ActiveMQCompatibleMessage.checkPrefix1X(address);
    }
 
+   @Override
+   public void setJMSReplyTo(Destination dest) throws JMSException {
+      replyTo = ActiveMQCompatibleMessage.setCompatibleReplyTo(dest, message);
+   }
 
    @Override
    public Destination getJMSReplyTo() throws JMSException {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQTextCompabileMessage.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQTextCompabileMessage.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQTextCompabileMessage.java
index 451c582..ae8aa52 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQTextCompabileMessage.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/compatible1X/ActiveMQTextCompabileMessage.java
@@ -27,6 +27,10 @@ import org.apache.activemq.artemis.jms.client.ActiveMQTextMessage;
 
 public class ActiveMQTextCompabileMessage extends ActiveMQTextMessage {
 
+   @Override
+   public void setJMSReplyTo(Destination dest) throws JMSException {
+      replyTo = ActiveMQCompatibleMessage.setCompatibleReplyTo(dest, message);
+   }
 
    @Override
    public Destination getJMSReplyTo() throws JMSException {

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/tests/compatibility-tests/src/main/resources/ReplyToTest/replyToReceive.groovy
----------------------------------------------------------------------
diff --git a/tests/compatibility-tests/src/main/resources/ReplyToTest/replyToReceive.groovy b/tests/compatibility-tests/src/main/resources/ReplyToTest/replyToReceive.groovy
index 156cbdb..7cfa673 100644
--- a/tests/compatibility-tests/src/main/resources/ReplyToTest/replyToReceive.groovy
+++ b/tests/compatibility-tests/src/main/resources/ReplyToTest/replyToReceive.groovy
@@ -76,7 +76,7 @@ void check(List<Message> messages) {
     checkMessage(streamMessage);
 
     TextMessage textMessage = iterator.next();
-    checkMessage(objectMessage);
+    checkMessage(textMessage);
 }
 
 

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/672f5362/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
----------------------------------------------------------------------
diff --git a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
index fb7846c..1f1699f 100644
--- a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
+++ b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
@@ -113,8 +113,9 @@ public class ReplyToTest extends ServerBase {
       combinations.add(new Object[]{SNAPSHOT, ONE_FIVE, ONE_FIVE});
       combinations.add(new Object[]{ONE_FIVE, SNAPSHOT, SNAPSHOT});
 
-      // TODO: It's not currently possible to mix reply to between 1.x and SNAPSHOT. Both sides need to be on the same version!
-      // combinations.addAll(combinatory(SNAPSHOT, new Object[]{SNAPSHOT, ONE_FIVE}, new Object[]{SNAPSHOT, ONE_FIVE}, new Object[]{SNAPSHOT, ONE_FIVE}));
+      combinations.add(new Object[]{ONE_FIVE, SNAPSHOT, ONE_FIVE});
+      combinations.add(new Object[]{ONE_FIVE, ONE_FIVE, SNAPSHOT});
+
       return combinations;
    }