use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method performManagementOperation.
private InternalMessage performManagementOperation(String operation, final InternalMessage msg) {
final InternalMessage responseMessage;
final InternalMessageHeader requestHeader = msg.getMessageHeader();
final MutableMessageHeader responseHeader = new MutableMessageHeader();
responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
responseHeader.setMessageId(UUID.randomUUID().toString());
Map<?, ?> result;
if (GET_TYPES.equals(operation)) {
result = performGetTypes(requestHeader.getHeaderMap());
} else if (GET_ATTRIBUTES.equals(operation)) {
result = performGetAttributes(requestHeader.getHeaderMap());
} else if (GET_OPERATIONS.equals(operation)) {
result = performGetOperations(requestHeader.getHeaderMap());
} else if (QUERY.equals(operation)) {
if (msg.getMessageBody() instanceof Map) {
result = performQuery(requestHeader.getHeaderMap(), (Map) (msg.getMessageBody()));
} else {
return createFailureResponse(msg, STATUS_CODE_BAD_REQUEST, "Body of a QUERY operation must be a map");
}
} else {
return createFailureResponse(msg, STATUS_CODE_NOT_IMPLEMENTED, "Unknown operation {}", operation);
}
responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_OK);
responseMessage = InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, result);
return responseMessage;
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method performUpdateOperation.
private InternalMessage performUpdateOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
InternalMessageHeader requestHeader = message.getMessageHeader();
final Map<String, Object> headers = requestHeader.getHeaderMap();
ConfiguredObject<?> object = findObject(clazz, headers);
if (object != null) {
if (message.getMessageBody() instanceof Map) {
@SuppressWarnings("unchecked") final HashMap<String, Object> attributes = new HashMap<>((Map) message.getMessageBody());
Object id = attributes.remove(IDENTITY_ATTRIBUTE);
if (id != null && !String.valueOf(id).equals(object.getId().toString())) {
return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Cannot change the value of '" + IDENTITY_ATTRIBUTE + "'");
}
String path = (String) attributes.remove(OBJECT_PATH);
Class<? extends ConfiguredObject> parentType = _model.getParentType(clazz);
if (parentType != null) {
String attributeName = parentType.getSimpleName().toLowerCase();
final Object parentValue = attributes.remove(attributeName);
if (parentValue != null && !String.valueOf(parentValue).equals(object.getParent().getName())) {
return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Cannot change the value of '" + attributeName + "'");
}
}
if (path != null && !attributes.containsKey(ConfiguredObject.NAME)) {
String[] pathElements = getPathElements(path);
attributes.put(ConfiguredObject.NAME, pathElements[pathElements.length - 1]);
}
object.setAttributes(attributes);
final MutableMessageHeader responseHeader = new MutableMessageHeader();
responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
responseHeader.setMessageId(UUID.randomUUID().toString());
responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_OK);
return InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, _managementOutputConverter.convertToOutput(object, true));
} else {
return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "Message body must be a map");
}
} else {
return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "No such object");
}
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method performReadOperation.
private InternalMessage performReadOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
InternalMessageHeader requestHeader = message.getMessageHeader();
final Map<String, Object> headers = requestHeader.getHeaderMap();
final boolean actuals = headers.get(ACTUALS_ATTRIBUTE) == null || Boolean.parseBoolean(String.valueOf(headers.get(ACTUALS_ATTRIBUTE)));
ConfiguredObject<?> object = findObject(clazz, headers);
if (object != null) {
final MutableMessageHeader responseHeader = new MutableMessageHeader();
responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
responseHeader.setMessageId(UUID.randomUUID().toString());
responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_OK);
return InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, _managementOutputConverter.convertToOutput(object, actuals));
} else {
return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "Not found");
}
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method performDeleteOperation.
private InternalMessage performDeleteOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
InternalMessageHeader requestHeader = message.getMessageHeader();
final Map<String, Object> headers = requestHeader.getHeaderMap();
ConfiguredObject<?> object = findObject(clazz, headers);
if (object != null) {
try {
object.delete();
final MutableMessageHeader responseHeader = new MutableMessageHeader();
responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
responseHeader.setMessageId(UUID.randomUUID().toString());
responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_NO_CONTENT);
return InternalMessage.createMapMessage(_addressSpace.getMessageStore(), responseHeader, Collections.emptyMap());
} catch (IntegrityViolationException e) {
return createFailureResponse(message, STATUS_CODE_FORBIDDEN, e.getMessage());
}
} else {
return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "Not Found");
}
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method performConfiguredObjectOperation.
private InternalMessage performConfiguredObjectOperation(final ConfiguredObject<?> object, final InternalMessage message, final ConfiguredObjectOperation<ConfiguredObject<?>> method) {
final InternalMessageHeader requestHeader = message.getMessageHeader();
final Map<String, Object> headers = requestHeader.getHeaderMap();
try {
Map<String, Object> parameters = new HashMap<>(headers);
parameters.remove(KEY_ATTRIBUTE);
parameters.remove(IDENTITY_ATTRIBUTE);
parameters.remove(TYPE_ATTRIBUTE);
parameters.remove(INDEX_ATTRIBUTE);
parameters.remove(OPERATION_HEADER);
parameters.keySet().removeIf(paramName -> paramName.startsWith("JMS_QPID"));
AmqpConnectionMetaData callerConnectionMetaData = getCallerConnectionMetaData();
if (method.isSecure(object, parameters) && !(callerConnectionMetaData.getTransport().isSecure() || callerConnectionMetaData.getPort().isAllowConfidentialOperationsOnInsecureChannels())) {
return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Operation '" + method.getName() + "' can only be performed over a secure (AMQPS) connection");
}
final MutableMessageHeader responseHeader = new MutableMessageHeader();
responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
responseHeader.setMessageId(UUID.randomUUID().toString());
responseHeader.setHeader(STATUS_CODE_HEADER, STATUS_CODE_OK);
final Object result = method.perform(object, parameters);
return createManagedOperationResponse(method, responseHeader, result);
} catch (IllegalArgumentException | IllegalStateException | IllegalConfigurationException e) {
return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, e.getMessage());
} catch (AccessControlException e) {
return createFailureResponse(message, STATUS_CODE_FORBIDDEN, "Forbidden");
}
}
Aggregations