Search in sources :

Example 11 with InternalMessageHeader

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);
}
Also used : ReplyTo(org.apache.qpid.server.protocol.v0_10.transport.ReplyTo) HashMap(java.util.HashMap) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Example 12 with InternalMessageHeader

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]);
}
Also used : InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader)

Example 13 with InternalMessageHeader

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");
    }
}
Also used : InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ManagedObject(org.apache.qpid.server.model.ManagedObject) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 14 with InternalMessageHeader

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());
    }
}
Also used : InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) ManagedObject(org.apache.qpid.server.model.ManagedObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject) ConfiguredObjectOperation(org.apache.qpid.server.model.ConfiguredObjectOperation)

Example 15 with InternalMessageHeader

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);
}
Also used : InternalMessage(org.apache.qpid.server.message.internal.InternalMessage) InternalMessageMetaData(org.apache.qpid.server.message.internal.InternalMessageMetaData) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) AMQMessageHeader(org.apache.qpid.server.message.AMQMessageHeader)

Aggregations

InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)22 InternalMessageMetaData (org.apache.qpid.server.message.internal.InternalMessageMetaData)9 HashMap (java.util.HashMap)7 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)7 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)6 ManagedObject (org.apache.qpid.server.model.ManagedObject)6 AMQMessageHeader (org.apache.qpid.server.message.AMQMessageHeader)5 InternalMessage (org.apache.qpid.server.message.internal.InternalMessage)5 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)3 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)2 AccessControlException (java.security.AccessControlException)1 Certificate (java.security.cert.Certificate)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 ArrayList (java.util.ArrayList)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 AmqpConnectionMetaData (org.apache.qpid.server.connection.AmqpConnectionMetaData)1 ConfiguredObjectOperation (org.apache.qpid.server.model.ConfiguredObjectOperation)1 IntegrityViolationException (org.apache.qpid.server.model.IntegrityViolationException)1 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)1