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;
}
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));
}
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));
}
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));
}
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;
}
Aggregations