Search in sources :

Example 21 with CoreMessage

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));
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Configuration(org.apache.activemq.artemis.core.config.Configuration) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) Test(org.junit.Test)

Example 22 with CoreMessage

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;
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) InvocationTargetException(java.lang.reflect.InvocationTargetException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 23 with CoreMessage

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));
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Test(org.junit.Test)

Example 24 with CoreMessage

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);
    }
}
Also used : PostOfficeJournalLoader(org.apache.activemq.artemis.core.server.impl.PostOfficeJournalLoader) GroupingInfo(org.apache.activemq.artemis.core.persistence.GroupingInfo) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) Message(org.apache.activemq.artemis.api.core.Message) HashMap(java.util.HashMap) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueBindingInfo(org.apache.activemq.artemis.core.persistence.QueueBindingInfo) FakePostOffice(org.apache.activemq.artemis.tests.unit.core.server.impl.fakes.FakePostOffice) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) AddressBindingInfo(org.apache.activemq.artemis.core.persistence.AddressBindingInfo) Queue(org.apache.activemq.artemis.core.server.Queue) FakeQueue(org.apache.activemq.artemis.tests.unit.core.postoffice.impl.FakeQueue) Test(org.junit.Test)

Example 25 with CoreMessage

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();
}
Also used : SessionSendLargeMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionSendLargeMessage) ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) CoreMessage(org.apache.activemq.artemis.core.message.impl.CoreMessage)

Aggregations

CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)48 Test (org.junit.Test)20 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)17 ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)16 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)11 Message (org.apache.activemq.artemis.api.core.Message)11 Configuration (org.apache.activemq.artemis.core.config.Configuration)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 ByteBuf (io.netty.buffer.ByteBuf)5 LinkedList (java.util.LinkedList)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)3 PagingStoreImpl (org.apache.activemq.artemis.core.paging.impl.PagingStoreImpl)3 JournalStorageManager (org.apache.activemq.artemis.core.persistence.impl.journal.JournalStorageManager)3 RoutingContext (org.apache.activemq.artemis.core.server.RoutingContext)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InstanceNotFoundException (javax.management.InstanceNotFoundException)2 MBeanRegistrationException (javax.management.MBeanRegistrationException)2 PageCursorProvider (org.apache.activemq.artemis.core.paging.cursor.PageCursorProvider)2 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)2