use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class MessageConverter_v0_10_to_Internal method convertHeader.
private AMQMessageHeader convertHeader(final MessageTransferMessage serverMessage, final NamedAddressSpace addressSpace, final Object convertedBodyObject, final String encoding) {
final String convertedMimeType = getInternalConvertedMimeType(serverMessage, convertedBodyObject);
final AMQMessageHeader messageHeader = serverMessage.getMessageHeader();
Map<String, Object> headers = new HashMap<>();
messageHeader.getHeaderNames().forEach(headerName -> headers.put(headerName, messageHeader.getHeader(headerName)));
final InternalMessageHeader header = new InternalMessageHeader(headers, messageHeader.getCorrelationId(), messageHeader.getExpiration(), messageHeader.getUserId(), messageHeader.getAppId(), messageHeader.getMessageId(), convertedMimeType, messageHeader.getEncoding(), messageHeader.getPriority(), messageHeader.getTimestamp(), messageHeader.getNotValidBefore(), messageHeader.getType(), messageHeader.getReplyTo(), serverMessage.getArrivalTime());
MessageProperties messageProps = serverMessage.getHeader().getMessageProperties();
final ReplyTo replyTo = messageProps == null ? null : messageProps.getReplyTo();
return new DelegatingMessageHeader(header, replyTo, encoding);
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method createFailureResponse.
private InternalMessage createFailureResponse(final InternalMessage requestMessage, final int statusCode, final String stateDescription, Object... params) {
final InternalMessageHeader requestHeader = requestMessage.getMessageHeader();
final MutableMessageHeader responseHeader = new MutableMessageHeader();
responseHeader.setCorrelationId(requestHeader.getCorrelationId() == null ? requestHeader.getMessageId() : requestHeader.getCorrelationId());
responseHeader.setMessageId(UUID.randomUUID().toString());
for (String header : requestHeader.getHeaderNames()) {
responseHeader.setHeader(header, requestHeader.getHeader(header));
}
responseHeader.setHeader(STATUS_CODE_HEADER, statusCode);
responseHeader.setHeader(STATUS_DESCRIPTION_HEADER, params.length == 0 ? stateDescription : MessageFormat.format(stateDescription, params));
return InternalMessage.createBytesMessage(_addressSpace.getMessageStore(), responseHeader, new byte[0]);
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method performCreateOperation.
private InternalMessage performCreateOperation(final Class<? extends ConfiguredObject> clazz, final InternalMessage message) {
InternalMessageHeader requestHeader = message.getMessageHeader();
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_CREATED);
if (message.getMessageBody() instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Object> attributes = (Map<String, Object>) message.getMessageBody();
if (attributes.containsKey(IDENTITY_ATTRIBUTE)) {
return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "The '" + IDENTITY_ATTRIBUTE + "' cannot be set when creating an object");
}
if (attributes.containsKey(ConfiguredObject.ID)) {
return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "The '" + ConfiguredObject.ID + "' cannot be set when creating an object");
}
if (!attributes.containsKey(QPID_TYPE) && ConfiguredObjectTypeRegistry.getCategory(clazz) != clazz) {
Class<? extends ConfiguredObject> typeClass = _model.getTypeRegistry().getTypeClass(clazz);
String type = typeClass.getAnnotation(ManagedObject.class).type();
if (!"".equals(type)) {
attributes.put(QPID_TYPE, type);
}
}
if (attributes.containsKey(OBJECT_PATH)) {
String path = String.valueOf(attributes.remove(OBJECT_PATH));
ConfiguredObject theParent = _managedObject;
final Class<? extends ConfiguredObject>[] hierarchy = _configuredObjectFinder.getHierarchy(clazz);
if (hierarchy.length > 1) {
ConfiguredObject parent = _configuredObjectFinder.findObjectParentsFromPath(Arrays.asList(getPathElements(path)), hierarchy, ConfiguredObjectTypeRegistry.getCategory(clazz));
if (parent == null) {
return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "The '" + OBJECT_PATH + "' " + path + " does not identify a valid parent");
}
theParent = parent;
}
return doCreate(clazz, message, responseHeader, attributes, theParent);
} else if (_configuredObjectFinder.getHierarchy(clazz).length == 1 && attributes.containsKey(ConfiguredObject.NAME)) {
return doCreate(clazz, message, responseHeader, attributes, _managedObject);
} else {
return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "The '" + OBJECT_PATH + "' must be supplied");
}
} else {
return createFailureResponse(message, STATUS_CODE_BAD_REQUEST, "Message body must be a map");
}
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class ManagementNode method performOperation.
private InternalMessage performOperation(final Class<? extends ConfiguredObject> clazz, final String operation, InternalMessage message) {
try {
if (STANDARD_OPERATIONS.contains(operation)) {
StandardOperation standardOperation;
if ((standardOperation = _standardOperations.get(clazz).get(operation)) != null) {
return standardOperation.performOperation(clazz, message);
}
} else {
final InternalMessageHeader requestHeader = message.getMessageHeader();
final Map<String, Object> headers = requestHeader.getHeaderMap();
ConfiguredObject<?> object = findObject(clazz, headers);
if (object == null) {
return createFailureResponse(message, STATUS_CODE_NOT_FOUND, "Not found");
}
final Map<String, ConfiguredObjectOperation<?>> operations = _model.getTypeRegistry().getOperations(object.getClass());
@SuppressWarnings("unchecked") final ConfiguredObjectOperation<ConfiguredObject<?>> method = (ConfiguredObjectOperation<ConfiguredObject<?>>) operations.get(operation);
if (method != null) {
return performConfiguredObjectOperation(object, message, method);
}
}
return createFailureResponse(message, STATUS_CODE_NOT_IMPLEMENTED, "Not implemented");
} catch (RuntimeException e) {
return createFailureResponse(message, STATUS_CODE_INTERNAL_ERROR, e.getMessage());
}
}
use of org.apache.qpid.server.message.internal.InternalMessageHeader in project qpid-broker-j by apache.
the class PropertyConverter_Internal_to_v1_0Test method createTestMessage.
private InternalMessage createTestMessage(String to) {
final InternalMessageHeader internalMessageHeader = new InternalMessageHeader(mock(AMQMessageHeader.class));
final StoredMessage<InternalMessageMetaData> handle = createInternalStoredMessage(null, false, internalMessageHeader);
return new InternalMessage(handle, internalMessageHeader, null, to);
}
Aggregations