Search in sources :

Example 6 with MessageMetaData_1_0

use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.

the class MessageConverter_1_0_to_v0_8 method convertMetaData.

private MessageMetaData convertMetaData(final Message_1_0 serverMsg, final String bodyMimeType, final int size, final NamedAddressSpace addressSpace) {
    final MessageMetaData_1_0.MessageHeader_1_0 header = serverMsg.getMessageHeader();
    final BasicContentHeaderProperties props = new BasicContentHeaderProperties();
    props.setAppId(serverMsg.getMessageHeader().getAppId());
    props.setContentType(bodyMimeType);
    props.setEncoding(convertToShortStringForProperty("content-encoding", serverMsg.getMessageHeader().getEncoding()));
    props.setCorrelationId(getCorrelationIdAsShortString(serverMsg));
    props.setDeliveryMode(serverMsg.isPersistent() ? BasicContentHeaderProperties.PERSISTENT : BasicContentHeaderProperties.NON_PERSISTENT);
    final Date absoluteExpiryTime = getAbsoluteExpiryTime(serverMsg);
    if (absoluteExpiryTime != null) {
        props.setExpiration(absoluteExpiryTime.getTime());
    } else {
        Long ttl = getTtl(serverMsg);
        if (ttl != null) {
            props.setExpiration(ttl + serverMsg.getArrivalTime());
        }
    }
    props.setMessageId(getMessageIdAsShortString(serverMsg));
    props.setPriority(serverMsg.getMessageHeader().getPriority());
    props.setReplyTo(getReplyTo(serverMsg, addressSpace));
    Date timestamp = getCreationTime(serverMsg);
    if (timestamp != null) {
        props.setTimestamp(timestamp.getTime());
    } else {
        props.setTimestamp(serverMsg.getArrivalTime());
    }
    props.setUserId(getUserIdAsShortString(serverMsg));
    Map<String, Object> headerProps = new LinkedHashMap<>();
    if (header.getSubject() != null) {
        headerProps.put("qpid.subject", header.getSubject());
        props.setType(convertToShortStringForProperty("subject", header.getSubject()));
    }
    String groupId = getGroupId(serverMsg);
    if (groupId != null) {
        headerProps.put("JMSXGroupID", groupId);
    }
    UnsignedInteger groupSequence = getGroupSequence(serverMsg);
    if (groupSequence != null) {
        headerProps.put("JMSXGroupSeq", groupSequence.intValue());
    }
    for (String headerName : serverMsg.getMessageHeader().getHeaderNames()) {
        headerProps.put(headerName, convertValue(serverMsg.getMessageHeader().getHeader(headerName)));
    }
    final FieldTable headers;
    try {
        headers = FieldTable.convertToFieldTable(headerProps);
    } catch (IllegalArgumentException e) {
        throw new MessageConversionException("Could not convert message from 1.0 to 0-8 because conversion of 'application-properties' failed.", e);
    }
    props.setHeaders(headers);
    final ContentHeaderBody chb = new ContentHeaderBody(props);
    chb.setBodySize(size);
    MessagePublishInfo publishInfo = createMessagePublishInfo(header, addressSpace);
    return new MessageMetaData(publishInfo, chb, serverMsg.getArrivalTime());
}
Also used : MessagePublishInfo(org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo) MessageMetaData(org.apache.qpid.server.protocol.v0_8.MessageMetaData) MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) ContentHeaderBody(org.apache.qpid.server.protocol.v0_8.transport.ContentHeaderBody) FieldTable(org.apache.qpid.server.protocol.v0_8.FieldTable) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0) AMQShortString(org.apache.qpid.server.protocol.v0_8.AMQShortString) BasicContentHeaderProperties(org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) UnsignedInteger(org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)

Example 7 with MessageMetaData_1_0

use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.

the class MessageConverter_Internal_to_v1_0 method convertMetaData.

@Override
protected MessageMetaData_1_0 convertMetaData(final InternalMessage serverMessage, final EncodingRetainingSection<?> bodySection, final SectionEncoder sectionEncoder) {
    Header header = new Header();
    header.setDurable(serverMessage.isPersistent());
    header.setPriority(UnsignedByte.valueOf(serverMessage.getMessageHeader().getPriority()));
    if (serverMessage.getExpiration() != 0l && serverMessage.getArrivalTime() != 0l && serverMessage.getExpiration() >= serverMessage.getArrivalTime()) {
        header.setTtl(UnsignedInteger.valueOf(serverMessage.getExpiration() - serverMessage.getArrivalTime()));
    }
    Properties properties = new Properties();
    if (serverMessage.getMessageHeader().getEncoding() != null) {
        properties.setContentEncoding(Symbol.valueOf(serverMessage.getMessageHeader().getEncoding()));
    }
    properties.setCorrelationId(getCorrelationId(serverMessage));
    properties.setCreationTime(new Date(serverMessage.getMessageHeader().getTimestamp()));
    properties.setMessageId(getMessageId(serverMessage));
    Symbol contentType = getContentTypeSymbol(serverMessage.getMessageBody(), serverMessage.getMessageHeader().getMimeType());
    properties.setContentType(contentType);
    final String userId = serverMessage.getMessageHeader().getUserId();
    if (userId != null) {
        properties.setUserId(new Binary(userId.getBytes(StandardCharsets.UTF_8)));
    }
    properties.setReplyTo(serverMessage.getMessageHeader().getReplyTo());
    properties.setTo(serverMessage.getTo());
    ApplicationProperties applicationProperties = null;
    if (!serverMessage.getMessageHeader().getHeaderNames().isEmpty()) {
        try {
            applicationProperties = new ApplicationProperties(serverMessage.getMessageHeader().getHeaderMap());
        } catch (IllegalArgumentException e) {
            throw new MessageConversionException("Could not convert message from internal to 1.0" + " because conversion of 'application headers' failed.", e);
        }
    }
    final MessageAnnotations messageAnnotation = createMessageAnnotation(serverMessage.getMessageBody(), serverMessage.getMessageHeader().getMimeType(), bodySection);
    return new MessageMetaData_1_0(header.createEncodingRetainingSection(), null, messageAnnotation == null ? null : messageAnnotation.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties == null ? null : applicationProperties.createEncodingRetainingSection(), null, serverMessage.getArrivalTime(), bodySection.getEncodedSize());
}
Also used : MessageConversionException(org.apache.qpid.server.protocol.converter.MessageConversionException) Header(org.apache.qpid.server.protocol.v1_0.type.messaging.Header) Symbol(org.apache.qpid.server.protocol.v1_0.type.Symbol) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Binary(org.apache.qpid.server.protocol.v1_0.type.Binary) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties) Date(java.util.Date)

Example 8 with MessageMetaData_1_0

use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.

the class MessageFormat_1_0 method createMessage.

@Override
public Message_1_0 createMessage(final QpidByteBuffer payload, final MessageStore store, final Object connectionReference) {
    List<EncodingRetainingSection<?>> dataSections = new ArrayList<>();
    List<EncodingRetainingSection<?>> allSections;
    try {
        allSections = getSectionDecoder().parseAll(payload);
    } catch (AmqpErrorException e) {
        throw new AmqpErrorRuntimeException(e);
    }
    MessageMetaData_1_0 mmd = createMessageMetaData(allSections, dataSections);
    MessageHandle<MessageMetaData_1_0> handle = store.addMessage(mmd);
    for (EncodingRetainingSection<?> dataSection : dataSections) {
        try (QpidByteBuffer encodedForm = dataSection.getEncodedForm()) {
            handle.addContent(encodedForm);
        }
        dataSection.dispose();
    }
    final StoredMessage<MessageMetaData_1_0> storedMessage = handle.allContentAdded();
    return new Message_1_0(storedMessage, connectionReference);
}
Also used : EncodingRetainingSection(org.apache.qpid.server.protocol.v1_0.type.messaging.EncodingRetainingSection) ArrayList(java.util.ArrayList) AmqpErrorException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorException) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) AmqpErrorRuntimeException(org.apache.qpid.server.protocol.v1_0.type.AmqpErrorRuntimeException)

Example 9 with MessageMetaData_1_0

use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.

the class ConsumerTarget_1_0Test method createTestMessage.

private Message_1_0 createTestMessage(final Header header, long arrivalTime) {
    DeliveryAnnotationsSection deliveryAnnotations = new DeliveryAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
    MessageAnnotationsSection messageAnnotations = new MessageAnnotations(Collections.emptyMap()).createEncodingRetainingSection();
    ApplicationPropertiesSection applicationProperties = new ApplicationProperties(Collections.emptyMap()).createEncodingRetainingSection();
    FooterSection footer = new Footer(Collections.emptyMap()).createEncodingRetainingSection();
    MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations, messageAnnotations, new Properties().createEncodingRetainingSection(), applicationProperties, footer, arrivalTime, 0);
    final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
    when(storedMessage.getContent(eq(0), anyInt())).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
    when(storedMessage.getMetaData()).thenReturn(metaData);
    return new Message_1_0(storedMessage);
}
Also used : DeliveryAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotationsSection) FooterSection(org.apache.qpid.server.protocol.v1_0.type.messaging.FooterSection) MessageAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations) DeliveryAnnotations(org.apache.qpid.server.protocol.v1_0.type.messaging.DeliveryAnnotations) Footer(org.apache.qpid.server.protocol.v1_0.type.messaging.Footer) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) MessageAnnotationsSection(org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotationsSection) ApplicationPropertiesSection(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationPropertiesSection) ApplicationProperties(org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties) Properties(org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)

Example 10 with MessageMetaData_1_0

use of org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0 in project qpid-broker-j by apache.

the class PropertyConverter_1_0_to_0_8Test method createTestMessage.

private Message_1_0 createTestMessage(final Header header, final DeliveryAnnotations deliveryAnnotations, final MessageAnnotations messageAnnotations, final Properties properties, final ApplicationProperties applicationProperties, final long arrivalTime) {
    final StoredMessage<MessageMetaData_1_0> storedMessage = mock(StoredMessage.class);
    when(storedMessage.getContentSize()).thenReturn(0);
    when(storedMessage.getContent(0, 0)).thenReturn(QpidByteBuffer.emptyQpidByteBuffer());
    MessageMetaData_1_0 metaData = new MessageMetaData_1_0(header.createEncodingRetainingSection(), deliveryAnnotations.createEncodingRetainingSection(), messageAnnotations.createEncodingRetainingSection(), properties.createEncodingRetainingSection(), applicationProperties.createEncodingRetainingSection(), new Footer(Collections.emptyMap()).createEncodingRetainingSection(), arrivalTime, 0);
    when(storedMessage.getMetaData()).thenReturn(metaData);
    return new Message_1_0(storedMessage);
}
Also used : Footer(org.apache.qpid.server.protocol.v1_0.type.messaging.Footer) Message_1_0(org.apache.qpid.server.protocol.v1_0.Message_1_0) MessageMetaData_1_0(org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)

Aggregations

MessageMetaData_1_0 (org.apache.qpid.server.protocol.v1_0.MessageMetaData_1_0)9 Footer (org.apache.qpid.server.protocol.v1_0.type.messaging.Footer)7 QpidByteBuffer (org.apache.qpid.server.bytebuffer.QpidByteBuffer)6 Date (java.util.Date)5 Binary (org.apache.qpid.server.protocol.v1_0.type.Binary)5 DataSection (org.apache.qpid.server.protocol.v1_0.type.messaging.DataSection)5 MessageConversionException (org.apache.qpid.server.protocol.converter.MessageConversionException)4 Message_1_0 (org.apache.qpid.server.protocol.v1_0.Message_1_0)4 UnsignedInteger (org.apache.qpid.server.protocol.v1_0.type.UnsignedInteger)4 ApplicationProperties (org.apache.qpid.server.protocol.v1_0.type.messaging.ApplicationProperties)4 MessageAnnotations (org.apache.qpid.server.protocol.v1_0.type.messaging.MessageAnnotations)4 Properties (org.apache.qpid.server.protocol.v1_0.type.messaging.Properties)4 LinkedHashMap (java.util.LinkedHashMap)3 Symbol (org.apache.qpid.server.protocol.v1_0.type.Symbol)3 Header (org.apache.qpid.server.protocol.v1_0.type.messaging.Header)3 DeliveryProperties (org.apache.qpid.server.protocol.v0_10.transport.DeliveryProperties)2 MessageProperties (org.apache.qpid.server.protocol.v0_10.transport.MessageProperties)2 AMQShortString (org.apache.qpid.server.protocol.v0_8.AMQShortString)2 BasicContentHeaderProperties (org.apache.qpid.server.protocol.v0_8.transport.BasicContentHeaderProperties)2 MessagePublishInfo (org.apache.qpid.server.protocol.v0_8.transport.MessagePublishInfo)2