Search in sources :

Example 16 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.

the class ServerMessageImpl method setOriginalHeaders.

@Override
public void setOriginalHeaders(ServerMessage otherServerMessage, MessageReference originalReference, boolean expiry) {
    ICoreMessage other = otherServerMessage.getICoreMessage();
    SimpleString originalQueue = other.getSimpleStringProperty(Message.HDR_ORIGINAL_QUEUE);
    if (originalQueue != null) {
        message.putStringProperty(Message.HDR_ORIGINAL_QUEUE, originalQueue);
    } else if (originalReference != null) {
        message.putStringProperty(Message.HDR_ORIGINAL_QUEUE, originalReference.getQueue().getName());
    }
    if (other.containsProperty(Message.HDR_ORIG_MESSAGE_ID)) {
        message.putStringProperty(Message.HDR_ORIGINAL_ADDRESS, other.getSimpleStringProperty(Message.HDR_ORIGINAL_ADDRESS));
        message.putLongProperty(Message.HDR_ORIG_MESSAGE_ID, other.getLongProperty(Message.HDR_ORIG_MESSAGE_ID));
    } else {
        message.putStringProperty(Message.HDR_ORIGINAL_ADDRESS, new SimpleString(other.getAddress()));
        message.putLongProperty(Message.HDR_ORIG_MESSAGE_ID, other.getMessageID());
    }
    // reset expiry
    message.setExpiration(0);
    if (expiry) {
        long actualExpiryTime = System.currentTimeMillis();
        message.putLongProperty(Message.HDR_ACTUAL_EXPIRY_TIME, actualExpiryTime);
    }
// TODO ASk clebert
// message.bufferValid = false;
}
Also used : ICoreMessage(org.apache.activemq.artemis.api.core.ICoreMessage) SimpleString(org.apache.activemq.artemis.api.core.SimpleString)

Example 17 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.

the class ManagementServiceImplTest method testHandleManagementMessageWithOperationWhichFails.

@Test
public void testHandleManagementMessageWithOperationWhichFails() throws Exception {
    Configuration config = createBasicConfig().setJMXManagementEnabled(false);
    ActiveMQServer server = addServer(ActiveMQServers.newActiveMQServer(config, false));
    server.start();
    // invoke attribute and operation on the server
    CoreMessage message = new CoreMessage(1, 100);
    ManagementHelper.putOperationInvocation(message, ResourceNames.BROKER, "thereIsNoSuchOperation");
    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 18 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage in project activemq-artemis by apache.

the class ManagementServiceImplTest method testHandleManagementMessageWithKnownAttribute.

@Test
public void testHandleManagementMessageWithKnownAttribute() 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.putAttribute(message, ResourceNames.BROKER, "attribute.Does.Not.Exist");
    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 19 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage 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 20 with ICoreMessage

use of org.apache.activemq.artemis.api.core.ICoreMessage 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)

Aggregations

ICoreMessage (org.apache.activemq.artemis.api.core.ICoreMessage)39 Test (org.junit.Test)24 AMQPMessage (org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage)17 CoreMessage (org.apache.activemq.artemis.core.message.impl.CoreMessage)10 AmqpValue (org.apache.qpid.proton.amqp.messaging.AmqpValue)10 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)9 Message (org.apache.qpid.proton.message.Message)7 ApplicationProperties (org.apache.qpid.proton.amqp.messaging.ApplicationProperties)6 MessageImpl (org.apache.qpid.proton.message.impl.MessageImpl)6 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)4 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)4 ServerJMSBytesMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSBytesMessage)3 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)3 ServerJMSStreamMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSStreamMessage)3 ServerJMSTextMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSTextMessage)3 HashMap (java.util.HashMap)2 ClientMessageImpl (org.apache.activemq.artemis.core.client.impl.ClientMessageImpl)2 PagedMessage (org.apache.activemq.artemis.core.paging.PagedMessage)2 LargeServerMessage (org.apache.activemq.artemis.core.server.LargeServerMessage)2