ARTEMIS-2753 Fixing OpenWire Temporary queue names over wildcard configurations
diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQConsumer.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQConsumer.java
index cb9c74b..cefd027 100644
--- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQConsumer.java
+++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQConsumer.java
@@ -139,7 +139,13 @@
          }
       }
 
-      SimpleString destinationName = new SimpleString(session.convertWildcard(openwireDestination.getPhysicalName()));
+      SimpleString destinationName;
+      if (openwireDestination.isTemporary()) {
+         destinationName = new SimpleString(openwireDestination.getPhysicalName());
+      } else {
+         destinationName = new SimpleString(session.convertWildcard(openwireDestination.getPhysicalName()));
+      }
+
       if (openwireDestination.isTopic()) {
          SimpleString queueName = createTopicSubscription(info.isDurable(), info.getClientId(), destinationName.toString(), info.getSubscriptionName(), selector, destinationName);
 
diff --git a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java
index 79b969e..af7a194 100644
--- a/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java
+++ b/artemis-protocols/artemis-openwire-protocol/src/main/java/org/apache/activemq/artemis/core/protocol/openwire/amq/AMQSession.java
@@ -183,7 +183,12 @@
          }
          if (openWireDest.isQueue()) {
             openWireDest = protocolManager.virtualTopicConsumerToFQQN(openWireDest);
-            SimpleString queueName = new SimpleString(convertWildcard(openWireDest.getPhysicalName()));
+            SimpleString queueName;
+            if (!openWireDest.isTemporary()) {
+               queueName = new SimpleString(convertWildcard(openWireDest.getPhysicalName()));
+            } else {
+               queueName = new SimpleString(openWireDest.getPhysicalName());
+            }
 
             if (!checkAutoCreateQueue(queueName, openWireDest.isTemporary())) {
                throw new InvalidDestinationException("Destination doesn't exist: " + queueName);
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/RedeployTempTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/RedeployTempTest.java
index 7ba1746..23a6491 100644
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/RedeployTempTest.java
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/jms/RedeployTempTest.java
@@ -42,6 +42,7 @@
 import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
 import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
 import org.apache.activemq.artemis.utils.ReusableLatch;
+import org.junit.Assert;
 import org.junit.Test;
 
 public class RedeployTempTest extends ActiveMQTestBase {
@@ -102,6 +103,7 @@
 
          MessageConsumer messageConsumerProducer = session.createConsumer(replyTo);
          Message message2 = messageConsumerProducer.receive(1000);
+         Assert.assertNotNull(message2);
          assertEquals("hi there", ((TextMessage) message2).getText());
 
       } finally {
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/TempQueueWithDotTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/TempQueueWithDotTest.java
new file mode 100644
index 0000000..ebfd3b2
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/openwire/TempQueueWithDotTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.activemq.artemis.tests.integration.openwire;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
+
+import org.apache.activemq.artemis.core.config.Configuration;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.utils.Wait;
+import org.jboss.logging.Logger;
+import org.junit.Assert;
+import org.junit.Test;
+
+/** This test would fail only if your hostname contains dot on its name.
+ * my box name was in the format of xxx-xxx.xxx when it failed. */
+public class TempQueueWithDotTest extends BasicOpenWireTest {
+
+   private static final Logger log = Logger.getLogger(TempQueueWithDotTest.class);
+
+   @Override
+   protected Configuration createDefaultConfig(final int serverID, final boolean netty) throws Exception {
+      Configuration configuration = super.createDefaultConfig(serverID, netty);
+      configuration.getWildcardConfiguration().setDelimiter('_');
+      return configuration;
+   }
+
+   /** This fails sometimes on some computers depending on your computer name.
+    * It failed for me when I used xxx-xxxx.xxx.
+    * As Openwire will use your uname as the temp queue ID. */
+   @Test
+   public void testSimple() throws Exception {
+      testSimple("OPENWIRE");
+      testSimple("CORE");
+   }
+
+   public void testSimple(String protocol) throws Exception {
+      ConnectionFactory factory = CFUtil.createConnectionFactory(protocol, getConnectionUrl());
+      Connection connection = factory.createConnection();
+      try {
+         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+         Queue dest = session.createTemporaryQueue();
+         String queueName = dest.getQueueName();
+         Wait.waitFor(() -> server.locateQueue(queueName) != null);
+         org.apache.activemq.artemis.core.server.Queue queue = server.locateQueue(queueName);
+         MessageConsumer consumer = null;
+         try {
+            consumer = session.createConsumer(dest);
+         } catch (Exception e) {
+            e.printStackTrace();
+            // I'm calling fail because openwire sends the stacktrace for the server, not the client in case of a failure
+            fail(e.getMessage());
+         }
+
+         MessageProducer producer = session.createProducer(dest);
+         producer.send(session.createTextMessage("hello"));
+
+         Wait.assertEquals(1, queue::getMessageCount);
+
+         connection.start();
+
+         Assert.assertNotNull(consumer.receive(500));
+      } finally {
+         connection.close();
+      }
+   }
+
+}