diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java index a3211659a7..f0a3a77d25 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/management/impl/AddressControlImpl.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import org.apache.activemq.artemis.api.core.ActiveMQException; +import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.RoutingType; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.management.AddressControl; @@ -300,7 +301,11 @@ public class AddressControlImpl extends AbstractControl implements AddressContro message.setDurable(durable); message.setTimestamp(System.currentTimeMillis()); if (body != null) { - message.getBodyBuffer().writeBytes(Base64.decode(body)); + if (type == Message.TEXT_TYPE) { + message.getBodyBuffer().writeNullableSimpleString(new SimpleString(body)); + } else { + message.getBodyBuffer().writeBytes(Base64.decode(body)); + } } message.setAddress(addressInfo.getName()); postOffice.route(message, true); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java index f4433383f5..938e7ae75c 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/amqp/ProtonTest.java @@ -262,7 +262,7 @@ public class ProtonTest extends ProtonTestBase { AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mBeanServer); Assert.assertEquals(1, addressControl.getQueueNames().length); - addressControl.sendMessage(null, org.apache.activemq.artemis.api.core.Message.BYTES_TYPE, Base64.encodeBytes("test".getBytes()), false, null, null); + addressControl.sendMessage(null, org.apache.activemq.artemis.api.core.Message.BYTES_TYPE, Base64.encodeBytes("test".getBytes()), false, userName, password); Assert.assertEquals(1, addressControl.getMessageCount()); @@ -285,6 +285,35 @@ public class ProtonTest extends ProtonTestBase { } } + @Test + public void testAddressControlSendMessageWithText() throws Exception { + SimpleString address = RandomUtil.randomSimpleString(); + server.createQueue(address, RoutingType.ANYCAST, address, null, true, false); + + AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mBeanServer); + Assert.assertEquals(1, addressControl.getQueueNames().length); + addressControl.sendMessage(null, org.apache.activemq.artemis.api.core.Message.TEXT_TYPE, "test", false, userName, password); + + Assert.assertEquals(1, addressControl.getMessageCount()); + + Connection connection = createConnection("myClientId"); + try { + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + javax.jms.Queue queue = session.createQueue(address.toString()); + MessageConsumer consumer = session.createConsumer(queue); + Message message = consumer.receive(500); + assertNotNull(message); + String text = ((TextMessage) message).getText(); + assertEquals("test", text); + session.close(); + connection.close(); + } finally { + if (connection != null) { + connection.close(); + } + } + } + @Test public void testDurableSubscriptionUnsubscribe() throws Exception { Connection connection = createConnection("myClientId"); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java index 85f6ecafe1..08781fea9a 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/management/AddressControlTest.java @@ -23,7 +23,6 @@ import java.util.HashSet; import java.util.Set; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; -import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.JsonUtil; import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.RoutingType; @@ -36,7 +35,6 @@ import org.apache.activemq.artemis.api.core.client.ClientSessionFactory; import org.apache.activemq.artemis.api.core.client.ServerLocator; import org.apache.activemq.artemis.api.core.management.AddressControl; import org.apache.activemq.artemis.api.core.management.RoleInfo; -import org.apache.activemq.artemis.core.buffers.impl.ChannelBufferWrapper; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.security.CheckType; import org.apache.activemq.artemis.core.security.Role;