Search in sources :

Example 6 with MessageMetaData_0_10

use of org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10 in project qpid-broker-j by apache.

the class MessageFormat_0_10 method createMessage.

@Override
public MessageTransferMessage createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
    try {
        ServerDecoder serverDecoder = new ServerDecoder(payload);
        int headerCount = serverDecoder.readInt32();
        DeliveryProperties deliveryProperties = null;
        MessageProperties messageProperties = null;
        List<Struct> nonStandard = null;
        for (int i = 0; i < headerCount; i++) {
            final Struct struct = serverDecoder.readStruct32();
            switch(struct.getStructType()) {
                case DeliveryProperties.TYPE:
                    deliveryProperties = (DeliveryProperties) struct;
                    break;
                case MessageProperties.TYPE:
                    messageProperties = (MessageProperties) struct;
                    break;
                default:
                    if (nonStandard == null) {
                        nonStandard = new ArrayList<>();
                    }
                    nonStandard.add(struct);
            }
        }
        Header header = new Header(deliveryProperties, messageProperties, nonStandard);
        MessageMetaData_0_10 metaData = new MessageMetaData_0_10(header, payload.remaining(), System.currentTimeMillis());
        final MessageHandle<MessageMetaData_0_10> handle = store.addMessage(metaData);
        handle.addContent(payload);
        final StoredMessage<MessageMetaData_0_10> storedMessage = handle.allContentAdded();
        return new MessageTransferMessage(storedMessage, connectionReference);
    } catch (BufferUnderflowException e) {
        throw new ConnectionScopedRuntimeException("Error parsing AMQP 0-10 message format", e);
    }
}
Also used : DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties) Struct(org.apache.qpid.server.protocol.v0_10.transport.Struct) Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) ConnectionScopedRuntimeException(org.apache.qpid.server.util.ConnectionScopedRuntimeException) BufferUnderflowException(java.nio.BufferUnderflowException)

Example 7 with MessageMetaData_0_10

use of org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10 in project qpid-broker-j by apache.

the class MessageTransferMessageMutator method create.

@Override
public MessageTransferMessage create() {
    final Header header = new Header(_deliveryProperties, _messageProperties);
    final MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(header, (int) _message.getSize(), _message.getArrivalTime());
    final QpidByteBuffer content = _message.getContent();
    final MessageHandle<MessageMetaData_0_10> addedMessage = _messageStore.addMessage(messageMetaData);
    if (content != null) {
        addedMessage.addContent(content);
    }
    return new MessageTransferMessage(addedMessage.allContentAdded(), _message.getConnectionReference());
}
Also used : Header(org.apache.qpid.server.protocol.v0_10.transport.Header) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer)

Example 8 with MessageMetaData_0_10

use of org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10 in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v0_10 method convertMetaData.

private MessageMetaData_0_10 convertMetaData(final InternalMessage serverMsg, final NamedAddressSpace addressSpace, final String bodyMimeType, final int size) {
    DeliveryProperties deliveryProps = new DeliveryProperties();
    MessageProperties messageProps = new MessageProperties();
    deliveryProps.setDeliveryMode(serverMsg.isPersistent() ? MessageDeliveryMode.PERSISTENT : MessageDeliveryMode.NON_PERSISTENT);
    long expiration = serverMsg.getExpiration();
    if (expiration > 0) {
        deliveryProps.setExpiration(expiration);
        deliveryProps.setTtl(Math.max(0, expiration - serverMsg.getArrivalTime()));
    }
    InternalMessageHeader messageHeader = serverMsg.getMessageHeader();
    deliveryProps.setPriority(MessageDeliveryPriority.get(messageHeader.getPriority()));
    convertToAndInitialRoutingKey(serverMsg, deliveryProps, addressSpace);
    deliveryProps.setTimestamp(messageHeader.getTimestamp());
    messageProps.setContentEncoding(ensureStr8("content-encoding", messageHeader.getEncoding()));
    messageProps.setContentLength(size);
    messageProps.setContentType(bodyMimeType);
    if (messageHeader.getCorrelationId() != null) {
        messageProps.setCorrelationId(ensureVBin16("correlation-id", messageHeader.getCorrelationId().getBytes(UTF_8)));
    }
    validateValue(messageHeader.getHeaderMap(), "application-headers");
    messageProps.setApplicationHeaders(messageHeader.getHeaderMap());
    String messageIdAsString = messageHeader.getMessageId();
    if (messageIdAsString != null) {
        try {
            if (messageIdAsString.startsWith("ID:")) {
                messageIdAsString = messageIdAsString.substring(3);
            }
            messageProps.setMessageId(UUID.fromString(messageIdAsString));
        } catch (IllegalArgumentException iae) {
        // ignore message id is not a UUID
        }
    }
    String userId = messageHeader.getUserId();
    if (userId != null) {
        byte[] bytes = userId.getBytes(UTF_8);
        if (bytes.length <= MAX_VBIN16_LENGTH) {
            messageProps.setUserId(bytes);
        }
    }
    final String origReplyTo = messageHeader.getReplyTo();
    if (origReplyTo != null && !origReplyTo.equals("")) {
        messageProps.setReplyTo(getReplyTo(addressSpace, origReplyTo));
    }
    Header header = new Header(deliveryProps, messageProps, null);
    return new MessageMetaData_0_10(header, size, serverMsg.getArrivalTime());
}
Also used : Header(org.apache.qpid.server.protocol.v0_10.transport.Header) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) InternalMessageHeader(org.apache.qpid.server.message.internal.InternalMessageHeader) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)

Example 9 with MessageMetaData_0_10

use of org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10 in project qpid-broker-j by apache.

the class MessageTransferMessageMutatorTest method createTestMessage.

private MessageTransferMessage createTestMessage() {
    final DeliveryProperties deliveryProperties = new DeliveryProperties();
    deliveryProperties.setPriority(MessageDeliveryPriority.get(TEST_PRIORITY));
    final MessageProperties messageProperties = new MessageProperties();
    messageProperties.setContentType(TEST_CONTENT_TYPE);
    messageProperties.setApplicationHeaders(Collections.singletonMap(TEST_HEADER_NAME, TEST_HEADER_VALUE));
    final Header header = new Header(deliveryProperties, messageProperties);
    final QpidByteBuffer content = QpidByteBuffer.wrap(TEST_CONTENT.getBytes(UTF_8));
    final MessageMetaData_0_10 messageMetaData = new MessageMetaData_0_10(header, content.remaining(), System.currentTimeMillis());
    final MessageHandle<MessageMetaData_0_10> addedMessage = _messageStore.addMessage(messageMetaData);
    addedMessage.addContent(content);
    return new MessageTransferMessage(addedMessage.allContentAdded(), null);
}
Also used : Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)

Example 10 with MessageMetaData_0_10

use of org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10 in project qpid-broker-j by apache.

the class MessageConverter_v0_10 method convertMetaData.

private MessageMetaData_0_10 convertMetaData(ServerMessage serverMsg) {
    DeliveryProperties deliveryProps = new DeliveryProperties();
    MessageProperties messageProps = new MessageProperties();
    int size = (int) serverMsg.getSize();
    deliveryProps.setExpiration(serverMsg.getExpiration());
    deliveryProps.setPriority(MessageDeliveryPriority.get(serverMsg.getMessageHeader().getPriority()));
    deliveryProps.setRoutingKey(serverMsg.getInitialRoutingAddress());
    deliveryProps.setTimestamp(serverMsg.getMessageHeader().getTimestamp());
    messageProps.setContentEncoding(serverMsg.getMessageHeader().getEncoding());
    messageProps.setContentLength(size);
    messageProps.setContentType(serverMsg.getMessageHeader().getMimeType());
    if (serverMsg.getMessageHeader().getCorrelationId() != null) {
        messageProps.setCorrelationId(serverMsg.getMessageHeader().getCorrelationId().getBytes(UTF_8));
    }
    Header header = new Header(deliveryProps, messageProps, null);
    return new MessageMetaData_0_10(header, size, serverMsg.getArrivalTime());
}
Also used : Header(org.apache.qpid.server.protocol.v0_10.transport.Header) MessageProperties(org.apache.qpid.server.protocol.v0_10.transport.MessageProperties) DeliveryProperties(org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)

Aggregations

Header (org.apache.qpid.server.protocol.v0_10.transport.Header)7 MessageMetaData_0_10 (org.apache.qpid.server.protocol.v0_10.MessageMetaData_0_10)6 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)6 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)6 UUID (java.util.UUID)2 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)2 MessageTransferMessage (org.apache.qpid.server.protocol.v0_10.MessageTransferMessage)2 StoredMessage (org.apache.qpid.server.store.StoredMessage)2 URISyntaxException (java.net.URISyntaxException)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 InternalMessageHeader (org.apache.qpid.server.message.internal.InternalMessageHeader)1 ReplyTo (org.apache.qpid.server.protocol.v0_10.transport.ReplyTo)1 Struct (org.apache.qpid.server.protocol.v0_10.transport.Struct)1 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)1 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)1 ConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.ConvertedContentAndMimeType)1 MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType (org.apache.qpid.server.protocol.v1_0.MessageConverter_from_1_0.getAmqp0xConvertedContentAndMimeType)1 MessageMetaData_1_0 (org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)1