use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class ManagementServiceImplTest method testHandleManagementMessageWithUnknowResource.
@Test
public void testHandleManagementMessageWithUnknowResource() throws Exception {
Configuration config = createBasicConfig().setJMXManagementEnabled(false);
ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
server.start();
// invoke attribute and operation on the server
ICoreMessage message = new CoreMessage(1, 100);
ManagementHelper.putOperationInvocation(message, "Resouce.Does.Not.Exist", "toString");
ICoreMessage reply = server.getManagementService().handleMessage(message);
Assert.assertFalse(ManagementHelper.hasOperationSucceeded(reply));
Assert.assertNotNull(ManagementHelper.getResult(reply));
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class ManagementServiceImpl method handleMessage.
@Override
public ICoreMessage handleMessage(Message message) throws Exception {
message = message.toCore();
// a reply message is sent with the result stored in the message body.
CoreMessage reply = new CoreMessage(storageManager.generateID(), 512);
reply.setType(Message.TEXT_TYPE);
reply.setReplyTo(message.getReplyTo());
String resourceName = message.getStringProperty(ManagementHelper.HDR_RESOURCE_NAME);
if (logger.isDebugEnabled()) {
logger.debug("handling management message for " + resourceName);
}
String operation = message.getStringProperty(ManagementHelper.HDR_OPERATION_NAME);
if (operation != null) {
Object[] params = ManagementHelper.retrieveOperationParameters(message);
if (params == null) {
params = new Object[0];
}
try {
Object result = invokeOperation(resourceName, operation, params);
ManagementHelper.storeResult(reply, result);
reply.putBooleanProperty(ManagementHelper.HDR_OPERATION_SUCCEEDED, true);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.managementOperationError(e, operation, resourceName);
reply.putBooleanProperty(ManagementHelper.HDR_OPERATION_SUCCEEDED, false);
String exceptionMessage;
if (e instanceof InvocationTargetException) {
exceptionMessage = ((InvocationTargetException) e).getTargetException().getMessage();
} else {
exceptionMessage = e.getMessage();
}
ManagementHelper.storeResult(reply, exceptionMessage);
}
} else {
String attribute = message.getStringProperty(ManagementHelper.HDR_ATTRIBUTE);
if (attribute != null) {
try {
Object result = getAttribute(resourceName, attribute);
ManagementHelper.storeResult(reply, result);
reply.putBooleanProperty(ManagementHelper.HDR_OPERATION_SUCCEEDED, true);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.managementAttributeError(e, attribute, resourceName);
reply.putBooleanProperty(ManagementHelper.HDR_OPERATION_SUCCEEDED, false);
String exceptionMessage;
if (e instanceof InvocationTargetException) {
exceptionMessage = ((InvocationTargetException) e).getTargetException().getMessage();
} else {
exceptionMessage = e.getMessage();
}
ManagementHelper.storeResult(reply, exceptionMessage);
}
}
}
return reply;
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class FilterTest method testFilterForgets.
@Test
public void testFilterForgets() throws Exception {
filter = FilterImpl.createFilter(new SimpleString("color = 'RED'"));
message.putStringProperty(new SimpleString("color"), new SimpleString("RED"));
Assert.assertTrue(filter.match(message));
message = new CoreMessage();
Assert.assertFalse(filter.match(message));
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class DeleteMessagesOnStartupTest method testDeleteMessagesOnStartup.
@Test
public void testDeleteMessagesOnStartup() throws Exception {
createStorage();
Queue theQueue = new FakeQueue(new SimpleString(""));
HashMap<Long, Queue> queues = new HashMap<>();
queues.put(100L, theQueue);
Message msg = new CoreMessage(1, 100);
journal.storeMessage(msg);
for (int i = 2; i < 100; i++) {
journal.storeMessage(new CoreMessage(i, 100));
}
journal.storeReference(100, 1, true);
journal.stop();
journal.start();
journal.loadBindingJournal(new ArrayList<QueueBindingInfo>(), new ArrayList<GroupingInfo>(), new ArrayList<AddressBindingInfo>());
FakePostOffice postOffice = new FakePostOffice();
journal.loadMessageJournal(postOffice, null, null, null, null, null, null, new PostOfficeJournalLoader(postOffice, null, journal, null, null, null, null, null, queues));
Assert.assertEquals(98, deletedMessage.size());
for (Long messageID : deletedMessage) {
Assert.assertTrue("messageID = " + messageID, messageID.longValue() >= 2 && messageID <= 99);
}
}
use of org.apache.activemq.artemis.core.message.impl.CoreMessage in project activemq-artemis by apache.
the class ActiveMQSessionContext method sendInitialChunkOnLargeMessage.
@Override
public int sendInitialChunkOnLargeMessage(Message msgI) throws ActiveMQException {
SessionSendLargeMessage initialChunk = new SessionSendLargeMessage(msgI);
sessionChannel.send(initialChunk);
return ((CoreMessage) msgI).getHeadersAndPropertiesEncodeSize();
}
Aggregations