ARTEMIS-1107 - fix and Test AddressControl.sendMessage()

https://issues.apache.org/jira/browse/ARTEMIS-1107
This commit is contained in:
Andy Taylor 2017-04-11 08:29:43 +01:00
parent 0032a5df92
commit fb3de112e4
3 changed files with 36 additions and 4 deletions

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.activemq.artemis.api.core.ActiveMQException; 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.RoutingType;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.api.core.management.AddressControl; import org.apache.activemq.artemis.api.core.management.AddressControl;
@ -300,7 +301,11 @@ public class AddressControlImpl extends AbstractControl implements AddressContro
message.setDurable(durable); message.setDurable(durable);
message.setTimestamp(System.currentTimeMillis()); message.setTimestamp(System.currentTimeMillis());
if (body != null) { 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()); message.setAddress(addressInfo.getName());
postOffice.route(message, true); postOffice.route(message, true);

View File

@ -262,7 +262,7 @@ public class ProtonTest extends ProtonTestBase {
AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mBeanServer); AddressControl addressControl = ManagementControlHelper.createAddressControl(address, mBeanServer);
Assert.assertEquals(1, addressControl.getQueueNames().length); 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()); 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 @Test
public void testDurableSubscriptionUnsubscribe() throws Exception { public void testDurableSubscriptionUnsubscribe() throws Exception {
Connection connection = createConnection("myClientId"); Connection connection = createConnection("myClientId");

View File

@ -23,7 +23,6 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; 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.JsonUtil;
import org.apache.activemq.artemis.api.core.Message; import org.apache.activemq.artemis.api.core.Message;
import org.apache.activemq.artemis.api.core.RoutingType; 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.client.ServerLocator;
import org.apache.activemq.artemis.api.core.management.AddressControl; import org.apache.activemq.artemis.api.core.management.AddressControl;
import org.apache.activemq.artemis.api.core.management.RoleInfo; 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.config.Configuration;
import org.apache.activemq.artemis.core.security.CheckType; import org.apache.activemq.artemis.core.security.CheckType;
import org.apache.activemq.artemis.core.security.Role; import org.apache.activemq.artemis.core.security.Role;